aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-16 11:21:46 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-16 11:21:46 +0100
commit9abc6a25c89251659c5ffe2f59f6379cbf9f8e04 (patch)
treecbea5cb90c3b0cd4c88428a4f1a3dc063f367ae3 /components
parentb2e0569eb74cddc92c1e8576755137aa64f95d86 (diff)
prevent repeat api requests
Diffstat (limited to 'components')
-rw-r--r--components/account.tsx2
-rw-r--r--components/navbar.tsx2
-rw-r--r--components/preferencesContext.tsx12
3 files changed, 6 insertions, 10 deletions
diff --git a/components/account.tsx b/components/account.tsx
index 005e0d1..7b825cd 100644
--- a/components/account.tsx
+++ b/components/account.tsx
@@ -1,5 +1,3 @@
-import { useState, useEffect } from 'react';
-
var dummy = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4z/j/PwAHAQL/gXZXNQAAAABJRU5ErkJggg==";
export function AccountAvatar(props: {
diff --git a/components/navbar.tsx b/components/navbar.tsx
index 2c38c3c..252635d 100644
--- a/components/navbar.tsx
+++ b/components/navbar.tsx
@@ -46,7 +46,7 @@ export function NavBar() {
}
setGotData(true);
- })()});
+ })()}, []);
return <div className="navbar" style={{
width: 48,
diff --git a/components/preferencesContext.tsx b/components/preferencesContext.tsx
index 6b7914f..1b58a4f 100644
--- a/components/preferencesContext.tsx
+++ b/components/preferencesContext.tsx
@@ -12,13 +12,13 @@ function applyPreferences(preferences: userPreferences) {
var PreferencesContext = createContext<{ preferences?: userPreferences; updatePreference?: (newPreference: userPreferences) => void }>({});
export function PreferencesContextWrapper(props: { children?: ReactNode }) {
- var [gotData, setGotData] = useState(false);
+ var server = typeof window === "undefined";
+ var loggedIn = !server && document.cookie.includes("token");
+
var [preferences, setPreferences] = useState<userPreferences>();
useEffect(() => {(async() => {
- if (gotData) return;
- if (typeof window === "undefined") return;
- if (!document.cookie.includes("token")) return;
+ if (!loggedIn) return;
var local_prefs = window.localStorage.getItem("preferences");
if (local_prefs) {
@@ -37,9 +37,7 @@ export function PreferencesContextWrapper(props: { children?: ReactNode }) {
window.localStorage.setItem("preferences", JSON.stringify(preferencesReq.data.preferences));
setPreferences(preferencesReq.data.preferences);
}
-
- setGotData(true);
- })()});
+ })()}, []);
useEffect(() => applyPreferences(preferences), [preferences]);