From b95a2a69b2dbaa2aa84e6ca7664ac8babfc0ec10 Mon Sep 17 00:00:00 2001 From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de> Date: Mon, 1 Oct 2018 19:50:51 +0200 Subject: [PATCH] Active assignments are more aggressively cleared Also, there is no annoying reload upon logout anymore --- frontend/src/pages/SubscriptionWorkPage.vue | 13 ++++++----- frontend/src/store/actions.ts | 2 -- frontend/src/store/modules/subscriptions.ts | 26 +++++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/frontend/src/pages/SubscriptionWorkPage.vue b/frontend/src/pages/SubscriptionWorkPage.vue index 067b3c6e..980b9250 100644 --- a/frontend/src/pages/SubscriptionWorkPage.vue +++ b/frontend/src/pages/SubscriptionWorkPage.vue @@ -41,11 +41,9 @@ import RouteChangeConfirmation from '@/components/submission_notes/RouteChangeCo import { getters } from '@/store/getters' function onRouteEnterOrUpdate (to, from, next) { - if (to.name === 'subscription') { - Subscriptions.changeActiveSubscription(to.params['pk']).then(() => { - next() - }) - } + Subscriptions.changeActiveSubscription(to.params['pk']).then(() => { + next() + }) } export default { @@ -88,7 +86,10 @@ export default { if (to.name === 'subscription-ended') { next() } else { - this.nextRoute = next + this.nextRoute = () => { + Subscriptions.removeActiveSubscription() + next() + } } }, methods: { diff --git a/frontend/src/store/actions.ts b/frontend/src/store/actions.ts index e7ac38b6..7ce8219a 100644 --- a/frontend/src/store/actions.ts +++ b/frontend/src/store/actions.ts @@ -78,8 +78,6 @@ function logout ( } router.push({ name: 'login' }, () => { resetState({ message }) - // there should be a better way to solve the issue of resetting the once() function used in subscription module - router.go(0) }) } diff --git a/frontend/src/store/modules/subscriptions.ts b/frontend/src/store/modules/subscriptions.ts index e7f181e5..2d43594b 100644 --- a/frontend/src/store/modules/subscriptions.ts +++ b/frontend/src/store/modules/subscriptions.ts @@ -144,6 +144,7 @@ function POP_ASSIGNMENT_FROM_QUEUE (state: SubscriptionsState): void { } function RESET_STATE (state: SubscriptionsState): void { Object.assign(state, initialState()) + subscribeToAll.reset() } async function subscribeTo ( @@ -217,20 +218,21 @@ async function deleteActiveAssignments ({ state }: BareActionContext<Subscriptio })) } async function changeActiveSubscription ({ state }: BareActionContext<SubscriptionsState, RootState>, subscriptionPk = '') { - if (subscriptionPk !== state.activeSubscriptionPk) { - await Subscriptions.deleteActiveAssignments() - Subscriptions.SET_ACTIVE_SUBSCRIPTION_PK(subscriptionPk) - let assignmentsPromises = await Subscriptions.getAssignmentsForActiveSubscription(MAX_NUMBER_OF_ASSIGNMENTS) - let createdAssignments = [] - // TODO refactor this since it's very bad to await promises in for loops + if (subscriptionPk === state.activeSubscriptionPk) { + return + } + await Subscriptions.deleteActiveAssignments() + Subscriptions.SET_ACTIVE_SUBSCRIPTION_PK(subscriptionPk) + let assignmentsPromises = await Subscriptions.getAssignmentsForActiveSubscription(MAX_NUMBER_OF_ASSIGNMENTS) + let createdAssignments = [] + // TODO refactor this since it's very bad to await promises in for loops - for (let promise of assignmentsPromises) { - try { - createdAssignments.push(await promise) - } catch (_) {} - } - Subscriptions.SET_ASSIGNMENT_QUEUE(createdAssignments) + for (let promise of assignmentsPromises) { + try { + createdAssignments.push(await promise) + } catch (_) {} } + Subscriptions.SET_ASSIGNMENT_QUEUE(createdAssignments) } async function removeActiveSubscription () { await Subscriptions.deleteActiveAssignments() -- GitLab