Restructure status module for easier testing.
This commit is contained in:
parent
26d47c0f41
commit
78db0db637
|
@ -2,7 +2,7 @@ import { map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy,
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import apiService from '../services/api/api.service.js'
|
import apiService from '../services/api/api.service.js'
|
||||||
|
|
||||||
const defaultState = {
|
export const defaultState = {
|
||||||
allStatuses: [],
|
allStatuses: [],
|
||||||
maxId: 0,
|
maxId: 0,
|
||||||
timelines: {
|
timelines: {
|
||||||
|
@ -110,21 +110,7 @@ const updateTimestampsInStatuses = (statuses) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const statuses = {
|
export const mutations = {
|
||||||
state: defaultState,
|
|
||||||
actions: {
|
|
||||||
favorite ({ rootState, commit }, status) {
|
|
||||||
// Optimistic favoriting...
|
|
||||||
commit('setFavorited', { status, value: true })
|
|
||||||
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
|
||||||
},
|
|
||||||
unfavorite ({ rootState, commit }, status) {
|
|
||||||
// Optimistic favoriting...
|
|
||||||
commit('setFavorited', { status, value: false })
|
|
||||||
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
|
addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
|
||||||
state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline])
|
state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline])
|
||||||
state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses.id)
|
state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses.id)
|
||||||
|
@ -155,7 +141,23 @@ const statuses = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const statuses = {
|
||||||
|
state: defaultState,
|
||||||
|
actions: {
|
||||||
|
favorite ({ rootState, commit }, status) {
|
||||||
|
// Optimistic favoriting...
|
||||||
|
commit('setFavorited', { status, value: true })
|
||||||
|
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
||||||
|
},
|
||||||
|
unfavorite ({ rootState, commit }, status) {
|
||||||
|
// Optimistic favoriting...
|
||||||
|
commit('setFavorited', { status, value: false })
|
||||||
|
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
mutations
|
||||||
}
|
}
|
||||||
|
|
||||||
export default statuses
|
export default statuses
|
||||||
|
|
Loading…
Reference in New Issue