diff --git a/spec/renderer/unit/store/TimelineSpace/Modals/Jump.spec.ts b/spec/renderer/unit/store/TimelineSpace/Modals/Jump.spec.ts index 54418239..a33349d0 100644 --- a/spec/renderer/unit/store/TimelineSpace/Modals/Jump.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Modals/Jump.spec.ts @@ -56,16 +56,16 @@ describe('TimelineSpace/Modals/Jump', () => { describe('updateListChannel', () => { it('should be updated', () => { const admin: List = { - id: 0, - title: 'admin' + id: 0, + title: 'admin' } const engineer: List = { - id: 1, - title: 'engineer' + id: 1, + title: 'engineer' } const designer: List = { - id: 2, - title: 'designer' + id: 2, + title: 'designer' } const channelList = [admin, engineer, designer] Jump.mutations![MUTATION_TYPES.UPDATE_LIST_CHANNEL](state, channelList) diff --git a/src/renderer/store/Preferences.ts b/src/renderer/store/Preferences.ts index db7fa6b3..20e497eb 100644 --- a/src/renderer/store/Preferences.ts +++ b/src/renderer/store/Preferences.ts @@ -1,14 +1,22 @@ -import General from './Preferences/General' -import Account from './Preferences/Account' -import Language from './Preferences/Language' -import Notification from './Preferences/Notification' -import Appearance from './Preferences/Appearance' +import General, { GeneralState } from './Preferences/General' +import Account, { AccountState } from './Preferences/Account' +import Language, { LanguageState } from './Preferences/Language' +import Appearance, { AppearanceState } from './Preferences/Appearance' +import Notification, { NotificationState } from './Preferences/Notification' import { Module } from 'vuex' export interface PreferencesState {} const state = (): PreferencesState => ({}) +export interface PreferencesModuleState extends PreferencesState { + General: GeneralState, + Account: AccountState, + Language: LanguageState, + Notification: NotificationState, + Appearance: AppearanceState +} + // TODO: use type of rootState const Preferences: Module = { namespaced: true, diff --git a/src/renderer/store/Settings.ts b/src/renderer/store/Settings.ts index 6eb8d2b7..902e8566 100644 --- a/src/renderer/store/Settings.ts +++ b/src/renderer/store/Settings.ts @@ -1,5 +1,5 @@ -import General from './Settings/General' -import Timeline from './Settings/Timeline' +import General, { GeneralState } from './Settings/General' +import Timeline, { TimelineState } from './Settings/Timeline' import { Module, MutationTree } from 'vuex' export interface SettingsState { @@ -20,6 +20,11 @@ const mutations: MutationTree = { } } +export interface SettingsModuleState extends SettingsState { + General: GeneralState, + Timeline: TimelineState, +} + // TODO: use type of rootState const Settings: Module = { namespaced: true, diff --git a/src/renderer/store/TimelineSpace.ts b/src/renderer/store/TimelineSpace.ts index d8fbae10..409fcf2f 100644 --- a/src/renderer/store/TimelineSpace.ts +++ b/src/renderer/store/TimelineSpace.ts @@ -1,9 +1,9 @@ import sanitizeHtml from 'sanitize-html' import { ipcRenderer } from 'electron' import Mastodon, { Account, Emoji, Instance, Status, Notification as NotificationType } from 'megalodon' -import SideMenu from './TimelineSpace/SideMenu' -import HeaderMenu from './TimelineSpace/HeaderMenu' -import Modals from './TimelineSpace/Modals' +import SideMenu, { SideMenuState } from './TimelineSpace/SideMenu' +import HeaderMenu, { HeaderMenuState } from './TimelineSpace/HeaderMenu' +import Modals, { ModalsModuleState } from './TimelineSpace/Modals' import Contents from './TimelineSpace/Contents' import router from '@/router' import unreadSettings from '~/src/constants/unreadNotification' @@ -416,6 +416,13 @@ const actions: ActionTree = { } } +export interface TimelineSpaceModuleState extends TimelineSpaceState { + SideMenu: SideMenuState, + HeaderMenu: HeaderMenuState, + Modals: ModalsModuleState + // TODO: Contents: ContentsState +} + const TimelineSpace: Module = { namespaced: true, modules: { diff --git a/src/renderer/store/TimelineSpace/Modals.ts b/src/renderer/store/TimelineSpace/Modals.ts index 6bfb4685..65ae9d9e 100644 --- a/src/renderer/store/TimelineSpace/Modals.ts +++ b/src/renderer/store/TimelineSpace/Modals.ts @@ -1,19 +1,25 @@ import NewToot from './Modals/NewToot' import ImageViewer from './Modals/ImageViewer' -import Jump from './Modals/Jump' +import Jump, { JumpState } from './Modals/Jump' import ListMembership from './Modals/ListMembership' -import AddListMember from './Modals/AddListMember' +import AddListMember, { AddListMemberState } from './Modals/AddListMember' import MuteConfirm from './Modals/MuteConfirm' import Shortcut from './Modals/Shortcut' import Report from './Modals/Report' import { Module, GetterTree } from 'vuex' +import { RootState } from '@/store/index' export interface ModalsState {} +export interface ModalsModuleState extends ModalsState { + Jump: JumpState, + AddListMember: AddListMemberState +} + const state = (): ModalsState => ({}) -// TODO: use type of rootState -const getters: GetterTree = { + +const getters: GetterTree = { modalOpened: (_state, _getters, rootState) => { const imageViewer = rootState.TimelineSpace.Modals.ImageViewer.modalOpen const newToot = rootState.TimelineSpace.Modals.NewToot.modalOpen @@ -27,7 +33,7 @@ const getters: GetterTree = { } } -const Modals: Module = { +const Modals: Module = { namespaced: true, modules: { ImageViewer, diff --git a/src/renderer/store/TimelineSpace/Modals/AddListMember.js b/src/renderer/store/TimelineSpace/Modals/AddListMember.js deleted file mode 100644 index b0368fdb..00000000 --- a/src/renderer/store/TimelineSpace/Modals/AddListMember.js +++ /dev/null @@ -1,49 +0,0 @@ -import Mastodon from 'megalodon' - -export default { - namespaced: true, - state: { - modalOpen: false, - accounts: [], - targetListId: null - }, - mutations: { - changeModal (state, value) { - state.modalOpen = value - }, - updateAccounts (state, accounts) { - state.accounts = accounts - }, - setListId (state, id) { - state.targetListId = id - } - }, - actions: { - changeModal ({ commit }, value) { - commit('changeModal', value) - }, - search ({ commit, rootState }, name) { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, - rootState.TimelineSpace.account.baseURL + '/api/v1' - ) - return client.get('/accounts/search', { - q: name, - following: true - }) - .then(res => { - commit('updateAccounts', res.data) - return res.data - }) - }, - add ({ state, rootState }, account) { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, - rootState.TimelineSpace.account.baseURL + '/api/v1' - ) - return client.post(`/lists/${state.targetListId}/accounts`, { - account_ids: [account.id] - }) - } - } -} diff --git a/src/renderer/store/TimelineSpace/Modals/AddListMember.ts b/src/renderer/store/TimelineSpace/Modals/AddListMember.ts new file mode 100644 index 00000000..84ccad6a --- /dev/null +++ b/src/renderer/store/TimelineSpace/Modals/AddListMember.ts @@ -0,0 +1,70 @@ +import Mastodon, { Account, Response } from 'megalodon' +import { Module, MutationTree, ActionTree } from 'vuex' + +export interface AddListMemberState { + modalOpen: boolean, + accounts: Array, + targetListId: number | null +} + +const state = (): AddListMemberState => ({ + modalOpen: false, + accounts: [], + targetListId: null +}) + +export const MUTATION_TYPES = { + CHANGE_MODAL: 'changeModal', + UPDATE_ACCOUNTS: 'updateAccounts', + SET_LIST_ID: 'setListId' +} + +const mutations: MutationTree = { + [MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => { + state.modalOpen = value + }, + [MUTATION_TYPES.UPDATE_ACCOUNTS]: (state, accounts: Array) => { + state.accounts = accounts + }, + [MUTATION_TYPES.SET_LIST_ID]: (state, id: number) => { + state.targetListId = id + } +} + +// TODO: use type of rootState +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.baseURL + '/api/v1' + ) + const res: Response> = await client.get>('/accounts/search', { + q: name, + following: true + }) + commit(MUTATION_TYPES.UPDATE_ACCOUNTS, res.data) + return res.data + }, + add: async ({ state, rootState }, account: Account): Promise<{}> => { + const client = new Mastodon( + rootState.TimelineSpace.account.accessToken, + rootState.TimelineSpace.account.baseURL + '/api/v1' + ) + const res: Response<{}> = await client.post<{}>(`/lists/${state.targetListId}/accounts`, { + account_ids: [account.id] + }) + return res.data + } +} + +const AddListMember: Module = { + namespaced: true, + state: state, + mutations: mutations, + actions: actions +} + +export default AddListMember diff --git a/src/renderer/store/index.ts b/src/renderer/store/index.ts index 4e0e0f29..dd830f07 100644 --- a/src/renderer/store/index.ts +++ b/src/renderer/store/index.ts @@ -2,17 +2,28 @@ import Vue from 'vue' import Vuex from 'vuex' import createLogger from 'vuex/dist/logger' -import App from './App' -import GlobalHeader from './GlobalHeader' -import Login from './Login' -import Authorize from './Authorize' -import TimelineSpace from './TimelineSpace' -import Preferences from './Preferences' -import Settings from './Settings' -import molecules from './molecules' +import App, { AppState } from './App' +import GlobalHeader, { GlobalHeaderState } from './GlobalHeader' +import Login, { LoginState } from './Login' +import Authorize, { AuthorizeState } from './Authorize' +import TimelineSpace, { TimelineSpaceModuleState } from './TimelineSpace' +import Preferences, { PreferencesModuleState } from './Preferences' +import Settings, { SettingsModuleState } from './Settings' +import molecules, { MoleculesModuleState } from './molecules' Vue.use(Vuex) +export interface RootState { + App: AppState, + GlobalHeader: GlobalHeaderState, + Login: LoginState, + Authorize: AuthorizeState, + TimelineSpace: TimelineSpaceModuleState, + Preferences: PreferencesModuleState, + Settings: SettingsModuleState, + molecules: MoleculesModuleState +} + export default new Vuex.Store({ strict: process.env.NODE_ENV !== 'production', plugins: process.env.NODE_ENV !== 'production' diff --git a/src/renderer/store/molecules.ts b/src/renderer/store/molecules.ts index f0ee7f2a..82fbdfe9 100644 --- a/src/renderer/store/molecules.ts +++ b/src/renderer/store/molecules.ts @@ -1,5 +1,8 @@ import Toot from './molecules/Toot' +export interface MoleculesModuleState { +} + export default { namespaced: true, modules: {