From e064d2da4de67ad42268f8eea0efd20646b3cb16 Mon Sep 17 00:00:00 2001 From: wakarimasen Date: Thu, 9 Mar 2017 13:38:32 +0100 Subject: [PATCH] Use one error variable for all timelines --- src/components/timeline/timeline.js | 3 +++ src/components/timeline/timeline.vue | 6 +++--- src/modules/statuses.js | 21 ++++++++----------- .../timeline_fetcher.service.js | 13 ++---------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js index b4e80fe1..d5a9adcc 100644 --- a/src/components/timeline/timeline.js +++ b/src/components/timeline/timeline.js @@ -8,6 +8,9 @@ const Timeline = { 'timelineName', 'title' ], + computed: { + timelineError () { return this.$store.state.statuses.error } + }, components: { Status, StatusOrConversation diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index ac074f3c..b1ff327b 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -4,13 +4,13 @@
{{title}}
- - - diff --git a/src/modules/statuses.js b/src/modules/statuses.js index e4528520..051ec71b 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -8,6 +8,7 @@ export const defaultState = { maxId: 0, notifications: [], favorites: new Set(), + error: false, timelines: { mentions: { statuses: [], @@ -18,8 +19,7 @@ export const defaultState = { newStatusCount: 0, maxId: 0, minVisibleId: 0, - loading: false, - error: false + loading: false }, public: { statuses: [], @@ -30,8 +30,7 @@ export const defaultState = { newStatusCount: 0, maxId: 0, minVisibleId: 0, - loading: false, - error: false + loading: false }, publicAndExternal: { statuses: [], @@ -42,8 +41,7 @@ export const defaultState = { newStatusCount: 0, maxId: 0, minVisibleId: 0, - loading: false, - error: false + loading: false }, friends: { statuses: [], @@ -54,8 +52,7 @@ export const defaultState = { newStatusCount: 0, maxId: 0, minVisibleId: 0, - loading: false, - error: false + loading: false } } } @@ -298,8 +295,8 @@ export const mutations = { const newStatus = state.allStatusesObject[id] newStatus.nsfw = nsfw }, - setError (state, { timeline, value }) { - state.timelines[timeline].error = value + setError (state, { value }) { + state.error = value }, markNotificationsAsSeen (state, notifications) { each(notifications, (notification) => { @@ -314,8 +311,8 @@ const statuses = { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false }) { commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser }) }, - setError ({ rootState, commit }, { timeline, value }) { - commit('setError', { timeline, value }) + setError ({ rootState, commit }, { value }) { + commit('setError', { value }) }, deleteStatus ({ rootState, commit }, status) { commit('setDeleted', { status }) diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index e684a170..24aef069 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -5,7 +5,7 @@ import apiService from '../api/api.service.js' const update = ({store, statuses, timeline, showImmediately}) => { const ccTimeline = camelCase(timeline) - setError({store, timeline, value: false}) + store.dispatch('setError', { value: false }) store.dispatch('addNewStatuses', { 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 args = { timeline, credentials } const rootState = store.rootState || store.state @@ -36,7 +27,7 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false return apiService.fetchTimeline(args) .then((statuses) => update({store, statuses, timeline, showImmediately}), - () => setError({store, timeline, value: true})) + () => store.dispatch('setError', { value: true })) } const startFetching = ({ timeline = 'friends', credentials, store }) => {