diff --git a/frontend/src/pages/SubscriptionWorkPage.vue b/frontend/src/pages/SubscriptionWorkPage.vue index 067b3c6eea574aff5f22919c1766d2e861b2c7f1..980b9250850c56b36a3c4ea7b01619a5eeff8877 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 e7ac38b6398684c67fa188f66d9e8d815c3b7bc1..7ce8219ae8577f567239625822a05589ac88d65f 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 e7f181e5fa891934dc841d608c7626e231eb9dcb..2d43594bb02ee3c47fb04b5394c075bf239b45ef 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()