mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-01-19 12:20:20 +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 i18n from '~/src/config/i18n'
|
||||
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 {
|
||||
modalOpen: true,
|
||||
channel: '',
|
||||
@ -93,10 +93,11 @@ describe('Jump', () => {
|
||||
|
||||
describe('jump', () => {
|
||||
it('should be changed', () => {
|
||||
store.dispatch('Jump/jump', {
|
||||
const channel: Channel = {
|
||||
name: 'public',
|
||||
path: 'public'
|
||||
})
|
||||
}
|
||||
store.dispatch('Jump/jump', channel)
|
||||
expect(store.state.Jump.modalOpen).toEqual(false)
|
||||
expect(router.push).toHaveBeenCalledWith({ path: '/0/public' })
|
||||
})
|
||||
|
@ -1,9 +1,11 @@
|
||||
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('mutations', () => {
|
||||
let state
|
||||
let state: JumpState
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
modalOpen: true,
|
||||
@ -53,59 +55,55 @@ describe('TimelineSpace/Modals/Jump', () => {
|
||||
|
||||
describe('updateListChannel', () => {
|
||||
it('should be updated', () => {
|
||||
const channelList = [
|
||||
{
|
||||
id: '0',
|
||||
const admin: List = {
|
||||
id: 0,
|
||||
title: 'admin'
|
||||
},
|
||||
{
|
||||
id: '1',
|
||||
}
|
||||
const engineer: List = {
|
||||
id: 1,
|
||||
title: 'engineer'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
}
|
||||
const designer: List = {
|
||||
id: 2,
|
||||
title: 'designer'
|
||||
}
|
||||
]
|
||||
Jump.mutations.updateListChannel(state, channelList)
|
||||
expect(state.listChannelList).toEqual([
|
||||
{
|
||||
path: 'lists/0',
|
||||
name: '#admin'
|
||||
},
|
||||
{
|
||||
path: 'lists/1',
|
||||
name: '#engineer'
|
||||
},
|
||||
{
|
||||
path: 'lists/2',
|
||||
name: '#designer'
|
||||
}
|
||||
])
|
||||
}
|
||||
const channelList = [admin, engineer, designer]
|
||||
Jump.mutations![MUTATION_TYPES.UPDATE_LIST_CHANNEL](state, channelList)
|
||||
const adminChannel: Channel = {
|
||||
path: 'lists/0',
|
||||
name: '#admin'
|
||||
}
|
||||
const engineerChannel: Channel = {
|
||||
path: 'lists/1',
|
||||
name: '#engineer'
|
||||
}
|
||||
const designerChannel: Channel = {
|
||||
path: 'lists/2',
|
||||
name: '#designer'
|
||||
}
|
||||
expect(state.listChannelList).toEqual([adminChannel, engineerChannel, designerChannel])
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateTagChannel', () => {
|
||||
it('should be updated', () => {
|
||||
const channelList = [
|
||||
{
|
||||
tagName: 'whalebird'
|
||||
},
|
||||
{
|
||||
tagName: 'tqrk'
|
||||
}
|
||||
]
|
||||
Jump.mutations.updateTagChannel(state, channelList)
|
||||
expect(state.tagChannelList).toEqual([
|
||||
{
|
||||
name: '#whalebird',
|
||||
path: 'hashtag/whalebird'
|
||||
},
|
||||
{
|
||||
name: '#tqrk',
|
||||
path: 'hashtag/tqrk'
|
||||
}
|
||||
])
|
||||
const whalebird: Hashtag = {
|
||||
tagName: 'whalebird'
|
||||
}
|
||||
const tqrk: Hashtag = {
|
||||
tagName: 'tqrk'
|
||||
}
|
||||
const channelList = [whalebird, tqrk]
|
||||
Jump.mutations![MUTATION_TYPES.UPDATE_TAG_CHANNEL](state, channelList)
|
||||
const whalebirdChannel: Channel = {
|
||||
name: '#whalebird',
|
||||
path: 'hashtag/whalebird'
|
||||
}
|
||||
const tqrkChannel: Channel = {
|
||||
name: '#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…
Reference in New Issue
Block a user