Use one error variable for all timelines

This commit is contained in:
wakarimasen 2017-03-09 13:38:32 +01:00
parent 64d71b75cf
commit e064d2da4d
4 changed files with 17 additions and 26 deletions

View file

@ -8,6 +8,9 @@ const Timeline = {
'timelineName', 'timelineName',
'title' 'title'
], ],
computed: {
timelineError () { return this.$store.state.statuses.error }
},
components: { components: {
Status, Status,
StatusOrConversation StatusOrConversation

View file

@ -4,13 +4,13 @@
<div class="title"> <div class="title">
{{title}} {{title}}
</div> </div>
<button @click.prevent="showNewStatuses" class="base06 base02-background loadmore-button" v-if="timeline.newStatusCount > 0 && !timeline.error"> <button @click.prevent="showNewStatuses" class="base06 base02-background loadmore-button" v-if="timeline.newStatusCount > 0 && !timelineError">
Show new ({{timeline.newStatusCount}}) Show new ({{timeline.newStatusCount}})
</button> </button>
<button @click.prevent class="base06 error no-press loadmore-button" v-if="timeline.error"> <button @click.prevent class="base06 error no-press loadmore-button" v-if="timelineError">
Error fetching updates Error fetching updates
</button> </button>
<button @click.prevent class="base04 base01-background no-press loadmore-button" v-if="!timeline.newStatusCount > 0 && !timeline.error"> <button @click.prevent class="base04 base01-background no-press loadmore-button" v-if="!timeline.newStatusCount > 0 && !timelineError">
Up-to-date Up-to-date
</button> </button>
</div> </div>

View file

@ -8,6 +8,7 @@ export const defaultState = {
maxId: 0, maxId: 0,
notifications: [], notifications: [],
favorites: new Set(), favorites: new Set(),
error: false,
timelines: { timelines: {
mentions: { mentions: {
statuses: [], statuses: [],
@ -18,8 +19,7 @@ export const defaultState = {
newStatusCount: 0, newStatusCount: 0,
maxId: 0, maxId: 0,
minVisibleId: 0, minVisibleId: 0,
loading: false, loading: false
error: false
}, },
public: { public: {
statuses: [], statuses: [],
@ -30,8 +30,7 @@ export const defaultState = {
newStatusCount: 0, newStatusCount: 0,
maxId: 0, maxId: 0,
minVisibleId: 0, minVisibleId: 0,
loading: false, loading: false
error: false
}, },
publicAndExternal: { publicAndExternal: {
statuses: [], statuses: [],
@ -42,8 +41,7 @@ export const defaultState = {
newStatusCount: 0, newStatusCount: 0,
maxId: 0, maxId: 0,
minVisibleId: 0, minVisibleId: 0,
loading: false, loading: false
error: false
}, },
friends: { friends: {
statuses: [], statuses: [],
@ -54,8 +52,7 @@ export const defaultState = {
newStatusCount: 0, newStatusCount: 0,
maxId: 0, maxId: 0,
minVisibleId: 0, minVisibleId: 0,
loading: false, loading: false
error: false
} }
} }
} }
@ -298,8 +295,8 @@ export const mutations = {
const newStatus = state.allStatusesObject[id] const newStatus = state.allStatusesObject[id]
newStatus.nsfw = nsfw newStatus.nsfw = nsfw
}, },
setError (state, { timeline, value }) { setError (state, { value }) {
state.timelines[timeline].error = value state.error = value
}, },
markNotificationsAsSeen (state, notifications) { markNotificationsAsSeen (state, notifications) {
each(notifications, (notification) => { each(notifications, (notification) => {
@ -314,8 +311,8 @@ const statuses = {
addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) {
commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser }) commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser })
}, },
setError ({ rootState, commit }, { timeline, value }) { setError ({ rootState, commit }, { value }) {
commit('setError', { timeline, value }) commit('setError', { value })
}, },
deleteStatus ({ rootState, commit }, status) { deleteStatus ({ rootState, commit }, status) {
commit('setDeleted', { status }) commit('setDeleted', { status })

View file

@ -5,7 +5,7 @@ import apiService from '../api/api.service.js'
const update = ({store, statuses, timeline, showImmediately}) => { const update = ({store, statuses, timeline, showImmediately}) => {
const ccTimeline = camelCase(timeline) const ccTimeline = camelCase(timeline)
setError({store, timeline, value: false}) store.dispatch('setError', { value: false })
store.dispatch('addNewStatuses', { store.dispatch('addNewStatuses', {
timeline: ccTimeline, timeline: ccTimeline,
@ -14,15 +14,6 @@ const update = ({store, statuses, timeline, showImmediately}) => {
}) })
} }
const setError = ({store, timeline, value}) => {
const ccTimeline = camelCase(timeline)
store.dispatch('setError', {
timeline: ccTimeline,
value
})
}
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false}) => { const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false}) => {
const args = { timeline, credentials } const args = { timeline, credentials }
const rootState = store.rootState || store.state const rootState = store.rootState || store.state
@ -36,7 +27,7 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false
return apiService.fetchTimeline(args) return apiService.fetchTimeline(args)
.then((statuses) => update({store, statuses, timeline, showImmediately}), .then((statuses) => update({store, statuses, timeline, showImmediately}),
() => setError({store, timeline, value: true})) () => store.dispatch('setError', { value: true }))
} }
const startFetching = ({ timeline = 'friends', credentials, store }) => { const startFetching = ({ timeline = 'friends', credentials, store }) => {