Skip to content

Commit

Permalink
Re-fetch settings every time the pop-up is loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonbear committed Mar 30, 2024
1 parent d434908 commit 65d5b9b
Showing 1 changed file with 50 additions and 51 deletions.
101 changes: 50 additions & 51 deletions src/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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) {
Expand Down

0 comments on commit 65d5b9b

Please sign in to comment.