From 65d5b9bdce0fa5517670afb5e1acf051f457948a Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sat, 30 Mar 2024 13:45:52 -0700 Subject: [PATCH] Re-fetch settings every time the pop-up is loaded. --- src/popup.tsx | 101 +++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/src/popup.tsx b/src/popup.tsx index e96715e..4c52f74 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -354,61 +354,60 @@ if (!document.getElementById(ROOT_CONTAINER_ID)) { } }, [apiKey, popupDisplayed]); - useEffect(() => { - async function handle() { - let syncSettings: ExtensionSyncSettings; - let localSettings: ExtensionLocalSettings; + const fetchAndLoadSettings = async (): Promise => { + let syncSettings: ExtensionSyncSettings; + let localSettings: ExtensionLocalSettings; - try { - localSettings = await getLocalSettings(chrome.storage.local); - } catch (e) { - setStatus({ - severity: "error", - title: "Error", - message: "Could not get local settings!", - }); - return; - } + try { + localSettings = await getLocalSettings(chrome.storage.local); + } catch (e) { + setStatus({ + severity: "error", + title: "Error", + message: "Could not get local settings!", + }); + return; + } - try { - syncSettings = await getSyncSettings(chrome.storage.sync); - setPresets(syncSettings.presets); - } catch (e) { - setStatus({ - severity: "error", - title: "Error", - message: "Could not get sync settings!", - }); - return; - } + try { + syncSettings = await getSyncSettings(chrome.storage.sync); + setPresets(syncSettings.presets); + } catch (e) { + setStatus({ + severity: "error", + title: "Error", + message: "Could not get sync settings!", + }); + return; + } - setHost(localSettings.host); - setInsecureMode(localSettings.insecureMode ?? false); - setApiKey(localSettings.apiKey); - setSearchEnabled(syncSettings.searchMatch.enabled); - if (syncSettings.searchMatch.mentions.suggestionEnabled) { - setSearchMatchMentionTemplate( - syncSettings.searchMatch.mentions.template - ); - } else { - setSearchMatchMentionTemplate(undefined); - } - if (syncSettings.searchMatch.direct.suggestionEnabled) { - setSearchMatchDirectTemplate( - syncSettings.searchMatch.direct.template - ); - } else { - setSearchMatchDirectTemplate(undefined); - } - if (syncSettings.searchMatch.enabled) { - setHoverEnabled(syncSettings.searchMatch.hoverEnabled); - } else { - setHoverEnabled(false); - } - setOnboardedToVersion(syncSettings.onboardedToVersion); + setHost(localSettings.host); + setInsecureMode(localSettings.insecureMode ?? false); + setApiKey(localSettings.apiKey); + setSearchEnabled(syncSettings.searchMatch.enabled); + if (syncSettings.searchMatch.mentions.suggestionEnabled) { + setSearchMatchMentionTemplate( + syncSettings.searchMatch.mentions.template + ); + } else { + setSearchMatchMentionTemplate(undefined); } - handle(); - }, []); + if (syncSettings.searchMatch.direct.suggestionEnabled) { + setSearchMatchDirectTemplate(syncSettings.searchMatch.direct.template); + } else { + setSearchMatchDirectTemplate(undefined); + } + if (syncSettings.searchMatch.enabled) { + setHoverEnabled(syncSettings.searchMatch.hoverEnabled); + } else { + setHoverEnabled(false); + } + setOnboardedToVersion(syncSettings.onboardedToVersion); + }; + + useEffect(() => { + fetchAndLoadSettings(); + }, [popupDisplayed]); useEffect(() => { if (host) {