From 219095a6c699aaeceefcaa8dd6d1727e59741721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=83=D8=A7=D8=B1=D9=84=20=D9=85=D8=A8=D8=A7=D8=B1=D9=83?= Date: Thu, 15 Jul 2021 13:29:54 +0200 Subject: [PATCH] resolves zulip client before routing --- front/src/App.vue | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/front/src/App.vue b/front/src/App.vue index d1da945..6d8ad62 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -40,13 +40,19 @@ export default { this.$store.commit("setMobile", this.checkIfMobile()); }); - this.getStreams(); + this.$router.beforeEach(async (to) => { + if (!this.zulipClient || this.streams.length == 0) { + await this.getStreams() + } + }) this.$router.afterEach((to) => { this.$store.commit("setTopics", []); this.$store.commit("setRules", []); this.$store.commit("setCurStream", to.path.replace("/", "")); - if (this.currentStream != "" && this.streams.find(s => s.name == this.currentStream)) { + if (this.currentStream != "" + && this.streams.find(s => s.name == this.currentStream) + ) { this.setUpDoc(this.currentStream); } }); @@ -56,16 +62,19 @@ export default { checkIfMobile: () => window.innerWidth < 700, getStreams() { - api.zulip.init().then((client) => { - this.zulipClient = client; - api.zulip.getStreams(client).then((result) => { - this.$store.commit( - "setStreams", - result.streams.filter((s) => s.name.startsWith(this.pubStr)) - ); - }); - api.zulip.listen(this.zulipClient, this.eventHandler); - }); + return new Promise((resolve) => { + api.zulip.init().then((client) => { + this.zulipClient = client; + api.zulip.getStreams(client).then((result) => { + this.$store.commit( + "setStreams", + result.streams.filter((s) => s.name.startsWith(this.pubStr)) + ); + resolve() + }); + api.zulip.listen(this.zulipClient, this.eventHandler); + }); + }) }, setUpDoc(stream) {