diff --git a/src/renderer/store/App.ts b/src/renderer/store/App.ts index 79a23e10..8b1aa8dd 100644 --- a/src/renderer/store/App.ts +++ b/src/renderer/store/App.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { watchShortcutsEvents: () => { ipcRenderer.on('open-preferences', () => { router.push('/preferences/general') @@ -154,8 +154,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const App: Module = { +const App: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Authorize.ts b/src/renderer/store/Authorize.ts index 3dbd457c..ac8fded1 100644 --- a/src/renderer/store/Authorize.ts +++ b/src/renderer/store/Authorize.ts @@ -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 = { +const actions: ActionTree = { submit: (_, code: string) => { return new Promise((resolve, reject) => { ipcRenderer.send('get-access-token', code) @@ -22,8 +22,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const Authorize: Module = { +const Authorize: Module = { namespaced: true, state: state, mutations: {}, diff --git a/src/renderer/store/GlobalHeader.ts b/src/renderer/store/GlobalHeader.ts index 5302e803..df5bd1a8 100644 --- a/src/renderer/store/GlobalHeader.ts +++ b/src/renderer/store/GlobalHeader.ts @@ -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, @@ -33,8 +34,7 @@ const mutations: MutationTree = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { listAccounts: ({ dispatch, commit }): Promise> => { return new Promise((resolve, reject) => { ipcRenderer.send('list-accounts', 'list') @@ -107,8 +107,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const GlobalHeader: Module = { +const GlobalHeader: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Login.ts b/src/renderer/store/Login.ts index 7bb20de2..afb5e71b 100644 --- a/src/renderer/store/Login.ts +++ b/src/renderer/store/Login.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { fetchLogin: (_, instance: string) => { return new Promise((resolve, reject) => { ipcRenderer.send('get-auth-url', instance) @@ -55,8 +55,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const Login: Module = { +const Login: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Preferences.ts b/src/renderer/store/Preferences.ts index 20e497eb..0c8491e0 100644 --- a/src/renderer/store/Preferences.ts +++ b/src/renderer/store/Preferences.ts @@ -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 = { +const Preferences: Module = { namespaced: true, modules: { General, diff --git a/src/renderer/store/Preferences/Account.ts b/src/renderer/store/Preferences/Account.ts index b1735e28..767ce94d 100644 --- a/src/renderer/store/Preferences/Account.ts +++ b/src/renderer/store/Preferences/Account.ts @@ -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, @@ -26,8 +27,7 @@ const mutations: MutationTree = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { loadAccounts: ({ commit }): Promise> => { return new Promise((resolve, reject) => { ipcRenderer.send('list-accounts', 'list') @@ -96,8 +96,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const account: Module = { +const account: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Preferences/Appearance.ts b/src/renderer/store/Preferences/Appearance.ts index 87f20cc9..ca2e0562 100644 --- a/src/renderer/store/Preferences/Appearance.ts +++ b/src/renderer/store/Preferences/Appearance.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { loadAppearance: ({ commit }) => { return new Promise((resolve, reject) => { ipcRenderer.send('get-preferences') @@ -218,8 +218,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const Appearance: Module = { +const Appearance: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Preferences/General.ts b/src/renderer/store/Preferences/General.ts index 82d1eec9..a2bee1f3 100644 --- a/src/renderer/store/Preferences/General.ts +++ b/src/renderer/store/Preferences/General.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { loadGeneral: ({ commit }) => { return new Promise((resolve, reject) => { commit(MUTATION_TYPES.CHANGE_LOADING, true) @@ -119,7 +119,7 @@ const actions: ActionTree = { }) } } -const General: Module = { +const General: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Preferences/Language.ts b/src/renderer/store/Preferences/Language.ts index f2fc86f0..dfb958da 100644 --- a/src/renderer/store/Preferences/Language.ts +++ b/src/renderer/store/Preferences/Language.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { loadLanguage: ({ commit }) => { return new Promise((resolve, reject) => { ipcRenderer.send('get-preferences') @@ -60,10 +60,9 @@ const actions: ActionTree = { } } -// TODO: use type of rootState export default { namespaced: true, state: state, mutations: mutations, actions: actions -} as Module +} as Module diff --git a/src/renderer/store/Preferences/Notification.ts b/src/renderer/store/Preferences/Notification.ts index 0cc58912..b4788806 100644 --- a/src/renderer/store/Preferences/Notification.ts +++ b/src/renderer/store/Preferences/Notification.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { loadNotification: ({ commit }) => { return new Promise((resolve, reject) => { ipcRenderer.send('get-preferences') @@ -72,10 +72,9 @@ const actions: ActionTree = { } } -// TODO: use type of rootState export default { namespaced: true, state: state, mutations: mutations, actions: actions -} as Module +} as Module diff --git a/src/renderer/store/Settings.ts b/src/renderer/store/Settings.ts index 902e8566..651608a0 100644 --- a/src/renderer/store/Settings.ts +++ b/src/renderer/store/Settings.ts @@ -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 = { +const Settings: Module = { namespaced: true, modules: { General, diff --git a/src/renderer/store/Settings/General.ts b/src/renderer/store/Settings/General.ts index 9a06d0ce..09029679 100644 --- a/src/renderer/store/Settings/General.ts +++ b/src/renderer/store/Settings/General.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { fetchSettings: async ({ commit, rootState }): Promise => { const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, + rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1' ) const res = await client.get('/accounts/verify_credentials') @@ -44,7 +44,7 @@ const actions: ActionTree = { }, 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).find((v) => { @@ -60,7 +60,7 @@ const actions: ActionTree = { }, 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('/accounts/update_credentials', { @@ -73,8 +73,7 @@ const actions: ActionTree = { } } -// TODO: use type of rootState -const General: Module = { +const General: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/Settings/Timeline.ts b/src/renderer/store/Settings/Timeline.ts index 9cff7707..67d457c2 100644 --- a/src/renderer/store/Settings/Timeline.ts +++ b/src/renderer/store/Settings/Timeline.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { loadUnreadNotification: ({ commit, rootState }): Promise => { return new Promise(resolve => { ipcRenderer.once('response-get-unread-notification', (_, settings: UnreadNotification) => { @@ -71,8 +71,7 @@ const actions: ActionTree = { } } -// Todo: use type of rootState -const Timeline: Module = { +const Timeline: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index df641bf7..9830621e 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -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 = { } } -const actions: ActionTree = { +const actions: ActionTree = { // ------------------------------------------------- // Accounts // ------------------------------------------------- @@ -423,7 +424,7 @@ export interface TimelineSpaceModuleState extends TimelineSpaceState { Contents: ContentsModuleState } -const TimelineSpace: Module = { +const TimelineSpace: Module = { namespaced: true, modules: { SideMenu, diff --git a/src/renderer/store/TimelineSpace/HeaderMenu.ts b/src/renderer/store/TimelineSpace/HeaderMenu.ts index f2bf3775..7f70c21f 100644 --- a/src/renderer/store/TimelineSpace/HeaderMenu.ts +++ b/src/renderer/store/TimelineSpace/HeaderMenu.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { fetchList: async ({ commit, rootState }, listID: number): Promise => { const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, + rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1' ) const res: Response = await client.get(`/lists/${listID}`) @@ -38,7 +38,7 @@ const actions: ActionTree = { } } -const HeaderMenu: Module = { +const HeaderMenu: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/TimelineSpace/Modals/AddListMember.ts b/src/renderer/store/TimelineSpace/Modals/AddListMember.ts index 84ccad6a..b097fc2a 100644 --- a/src/renderer/store/TimelineSpace/Modals/AddListMember.ts +++ b/src/renderer/store/TimelineSpace/Modals/AddListMember.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { changeModal: ({ commit }, value: boolean) => { commit(MUTATION_TYPES.CHANGE_MODAL, value) }, search: async ({ commit, rootState }, name: string): Promise> => { const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, + rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1' ) const res: Response> = await client.get>('/accounts/search', { @@ -50,7 +50,7 @@ const actions: ActionTree = { }, 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 = { } } -const AddListMember: Module = { +const AddListMember: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/TimelineSpace/Modals/Jump.ts b/src/renderer/store/TimelineSpace/Modals/Jump.ts index c4aef049..529b5a9d 100644 --- a/src/renderer/store/TimelineSpace/Modals/Jump.ts +++ b/src/renderer/store/TimelineSpace/Modals/Jump.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { 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 = { } } -const Jump: Module = { +const Jump: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/TimelineSpace/SideMenu.ts b/src/renderer/store/TimelineSpace/SideMenu.ts index f1d91863..43ffacfe 100644 --- a/src/renderer/store/TimelineSpace/SideMenu.ts +++ b/src/renderer/store/TimelineSpace/SideMenu.ts @@ -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 = { } } -// TODO: use type of rootState -const actions: ActionTree = { +const actions: ActionTree = { fetchLists: async ({ commit, rootState }, account: Account | null = null): Promise> => { if (account === null) account = rootState.TimelineSpace.account const client = new Mastodon( @@ -119,7 +119,7 @@ const actions: ActionTree = { } } -const SideMenu: Module = { +const SideMenu: Module = { namespaced: true, state: state, mutations: mutations, diff --git a/src/renderer/store/index.ts b/src/renderer/store/index.ts index dd830f07..ac38876f 100644 --- a/src/renderer/store/index.ts +++ b/src/renderer/store/index.ts @@ -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({ diff --git a/src/renderer/store/molecules.ts b/src/renderer/store/molecules.ts index 82fbdfe9..0899b724 100644 --- a/src/renderer/store/molecules.ts +++ b/src/renderer/store/molecules.ts @@ -1,6 +1,7 @@ -import Toot from './molecules/Toot' +import Toot, { TootState } from './molecules/Toot' export interface MoleculesModuleState { + Toot: TootState } export default { diff --git a/src/renderer/store/molecules/Toot.ts b/src/renderer/store/molecules/Toot.ts index a997facf..68d2a4ca 100644 --- a/src/renderer/store/molecules/Toot.ts +++ b/src/renderer/store/molecules/Toot.ts @@ -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 = { +const actions: ActionTree = { 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 = await client.post(`/statuses/${message.id}/reblog`) @@ -21,7 +22,7 @@ const actions: ActionTree = { }, 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 = await client.post(`/statuses/${message.id}/unreblog`) @@ -29,7 +30,7 @@ const actions: ActionTree = { }, 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 = await client.post(`/statuses/${message.id}/favourite`) @@ -38,7 +39,7 @@ const actions: ActionTree = { }, 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 = await client.post(`/statuses/${message.id}/unfavourite`) @@ -46,7 +47,7 @@ const actions: ActionTree = { }, 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 = { }, 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 = { +const Toot: Module = { namespaced: true, state: state, actions: actions