resolves zulip client before routing
This commit is contained in:
parent
6eb4968579
commit
219095a6c6
1 changed files with 21 additions and 12 deletions
|
|
@ -40,13 +40,19 @@ export default {
|
||||||
this.$store.commit("setMobile", this.checkIfMobile());
|
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.$router.afterEach((to) => {
|
||||||
this.$store.commit("setTopics", []);
|
this.$store.commit("setTopics", []);
|
||||||
this.$store.commit("setRules", []);
|
this.$store.commit("setRules", []);
|
||||||
this.$store.commit("setCurStream", to.path.replace("/", ""));
|
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);
|
this.setUpDoc(this.currentStream);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -56,6 +62,7 @@ export default {
|
||||||
checkIfMobile: () => window.innerWidth < 700,
|
checkIfMobile: () => window.innerWidth < 700,
|
||||||
|
|
||||||
getStreams() {
|
getStreams() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
api.zulip.init().then((client) => {
|
api.zulip.init().then((client) => {
|
||||||
this.zulipClient = client;
|
this.zulipClient = client;
|
||||||
api.zulip.getStreams(client).then((result) => {
|
api.zulip.getStreams(client).then((result) => {
|
||||||
|
|
@ -63,9 +70,11 @@ export default {
|
||||||
"setStreams",
|
"setStreams",
|
||||||
result.streams.filter((s) => s.name.startsWith(this.pubStr))
|
result.streams.filter((s) => s.name.startsWith(this.pubStr))
|
||||||
);
|
);
|
||||||
|
resolve()
|
||||||
});
|
});
|
||||||
api.zulip.listen(this.zulipClient, this.eventHandler);
|
api.zulip.listen(this.zulipClient, this.eventHandler);
|
||||||
});
|
});
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
setUpDoc(stream) {
|
setUpDoc(stream) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue