mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-07 15:28:42 +01:00
refs #850 Replace Jump with typescript
This commit is contained in:
parent
94e3f57065
commit
1bb938e0a6
@ -2,9 +2,9 @@ import { createLocalVue } from '@vue/test-utils'
|
|||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import i18n from '~/src/config/i18n'
|
import i18n from '~/src/config/i18n'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
import Jump from '~/src/renderer/store/TimelineSpace/Modals/Jump'
|
import Jump, { JumpState, Channel } from '~/src/renderer/store/TimelineSpace/Modals/Jump'
|
||||||
|
|
||||||
const state = () => {
|
const state = (): JumpState => {
|
||||||
return {
|
return {
|
||||||
modalOpen: true,
|
modalOpen: true,
|
||||||
channel: '',
|
channel: '',
|
||||||
@ -93,10 +93,11 @@ describe('Jump', () => {
|
|||||||
|
|
||||||
describe('jump', () => {
|
describe('jump', () => {
|
||||||
it('should be changed', () => {
|
it('should be changed', () => {
|
||||||
store.dispatch('Jump/jump', {
|
const channel: Channel = {
|
||||||
name: 'public',
|
name: 'public',
|
||||||
path: 'public'
|
path: 'public'
|
||||||
})
|
}
|
||||||
|
store.dispatch('Jump/jump', channel)
|
||||||
expect(store.state.Jump.modalOpen).toEqual(false)
|
expect(store.state.Jump.modalOpen).toEqual(false)
|
||||||
expect(router.push).toHaveBeenCalledWith({ path: '/0/public' })
|
expect(router.push).toHaveBeenCalledWith({ path: '/0/public' })
|
||||||
})
|
})
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import i18n from '~/src/config/i18n'
|
import i18n from '~/src/config/i18n'
|
||||||
import Jump from '@/store/TimelineSpace/Modals/Jump'
|
import Jump, { JumpState, MUTATION_TYPES, Channel } from '@/store/TimelineSpace/Modals/Jump'
|
||||||
|
import Hashtag from '~/src/types/hashtag'
|
||||||
|
import { List } from 'megalodon'
|
||||||
|
|
||||||
describe('TimelineSpace/Modals/Jump', () => {
|
describe('TimelineSpace/Modals/Jump', () => {
|
||||||
describe('mutations', () => {
|
describe('mutations', () => {
|
||||||
let state
|
let state: JumpState
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
state = {
|
state = {
|
||||||
modalOpen: true,
|
modalOpen: true,
|
||||||
@ -53,59 +55,55 @@ describe('TimelineSpace/Modals/Jump', () => {
|
|||||||
|
|
||||||
describe('updateListChannel', () => {
|
describe('updateListChannel', () => {
|
||||||
it('should be updated', () => {
|
it('should be updated', () => {
|
||||||
const channelList = [
|
const admin: List = {
|
||||||
{
|
id: 0,
|
||||||
id: '0',
|
|
||||||
title: 'admin'
|
title: 'admin'
|
||||||
},
|
}
|
||||||
{
|
const engineer: List = {
|
||||||
id: '1',
|
id: 1,
|
||||||
title: 'engineer'
|
title: 'engineer'
|
||||||
},
|
}
|
||||||
{
|
const designer: List = {
|
||||||
id: '2',
|
id: 2,
|
||||||
title: 'designer'
|
title: 'designer'
|
||||||
}
|
}
|
||||||
]
|
const channelList = [admin, engineer, designer]
|
||||||
Jump.mutations.updateListChannel(state, channelList)
|
Jump.mutations![MUTATION_TYPES.UPDATE_LIST_CHANNEL](state, channelList)
|
||||||
expect(state.listChannelList).toEqual([
|
const adminChannel: Channel = {
|
||||||
{
|
|
||||||
path: 'lists/0',
|
path: 'lists/0',
|
||||||
name: '#admin'
|
name: '#admin'
|
||||||
},
|
}
|
||||||
{
|
const engineerChannel: Channel = {
|
||||||
path: 'lists/1',
|
path: 'lists/1',
|
||||||
name: '#engineer'
|
name: '#engineer'
|
||||||
},
|
}
|
||||||
{
|
const designerChannel: Channel = {
|
||||||
path: 'lists/2',
|
path: 'lists/2',
|
||||||
name: '#designer'
|
name: '#designer'
|
||||||
}
|
}
|
||||||
])
|
expect(state.listChannelList).toEqual([adminChannel, engineerChannel, designerChannel])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('updateTagChannel', () => {
|
describe('updateTagChannel', () => {
|
||||||
it('should be updated', () => {
|
it('should be updated', () => {
|
||||||
const channelList = [
|
const whalebird: Hashtag = {
|
||||||
{
|
|
||||||
tagName: 'whalebird'
|
tagName: 'whalebird'
|
||||||
},
|
}
|
||||||
{
|
const tqrk: Hashtag = {
|
||||||
tagName: 'tqrk'
|
tagName: 'tqrk'
|
||||||
}
|
}
|
||||||
]
|
const channelList = [whalebird, tqrk]
|
||||||
Jump.mutations.updateTagChannel(state, channelList)
|
Jump.mutations![MUTATION_TYPES.UPDATE_TAG_CHANNEL](state, channelList)
|
||||||
expect(state.tagChannelList).toEqual([
|
const whalebirdChannel: Channel = {
|
||||||
{
|
|
||||||
name: '#whalebird',
|
name: '#whalebird',
|
||||||
path: 'hashtag/whalebird'
|
path: 'hashtag/whalebird'
|
||||||
},
|
}
|
||||||
{
|
const tqrkChannel: Channel = {
|
||||||
name: '#tqrk',
|
name: '#tqrk',
|
||||||
path: 'hashtag/tqrk'
|
path: 'hashtag/tqrk'
|
||||||
}
|
}
|
||||||
])
|
expect(state.tagChannelList).toEqual([whalebirdChannel, tqrkChannel])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
import router from '@/router'
|
|
||||||
import i18n from '~/src/config/i18n'
|
|
||||||
|
|
||||||
const Jump = {
|
|
||||||
namespaced: true,
|
|
||||||
state: {
|
|
||||||
modalOpen: false,
|
|
||||||
channel: '',
|
|
||||||
defaultChannelList: [
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.home'),
|
|
||||||
path: 'home'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.notification'),
|
|
||||||
path: 'notifications'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.mention'),
|
|
||||||
path: 'mentions'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.favourite'),
|
|
||||||
path: 'favourites'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.local'),
|
|
||||||
path: 'local'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.public'),
|
|
||||||
path: 'public'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.hashtag'),
|
|
||||||
path: 'hashtag'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.search'),
|
|
||||||
path: 'search'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: i18n.t('side_menu.direct'),
|
|
||||||
path: 'direct-messages'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
listChannelList: [],
|
|
||||||
tagChannelList: [],
|
|
||||||
selectedChannel: {
|
|
||||||
name: i18n.t('side_menu.home'),
|
|
||||||
path: 'home'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
changeModal (state, value) {
|
|
||||||
state.modalOpen = value
|
|
||||||
},
|
|
||||||
updateChannel (state, value) {
|
|
||||||
state.channel = value
|
|
||||||
},
|
|
||||||
changeSelected (state, value) {
|
|
||||||
state.selectedChannel = value
|
|
||||||
},
|
|
||||||
updateListChannel (state, list) {
|
|
||||||
state.listChannelList = list.map((l) => {
|
|
||||||
return {
|
|
||||||
name: `#${l.title}`,
|
|
||||||
path: `lists/${l.id}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
updateTagChannel (state, tags) {
|
|
||||||
state.tagChannelList = tags.map(t => {
|
|
||||||
return {
|
|
||||||
name: `#${t.tagName}`,
|
|
||||||
path: `hashtag/${t.tagName}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
jumpCurrentSelected ({ state, commit, rootState }) {
|
|
||||||
commit('changeModal', false)
|
|
||||||
router.push({ path: `/${rootState.TimelineSpace.account._id}/${state.selectedChannel.path}` })
|
|
||||||
},
|
|
||||||
jump ({ commit, rootState }, channel) {
|
|
||||||
commit('changeModal', false)
|
|
||||||
router.push({ path: `/${rootState.TimelineSpace.account._id}/${channel.path}` })
|
|
||||||
},
|
|
||||||
syncListChannel ({ commit, rootState }) {
|
|
||||||
commit('updateListChannel', rootState.TimelineSpace.SideMenu.lists)
|
|
||||||
},
|
|
||||||
syncTagChannel ({ commit, rootState }) {
|
|
||||||
commit('updateTagChannel', rootState.TimelineSpace.SideMenu.tags)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Jump
|
|
133
src/renderer/store/TimelineSpace/Modals/Jump.ts
Normal file
133
src/renderer/store/TimelineSpace/Modals/Jump.ts
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
import router from '@/router'
|
||||||
|
import i18n from '~/src/config/i18n'
|
||||||
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
|
import { List } from 'megalodon'
|
||||||
|
import Hashtag from '~/src/types/hashtag'
|
||||||
|
|
||||||
|
export interface Channel {
|
||||||
|
name: string,
|
||||||
|
path: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface JumpState {
|
||||||
|
modalOpen: boolean,
|
||||||
|
channel: string,
|
||||||
|
defaultChannelList: Array<Channel>,
|
||||||
|
listChannelList: Array<Channel>,
|
||||||
|
tagChannelList: Array<Channel>,
|
||||||
|
selectedChannel: Channel
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = (): JumpState => ({
|
||||||
|
modalOpen: false,
|
||||||
|
channel: '',
|
||||||
|
defaultChannelList: [
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.home'),
|
||||||
|
path: 'home'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.notification'),
|
||||||
|
path: 'notifications'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.mention'),
|
||||||
|
path: 'mentions'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.favourite'),
|
||||||
|
path: 'favourites'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.local'),
|
||||||
|
path: 'local'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.public'),
|
||||||
|
path: 'public'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.hashtag'),
|
||||||
|
path: 'hashtag'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.search'),
|
||||||
|
path: 'search'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n.t('side_menu.direct'),
|
||||||
|
path: 'direct-messages'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
listChannelList: [],
|
||||||
|
tagChannelList: [],
|
||||||
|
selectedChannel: {
|
||||||
|
name: i18n.t('side_menu.home'),
|
||||||
|
path: 'home'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export const MUTATION_TYPES = {
|
||||||
|
CHANGE_MODAL: 'changeModal',
|
||||||
|
UPDATE_CHANNEL: 'updateChannel',
|
||||||
|
CHANGE_SELECTED: 'changeSelected',
|
||||||
|
UPDATE_LIST_CHANNEL: 'updateListChannel',
|
||||||
|
UPDATE_TAG_CHANNEL: 'updateTagChannel'
|
||||||
|
}
|
||||||
|
|
||||||
|
const mutations: MutationTree<JumpState> = {
|
||||||
|
[MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => {
|
||||||
|
state.modalOpen = value
|
||||||
|
},
|
||||||
|
[MUTATION_TYPES.UPDATE_CHANNEL]: (state, channel: string) => {
|
||||||
|
state.channel = channel
|
||||||
|
},
|
||||||
|
[MUTATION_TYPES.CHANGE_SELECTED]: (state, channel: Channel) => {
|
||||||
|
state.selectedChannel = channel
|
||||||
|
},
|
||||||
|
[MUTATION_TYPES.UPDATE_LIST_CHANNEL]: (state, lists: Array<List>) => {
|
||||||
|
state.listChannelList = lists.map((l) => {
|
||||||
|
const channel: Channel = {
|
||||||
|
name: `#${l.title}`,
|
||||||
|
path: `lists/${l.id}`
|
||||||
|
}
|
||||||
|
return channel
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[MUTATION_TYPES.UPDATE_TAG_CHANNEL]: (state, tags: Array<Hashtag>) => {
|
||||||
|
state.tagChannelList = tags.map(t => {
|
||||||
|
const channel: Channel = {
|
||||||
|
name: `#${t.tagName}`,
|
||||||
|
path: `hashtag/${t.tagName}`
|
||||||
|
}
|
||||||
|
return channel
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use type of rootState
|
||||||
|
const actions: ActionTree<JumpState, any> = {
|
||||||
|
jumpCurrentSelected: ({ state, commit, rootState }) => {
|
||||||
|
commit(MUTATION_TYPES.CHANGE_MODAL, false)
|
||||||
|
router.push({ path: `/${rootState.TimelineSpace.account._id}/${state.selectedChannel.path}` })
|
||||||
|
},
|
||||||
|
jump: ({ commit, rootState }, channel: Channel) => {
|
||||||
|
commit(MUTATION_TYPES.CHANGE_MODAL, false)
|
||||||
|
router.push({ path: `/${rootState.TimelineSpace.account._id}/${channel.path}` })
|
||||||
|
},
|
||||||
|
syncListChannel: ({ commit, rootState }) => {
|
||||||
|
commit(MUTATION_TYPES.UPDATE_LIST_CHANNEL, rootState.TimelineSpace.SideMenu.lists)
|
||||||
|
},
|
||||||
|
syncTagChannel: ({ commit, rootState }) => {
|
||||||
|
commit(MUTATION_TYPES.UPDATE_TAG_CHANNEL, rootState.TimelineSpace.SideMenu.tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Jump: Module<JumpState, any> = {
|
||||||
|
namespaced: true,
|
||||||
|
state: state,
|
||||||
|
mutations: mutations,
|
||||||
|
actions: actions
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Jump
|
Loading…
x
Reference in New Issue
Block a user