Merge pull request #936 from h3poteto/refactor/any
refactor: Replace any type and organize preference
This commit is contained in:
commit
824ac51cd8
|
@ -11,28 +11,7 @@ import { Timeline } from '~/src/types/timeline'
|
|||
import { Notify } from '~/src/types/notify'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { Language as LanguageSet } from '~/src/types/language'
|
||||
|
||||
type General = {
|
||||
sound: Sound
|
||||
timeline: Timeline
|
||||
}
|
||||
|
||||
type State = {
|
||||
collapse: boolean
|
||||
hideGlobalHeader: boolean
|
||||
}
|
||||
|
||||
type Notification = {
|
||||
notify: Notify
|
||||
}
|
||||
|
||||
type BaseConfig = {
|
||||
general: General
|
||||
state: State
|
||||
language: LanguageSet
|
||||
notification: Notification
|
||||
appearance: Appearance
|
||||
}
|
||||
import { General, State, Notification, BaseConfig } from '~/src/types/preference'
|
||||
|
||||
const sound: Sound = {
|
||||
fav_rb: true,
|
||||
|
|
|
@ -9,6 +9,8 @@ import Language from '~/src/constants/language'
|
|||
import DefaultFonts from '@/utils/fonts'
|
||||
import { RootState } from '@/store'
|
||||
import { Notify } from '~/src/types/notify'
|
||||
import { BaseConfig } from '~/src/types/preference'
|
||||
import { Appearance } from '~src/types/appearance'
|
||||
|
||||
export type AppState = {
|
||||
theme: ThemeColorType
|
||||
|
@ -58,7 +60,7 @@ const MUTATION_TYPES = {
|
|||
}
|
||||
|
||||
const mutations: MutationTree<AppState> = {
|
||||
[MUTATION_TYPES.UPDATE_THEME]: (state: AppState, themeColorList: any) => {
|
||||
[MUTATION_TYPES.UPDATE_THEME]: (state: AppState, themeColorList: ThemeColorType) => {
|
||||
state.theme = themeColorList
|
||||
},
|
||||
[MUTATION_TYPES.UPDATE_FONT_SIZE]: (state: AppState, value: number) => {
|
||||
|
@ -110,25 +112,24 @@ const actions: ActionTree<AppState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||
reject(err)
|
||||
})
|
||||
// TODO: any
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
dispatch('updateTheme', conf.appearance as any)
|
||||
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle as number)
|
||||
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize as number)
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFY, conf.notification.notify as Notify)
|
||||
commit(MUTATION_TYPES.UPDATE_TIME_FORMAT, conf.appearance.timeFormat as number)
|
||||
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language.language as string)
|
||||
commit(MUTATION_TYPES.UPDATE_TOOT_PADDING, conf.appearance.tootPadding as number)
|
||||
commit(MUTATION_TYPES.ADD_FONT, conf.appearance.font as string)
|
||||
commit(MUTATION_TYPES.UPDATE_IGNORE_CW, conf.general.timeline.cw as boolean)
|
||||
commit(MUTATION_TYPES.UPDATE_IGNORE_NFSW, conf.general.timeline.nfsw as boolean)
|
||||
commit(MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS, conf.general.timeline.hideAllAttachments as boolean)
|
||||
dispatch('updateTheme', conf.appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_DISPLAY_NAME_STYLE, conf.appearance.displayNameStyle)
|
||||
commit(MUTATION_TYPES.UPDATE_FONT_SIZE, conf.appearance.fontSize)
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFY, conf.notification.notify)
|
||||
commit(MUTATION_TYPES.UPDATE_TIME_FORMAT, conf.appearance.timeFormat)
|
||||
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language.language)
|
||||
commit(MUTATION_TYPES.UPDATE_TOOT_PADDING, conf.appearance.tootPadding)
|
||||
commit(MUTATION_TYPES.ADD_FONT, conf.appearance.font)
|
||||
commit(MUTATION_TYPES.UPDATE_IGNORE_CW, conf.general.timeline.cw)
|
||||
commit(MUTATION_TYPES.UPDATE_IGNORE_NFSW, conf.general.timeline.nfsw)
|
||||
commit(MUTATION_TYPES.UPDATE_HIDE_ALL_ATTACHMENTS, conf.general.timeline.hideAllAttachments)
|
||||
resolve(conf)
|
||||
})
|
||||
})
|
||||
},
|
||||
updateTheme: ({ commit }, appearance: any) => {
|
||||
updateTheme: ({ commit }, appearance: Appearance) => {
|
||||
const themeKey: string = appearance.theme
|
||||
switch (themeKey) {
|
||||
case Theme.Light.key:
|
||||
|
|
|
@ -7,6 +7,7 @@ import DefaultFonts from '@/utils/fonts'
|
|||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { BaseConfig } from '~/src/types/preference'
|
||||
|
||||
export type AppearanceState = {
|
||||
appearance: Appearance
|
||||
|
@ -48,9 +49,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
resolve(conf)
|
||||
})
|
||||
})
|
||||
|
@ -82,9 +83,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
|
@ -103,9 +104,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
|
@ -124,10 +125,10 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
})
|
||||
|
@ -145,10 +146,10 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
})
|
||||
|
@ -167,9 +168,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
|
@ -188,9 +189,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
|
@ -209,9 +210,9 @@ const actions: ActionTree<AppearanceState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance as Appearance)
|
||||
commit(MUTATION_TYPES.UPDATE_APPEARANCE, conf.appearance)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf.appearance)
|
||||
})
|
||||
|
|
|
@ -3,13 +3,10 @@ import { Module, MutationTree, ActionTree } from 'vuex'
|
|||
import { RootState } from '@/store'
|
||||
import { Sound } from '~/src/types/sound'
|
||||
import { Timeline } from '~/src/types/timeline'
|
||||
import { BaseConfig, General } from '~/src/types/preference'
|
||||
|
||||
interface GeneralSet {
|
||||
sound: Sound,
|
||||
timeline: Timeline
|
||||
}
|
||||
export interface GeneralState {
|
||||
general: GeneralSet,
|
||||
general: General
|
||||
loading: boolean
|
||||
}
|
||||
|
||||
|
@ -34,7 +31,7 @@ export const MUTATION_TYPES = {
|
|||
}
|
||||
|
||||
const mutations: MutationTree<GeneralState> = {
|
||||
[MUTATION_TYPES.UPDATE_GENERAL]: (state, conf: GeneralSet) => {
|
||||
[MUTATION_TYPES.UPDATE_GENERAL]: (state, conf: General) => {
|
||||
state.general = conf
|
||||
},
|
||||
[MUTATION_TYPES.CHANGE_LOADING]: (state, value: boolean) => {
|
||||
|
@ -52,9 +49,9 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as GeneralSet)
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||
resolve(conf)
|
||||
})
|
||||
|
@ -63,7 +60,7 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
updateSound: ({ commit, state }, sound: object) => {
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
||||
const newSound: Sound = Object.assign({}, state.general.sound, sound)
|
||||
const newGeneral: GeneralSet = Object.assign({}, state.general, {
|
||||
const newGeneral: General = Object.assign({}, state.general, {
|
||||
sound: newSound
|
||||
})
|
||||
const config = {
|
||||
|
@ -76,9 +73,9 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as GeneralSet)
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||
resolve(conf)
|
||||
})
|
||||
|
@ -87,7 +84,7 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
updateTimeline: ({ commit, state, dispatch }, timeline: object) => {
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, true)
|
||||
const newTimeline: Timeline = Object.assign({}, state.general.timeline, timeline)
|
||||
const newGeneral: GeneralSet = Object.assign({}, state.general, {
|
||||
const newGeneral: General = Object.assign({}, state.general, {
|
||||
timeline: newTimeline
|
||||
})
|
||||
const config = {
|
||||
|
@ -99,9 +96,9 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
commit('changeLoading', false)
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as GeneralSet)
|
||||
commit(MUTATION_TYPES.UPDATE_GENERAL, conf.general as General)
|
||||
commit(MUTATION_TYPES.CHANGE_LOADING, false)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf)
|
||||
|
@ -110,11 +107,10 @@ const actions: ActionTree<GeneralState, RootState> = {
|
|||
})
|
||||
}
|
||||
}
|
||||
const General: Module<GeneralState, RootState> = {
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: state,
|
||||
mutations: mutations,
|
||||
actions: actions
|
||||
}
|
||||
|
||||
export default General
|
||||
} as Module<GeneralState, RootState>
|
||||
|
|
|
@ -3,6 +3,7 @@ import Language from '~/src/constants/language'
|
|||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { Language as LanguageSet } from '~/src/types/language'
|
||||
import { BaseConfig } from '~/src/types/preference'
|
||||
|
||||
export interface LanguageState {
|
||||
language: LanguageSet
|
||||
|
@ -36,7 +37,7 @@ const actions: ActionTree<LanguageState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_LANGUAGE, conf.language as LanguageSet)
|
||||
resolve(conf)
|
||||
|
|
|
@ -2,10 +2,7 @@ import { ipcRenderer } from 'electron'
|
|||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
import { Notify } from '~/src/types/notify'
|
||||
|
||||
interface Notification {
|
||||
notify: Notify
|
||||
}
|
||||
import { BaseConfig, Notification } from '~/src/types/preference'
|
||||
|
||||
export interface NotificationState {
|
||||
notification: Notification
|
||||
|
@ -40,9 +37,9 @@ const actions: ActionTree<NotificationState, RootState> = {
|
|||
ipcRenderer.removeAllListeners('response-get-preferences')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: any) => {
|
||||
ipcRenderer.once('response-get-preferences', (_, conf: BaseConfig) => {
|
||||
ipcRenderer.removeAllListeners('error-get-preferences')
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification as Notification)
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification)
|
||||
resolve(conf)
|
||||
})
|
||||
})
|
||||
|
@ -57,8 +54,8 @@ const actions: ActionTree<NotificationState, RootState> = {
|
|||
}
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.send('update-preferences', config)
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: any) => {
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification as Notification)
|
||||
ipcRenderer.once('response-update-preferences', (_, conf: BaseConfig) => {
|
||||
commit(MUTATION_TYPES.UPDATE_NOTIFICATION, conf.notification)
|
||||
dispatch('App/loadPreferences', null, { root: true })
|
||||
resolve(conf.notification)
|
||||
})
|
||||
|
|
|
@ -47,7 +47,7 @@ const actions: ActionTree<TimelineState, RootState> = {
|
|||
ipcRenderer.send('get-unread-notification', rootState.Settings.accountID)
|
||||
})
|
||||
},
|
||||
changeUnreadNotification: ({ dispatch, state, rootState }, timeline: any): Promise<boolean> => {
|
||||
changeUnreadNotification: ({ dispatch, state, rootState }, timeline: { key: boolean }): Promise<boolean> => {
|
||||
const settings: UnreadNotification = Object.assign({}, state.unreadNotification, timeline, {
|
||||
accountID: rootState.Settings.accountID
|
||||
})
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import { Sound } from '~/src/types/sound'
|
||||
import { Timeline } from '~/src/types/timeline'
|
||||
import { Notify } from '~/src/types/notify'
|
||||
import { Appearance } from '~/src/types/appearance'
|
||||
import { Language } from '~/src/types/language'
|
||||
|
||||
export type General = {
|
||||
sound: Sound
|
||||
timeline: Timeline
|
||||
}
|
||||
|
||||
export type State = {
|
||||
collapse: boolean
|
||||
hideGlobalHeader: boolean
|
||||
}
|
||||
|
||||
export type Notification = {
|
||||
notify: Notify
|
||||
}
|
||||
|
||||
export type BaseConfig = {
|
||||
general: General
|
||||
state: State
|
||||
language: Language
|
||||
notification: Notification
|
||||
appearance: Appearance
|
||||
}
|
Loading…
Reference in New Issue