From 35e9d0103b7f54386f7711ca759762e98d5a06a7 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Wed, 13 Apr 2022 21:14:21 +0500 Subject: [PATCH] fix? bug with rerendering breaking game --- website/src/App.tsx | 26 +++++++++++++------------- website/src/screens/IsolatedEntry.tsx | 1 - 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/website/src/App.tsx b/website/src/App.tsx index 0c29957..78b6376 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -145,8 +145,7 @@ class App extends Component { ReactGA.pageview(window.location.pathname + window.location.search); } dictionary.initialize().then((r) => { - this.checkUserCronJob.start(); - this.networkCronJob.start(); + this.cronJob.start(); this.setState({ dictionaryStatus: "ready", dictionaryInfo: r.dictionaryInfo, @@ -231,8 +230,7 @@ class App extends Component { public componentWillUnmount() { window.removeEventListener("scroll", this.handleScroll); - this.checkUserCronJob.stop(); - this.networkCronJob.stop(); + this.cronJob.stop(); stopLocalDbs(); Mousetrap.unbind(["ctrl+down", "ctrl+up", "command+down", "command+up"]); Mousetrap.unbind(["ctrl+b", "command+b"]); @@ -276,8 +274,10 @@ class App extends Component { private async handleLoadUser(): Promise { try { + console.log("getting user"); const prevUser = this.state.user; const userOnServer = await getUser(); + console.log({ userOnServer }); if (userOnServer === "offline") return; if (userOnServer) sendSubmissions(); if (!userOnServer) { @@ -323,10 +323,13 @@ class App extends Component { dictionary.update(() => { this.setState({ dictionaryStatus: "updating" }); }).then(({ dictionaryInfo }) => { - this.setState({ - dictionaryStatus: "ready", - dictionaryInfo, - }); + if (this.state.dictionaryInfo?.release !== dictionaryInfo?.release) { + // to avoid unnecessary re-rendering that breaks things + this.setState({ + dictionaryStatus: "ready", + dictionaryInfo, + }); + } }).catch(() => { this.setState({ dictionaryStatus: "error loading" }); }); @@ -414,14 +417,11 @@ class App extends Component { // TODO: right now not checking user very often cause it messes with the state? // causes the verb quizzer to reset? - private checkUserCronJob = new CronJob("1/20 * * * *", () => { + private cronJob = new CronJob("* * * * *", () => { + this.handleDictionaryUpdate(); this.handleLoadUser(); }) - private networkCronJob = new CronJob("1/5 * * * *", () => { - this.handleDictionaryUpdate(); - }); - /* istanbul ignore next */ private handleScroll() { if (hitBottom() && this.props.location.pathname === "/search" && this.state.results.length >= (pageSize * this.state.page)) { diff --git a/website/src/screens/IsolatedEntry.tsx b/website/src/screens/IsolatedEntry.tsx index 7bc0ab9..ef18341 100644 --- a/website/src/screens/IsolatedEntry.tsx +++ b/website/src/screens/IsolatedEntry.tsx @@ -102,7 +102,6 @@ function IsolatedEntry({ state, dictionary, isolateEntry }: { return false; } })(); - console.log(inf); return
{entry.p} - LingDocs Pashto Dictionary