From 3aba0abeddd5136c5312bee9d96a5febd80c0270 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Mon, 2 Oct 2023 20:51:20 -0500 Subject: [PATCH] fix(router): use state to pass modal launch info --- website/client/src/components/tasks/user.vue | 9 +++++++++ website/client/src/router/index.js | 9 ++------- website/client/src/store/index.js | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/website/client/src/components/tasks/user.vue b/website/client/src/components/tasks/user.vue index 633b8c8da0..8acef03946 100644 --- a/website/client/src/components/tasks/user.vue +++ b/website/client/src/components/tasks/user.vue @@ -486,6 +486,15 @@ export default { this.$store.dispatch('common:setTitle', { section: this.$t('tasks'), }); + if (this.$store.state.postLoadModal) { + const modalToLoad = this.$store.state.postLoadModal; + if (modalToLoad.includes('profile')) { + this.$router.push(modalToLoad); + } else { + this.$root.$emit('bv::show::modal', modalToLoad); + } + this.$store.state.postLoadModal = ''; + } }, methods: { ...mapActions({ setUser: 'user:set' }), diff --git a/website/client/src/router/index.js b/website/client/src/router/index.js index 3238f17c44..13744b538e 100644 --- a/website/client/src/router/index.js +++ b/website/client/src/router/index.js @@ -320,12 +320,7 @@ router.beforeEach(async (to, from, next) => { startingPage = to.params.startingPage; } if (from.name === null) { - setTimeout(() => router.app.$emit('habitica:show-profile', { - userId: to.params.userId, - startingPage, - fromPath: '/', - toPath: to.path, - }), 500); + store.state.postLoadModal = `profile/${to.params.userId}`; return next({ name: 'tasks' }); } router.app.$emit('habitica:show-profile', { @@ -339,7 +334,7 @@ router.beforeEach(async (to, from, next) => { } if (to.name === 'tasks' && to.query.openGemsModal === 'true') { - setTimeout(() => router.app.$emit('bv::show::modal', 'buy-gems'), 500); + store.state.postLoadModal = 'buy-gems'; return next({ name: 'tasks' }); } diff --git a/website/client/src/store/index.js b/website/client/src/store/index.js index 20d2332406..56eaac19d7 100644 --- a/website/client/src/store/index.js +++ b/website/client/src/store/index.js @@ -151,6 +151,7 @@ export default function () { bugReportOptions: { question: false, }, + postLoadModal: '', }, });