refs #850 Use rootState for all stores

This commit is contained in:
AkiraFukushima 2019-04-14 23:11:24 +09:00
parent 4bd517a07b
commit baf6dc3084
21 changed files with 72 additions and 77 deletions

View File

@ -7,6 +7,7 @@ import Theme from '~/src/constants/theme'
import TimeFormat from '~/src/constants/timeFormat'
import Language from '~/src/constants/language'
import DefaultFonts from '@/utils/fonts'
import { RootState } from '@/store'
export interface Notify {
reply: boolean,
@ -93,8 +94,7 @@ const mutations: MutationTree<AppState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<AppState, any> = {
const actions: ActionTree<AppState, RootState> = {
watchShortcutsEvents: () => {
ipcRenderer.on('open-preferences', () => {
router.push('/preferences/general')
@ -154,8 +154,7 @@ const actions: ActionTree<AppState, any> = {
}
}
// TODO: use type of rootState
const App: Module<AppState, any> = {
const App: Module<AppState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,12 +1,12 @@
import { ipcRenderer } from 'electron'
import { Module, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface AuthorizeState {}
const state = (): AuthorizeState => ({})
// TODO: use type of rootState
const actions: ActionTree<AuthorizeState, any> = {
const actions: ActionTree<AuthorizeState, RootState> = {
submit: (_, code: string) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-access-token', code)
@ -22,8 +22,7 @@ const actions: ActionTree<AuthorizeState, any> = {
}
}
// TODO: use type of rootState
const Authorize: Module<AuthorizeState, any> = {
const Authorize: Module<AuthorizeState, RootState> = {
namespaced: true,
state: state,
mutations: {},

View File

@ -2,6 +2,7 @@ import { ipcRenderer } from 'electron'
import router from '@/router'
import Account from '~/src/types/account'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface GlobalHeaderState {
accounts: Array<Account>,
@ -33,8 +34,7 @@ const mutations: MutationTree<GlobalHeaderState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<GlobalHeaderState, any> = {
const actions: ActionTree<GlobalHeaderState, RootState> = {
listAccounts: ({ dispatch, commit }): Promise<Array<Account>> => {
return new Promise((resolve, reject) => {
ipcRenderer.send('list-accounts', 'list')
@ -107,8 +107,7 @@ const actions: ActionTree<GlobalHeaderState, any> = {
}
}
// TODO: use type of rootState
const GlobalHeader: Module<GlobalHeaderState, any> = {
const GlobalHeader: Module<GlobalHeaderState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,6 +1,7 @@
import { ipcRenderer } from 'electron'
import axios from 'axios'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface LoginState {
selectedInstance: string | null,
@ -26,8 +27,7 @@ const mutations: MutationTree<LoginState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<LoginState, any> = {
const actions: ActionTree<LoginState, RootState> = {
fetchLogin: (_, instance: string) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-auth-url', instance)
@ -55,8 +55,7 @@ const actions: ActionTree<LoginState, any> = {
}
}
// TODO: use type of rootState
const Login: Module<LoginState, any> = {
const Login: Module<LoginState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -4,6 +4,7 @@ import Language, { LanguageState } from './Preferences/Language'
import Appearance, { AppearanceState } from './Preferences/Appearance'
import Notification, { NotificationState } from './Preferences/Notification'
import { Module } from 'vuex'
import { RootState } from '@/store'
export interface PreferencesState {}
@ -17,8 +18,7 @@ export interface PreferencesModuleState extends PreferencesState {
Appearance: AppearanceState
}
// TODO: use type of rootState
const Preferences: Module<PreferencesState, any> = {
const Preferences: Module<PreferencesState, RootState> = {
namespaced: true,
modules: {
General,

View File

@ -1,6 +1,7 @@
import { ipcRenderer } from 'electron'
import { Module, MutationTree, ActionTree } from 'vuex'
import Account from '~/src/types/account'
import { RootState } from '@/store'
export interface AccountState {
accounts: Array<Account>,
@ -26,8 +27,7 @@ const mutations: MutationTree<AccountState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<AccountState, any> = {
const actions: ActionTree<AccountState, RootState> = {
loadAccounts: ({ commit }): Promise<Array<Account>> => {
return new Promise((resolve, reject) => {
ipcRenderer.send('list-accounts', 'list')
@ -96,8 +96,7 @@ const actions: ActionTree<AccountState, any> = {
}
}
// TODO: use type of rootState
const account: Module<AccountState, any> = {
const account: Module<AccountState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -5,6 +5,7 @@ import TimeFormat from '~/src/constants/timeFormat'
import { LightTheme } from '@/utils/theme'
import DefaultFonts from '@/utils/fonts'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
interface ColorThemeSet {
background_color: string,
@ -59,8 +60,7 @@ const mutations: MutationTree<AppearanceState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<AppearanceState, any> = {
const actions: ActionTree<AppearanceState, RootState> = {
loadAppearance: ({ commit }) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-preferences')
@ -218,8 +218,7 @@ const actions: ActionTree<AppearanceState, any> = {
}
}
// TODO: use type of rootState
const Appearance: Module<AppearanceState, any> = {
const Appearance: Module<AppearanceState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,5 +1,6 @@
import { ipcRenderer } from 'electron'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
interface Sound {
fav_rb: boolean,
@ -50,8 +51,7 @@ const mutations: MutationTree<GeneralState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<GeneralState, any> = {
const actions: ActionTree<GeneralState, RootState> = {
loadGeneral: ({ commit }) => {
return new Promise((resolve, reject) => {
commit(MUTATION_TYPES.CHANGE_LOADING, true)
@ -119,7 +119,7 @@ const actions: ActionTree<GeneralState, any> = {
})
}
}
const General: Module<GeneralState, any> = {
const General: Module<GeneralState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,6 +1,7 @@
import { ipcRenderer } from 'electron'
import Language from '~/src/constants/language'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
interface LanguageSet {
language: string
@ -30,8 +31,7 @@ const mutations: MutationTree<LanguageState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<LanguageState, any> = {
const actions: ActionTree<LanguageState, RootState> = {
loadLanguage: ({ commit }) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-preferences')
@ -60,10 +60,9 @@ const actions: ActionTree<LanguageState, any> = {
}
}
// TODO: use type of rootState
export default {
namespaced: true,
state: state,
mutations: mutations,
actions: actions
} as Module<LanguageState, any>
} as Module<LanguageState, RootState>

View File

@ -1,5 +1,6 @@
import { ipcRenderer } from 'electron'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
interface Notify {
reply: boolean,
@ -37,8 +38,7 @@ const mutations: MutationTree<NotificationState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<NotificationState, any> = {
const actions: ActionTree<NotificationState, RootState> = {
loadNotification: ({ commit }) => {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-preferences')
@ -72,10 +72,9 @@ const actions: ActionTree<NotificationState, any> = {
}
}
// TODO: use type of rootState
export default {
namespaced: true,
state: state,
mutations: mutations,
actions: actions
} as Module<NotificationState, any>
} as Module<NotificationState, RootState>

View File

@ -1,6 +1,7 @@
import General, { GeneralState } from './Settings/General'
import Timeline, { TimelineState } from './Settings/Timeline'
import { Module, MutationTree } from 'vuex'
import { RootState } from '@/store'
export interface SettingsState {
accountID: number | null
@ -25,8 +26,7 @@ export interface SettingsModuleState extends SettingsState {
Timeline: TimelineState,
}
// TODO: use type of rootState
const Settings: Module<SettingsState, any> = {
const Settings: Module<SettingsState, RootState> = {
namespaced: true,
modules: {
General,

View File

@ -2,6 +2,7 @@ import Mastodon, { Account } from 'megalodon'
import Visibilities from '~/src/constants/visibility'
import { Module, MutationTree, ActionTree } from 'vuex'
import Visibility from '~/src/types/visibility'
import { RootState } from '@/store'
export interface GeneralState {
visibility: number,
@ -27,11 +28,10 @@ const mutations: MutationTree<GeneralState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<GeneralState, any> = {
const actions: ActionTree<GeneralState, RootState> = {
fetchSettings: async ({ commit, rootState }): Promise<Account> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res = await client.get<Account>('/accounts/verify_credentials')
@ -44,7 +44,7 @@ const actions: ActionTree<GeneralState, any> = {
},
setVisibility: async ({ commit, rootState }, value: number) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const visibility = Object.values(Visibilities as Array<Visibility>).find((v) => {
@ -60,7 +60,7 @@ const actions: ActionTree<GeneralState, any> = {
},
setSensitive: async ({ commit, rootState }, value: boolean) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res = await client.patch<Account>('/accounts/update_credentials', {
@ -73,8 +73,7 @@ const actions: ActionTree<GeneralState, any> = {
}
}
// TODO: use type of rootState
const General: Module<GeneralState, any> = {
const General: Module<GeneralState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,6 +1,7 @@
import { ipcRenderer } from 'electron'
import unreadSettings from '~/src/constants/unreadNotification'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
interface UnreadNotification {
direct: boolean,
@ -30,8 +31,7 @@ const mutations: MutationTree<TimelineState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<TimelineState, any> = {
const actions: ActionTree<TimelineState, RootState> = {
loadUnreadNotification: ({ commit, rootState }): Promise<boolean> => {
return new Promise(resolve => {
ipcRenderer.once('response-get-unread-notification', (_, settings: UnreadNotification) => {
@ -71,8 +71,7 @@ const actions: ActionTree<TimelineState, any> = {
}
}
// Todo: use type of rootState
const Timeline: Module<TimelineState, any> = {
const Timeline: Module<TimelineState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -10,6 +10,7 @@ import unreadSettings from '~/src/constants/unreadNotification'
import { Module, MutationTree, ActionTree } from 'vuex'
import AccountType from '~/src/types/account'
import { Notify } from './App'
import { RootState } from '@/store'
declare var Notification: any
@ -105,7 +106,7 @@ const mutations: MutationTree<TimelineSpaceState> = {
}
}
const actions: ActionTree<TimelineSpaceState, any> = {
const actions: ActionTree<TimelineSpaceState, RootState> = {
// -------------------------------------------------
// Accounts
// -------------------------------------------------
@ -423,7 +424,7 @@ export interface TimelineSpaceModuleState extends TimelineSpaceState {
Contents: ContentsModuleState
}
const TimelineSpace: Module<TimelineSpaceState, any> = {
const TimelineSpace: Module<TimelineSpaceState, RootState> = {
namespaced: true,
modules: {
SideMenu,

View File

@ -1,5 +1,6 @@
import Mastodon, { List, Response } from 'megalodon'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface HeaderMenuState {
title: string,
@ -25,11 +26,10 @@ const mutations: MutationTree<HeaderMenuState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<HeaderMenuState, any> = {
const actions: ActionTree<HeaderMenuState, RootState> = {
fetchList: async ({ commit, rootState }, listID: number): Promise<List> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<List> = await client.get<List>(`/lists/${listID}`)
@ -38,7 +38,7 @@ const actions: ActionTree<HeaderMenuState, any> = {
}
}
const HeaderMenu: Module<HeaderMenuState, any> = {
const HeaderMenu: Module<HeaderMenuState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,5 +1,6 @@
import Mastodon, { Account, Response } from 'megalodon'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface AddListMemberState {
modalOpen: boolean,
@ -31,14 +32,13 @@ const mutations: MutationTree<AddListMemberState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<AddListMemberState, any> = {
const actions: ActionTree<AddListMemberState, RootState> = {
changeModal: ({ commit }, value: boolean) => {
commit(MUTATION_TYPES.CHANGE_MODAL, value)
},
search: async ({ commit, rootState }, name: string): Promise<Array<Account>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Array<Account>> = await client.get<Array<Account>>('/accounts/search', {
@ -50,7 +50,7 @@ const actions: ActionTree<AddListMemberState, any> = {
},
add: async ({ state, rootState }, account: Account): Promise<{}> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<{}> = await client.post<{}>(`/lists/${state.targetListId}/accounts`, {
@ -60,7 +60,7 @@ const actions: ActionTree<AddListMemberState, any> = {
}
}
const AddListMember: Module<AddListMemberState, any> = {
const AddListMember: Module<AddListMemberState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -3,6 +3,7 @@ import i18n from '~/src/config/i18n'
import { Module, MutationTree, ActionTree } from 'vuex'
import { List } from 'megalodon'
import Hashtag from '~/src/types/hashtag'
import { RootState } from '@/store'
export interface Channel {
name: string,
@ -105,8 +106,7 @@ const mutations: MutationTree<JumpState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<JumpState, any> = {
const actions: ActionTree<JumpState, RootState> = {
jumpCurrentSelected: ({ state, commit, rootState }) => {
commit(MUTATION_TYPES.CHANGE_MODAL, false)
router.push({ path: `/${rootState.TimelineSpace.account._id}/${state.selectedChannel.path}` })
@ -123,7 +123,7 @@ const actions: ActionTree<JumpState, any> = {
}
}
const Jump: Module<JumpState, any> = {
const Jump: Module<JumpState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -3,6 +3,7 @@ import { ipcRenderer } from 'electron'
import { Module, MutationTree, ActionTree } from 'vuex'
import Hashtag from '~/src/types/hashtag'
import Account from '~/src/types/account'
import { RootState } from '@/store'
export interface SideMenuState {
unreadHomeTimeline: boolean,
@ -70,8 +71,7 @@ const mutations: MutationTree<SideMenuState> = {
}
}
// TODO: use type of rootState
const actions: ActionTree<SideMenuState, any> = {
const actions: ActionTree<SideMenuState, RootState> = {
fetchLists: async ({ commit, rootState }, account: Account | null = null): Promise<Array<List>> => {
if (account === null) account = rootState.TimelineSpace.account
const client = new Mastodon(
@ -119,7 +119,7 @@ const actions: ActionTree<SideMenuState, any> = {
}
}
const SideMenu: Module<SideMenuState, any> = {
const SideMenu: Module<SideMenuState, RootState> = {
namespaced: true,
state: state,
mutations: mutations,

View File

@ -1,6 +1,7 @@
import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'
import { Route } from 'vue-router'
import App, { AppState } from './App'
import GlobalHeader, { GlobalHeaderState } from './GlobalHeader'
@ -21,7 +22,8 @@ export interface RootState {
TimelineSpace: TimelineSpaceModuleState,
Preferences: PreferencesModuleState,
Settings: SettingsModuleState,
molecules: MoleculesModuleState
molecules: MoleculesModuleState,
route: Route
}
export default new Vuex.Store({

View File

@ -1,6 +1,7 @@
import Toot from './molecules/Toot'
import Toot, { TootState } from './molecules/Toot'
export interface MoleculesModuleState {
Toot: TootState
}
export default {

View File

@ -1,15 +1,16 @@
import Mastodon, { Response, Status, Account } from 'megalodon'
import { ipcRenderer } from 'electron'
import { Module, ActionTree } from 'vuex'
import { RootState } from '@/store'
export interface TootState {}
const state = (): TootState => ({})
const actions: ActionTree<TootState, any> = {
const actions: ActionTree<TootState, RootState> = {
reblog: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/reblog`)
@ -21,7 +22,7 @@ const actions: ActionTree<TootState, any> = {
},
unreblog: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unreblog`)
@ -29,7 +30,7 @@ const actions: ActionTree<TootState, any> = {
},
addFavourite: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/favourite`)
@ -38,7 +39,7 @@ const actions: ActionTree<TootState, any> = {
},
removeFavourite: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Status> = await client.post<Status>(`/statuses/${message.id}/unfavourite`)
@ -46,7 +47,7 @@ const actions: ActionTree<TootState, any> = {
},
deleteToot: async ({ rootState }, message: Status) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
await client.del(`/statuses/${message.id}`)
@ -54,14 +55,14 @@ const actions: ActionTree<TootState, any> = {
},
block: async ({ rootState }, account: Account) => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.post(`/accounts/${account.id}/block`)
}
}
const Toot: Module<TootState, any> = {
const Toot: Module<TootState, RootState> = {
namespaced: true,
state: state,
actions: actions