move local settings to utils

This commit is contained in:
Arthur Lu 2024-06-17 21:02:15 +00:00
parent d3281fc27f
commit f58abd4d4d
3 changed files with 36 additions and 19 deletions

View File

@ -1,17 +1,8 @@
import { requestAPI } from "./utils.js";
import { getSyncSettings, requestAPI } from "./utils.js";
import { API } from "../vars.js";
export async function setupClientSync (callback) {
let scheme = localStorage.getItem("sync-scheme");
let rate = Number(localStorage.getItem("sync-rate"));
if (!scheme) {
scheme = "always";
localStorage.setItem("sync-scheme", "always");
}
if (!rate) {
rate = "5";
localStorage.setItem("sync-rate", "5");
}
const { scheme, rate } = getSyncSettings();
if (scheme === "always") {
callback();

View File

@ -1,4 +1,4 @@
import { requestPVE, requestAPI, goToPage, setTitleAndHeader, setAppearance } from "./utils.js";
import { requestPVE, requestAPI, goToPage, setTitleAndHeader, setAppearance, getSearchSettings } from "./utils.js";
import { alert, dialog } from "./dialog.js";
import { setupClientSync } from "./clientsync.js";
import wfAlign from "../modules/wfa.js";
@ -40,11 +40,7 @@ async function getInstances () {
}
async function populateInstances () {
let searchCriteria = localStorage.getItem("search-criteria");
if (!searchCriteria) {
searchCriteria = "fuzzy";
localStorage.setItem("search-criteria", "fuzzy");
}
const searchCriteria = getSearchSettings();
const searchQuery = document.querySelector("#search").value || null;
let criteria;
if (!searchQuery) {

View File

@ -268,11 +268,41 @@ export function setTitleAndHeader () {
document.querySelector("h1").innerText = organization;
}
const settingsDefault = {
"sync-scheme": "always",
"sync-rate": 5,
"search-criteria": "fuzzy",
"appearance-theme": "auto"
};
export function getSyncSettings () {
let scheme = localStorage.getItem("sync-scheme");
let rate = Number(localStorage.getItem("sync-rate"));
if (!scheme) {
scheme = settingsDefault["sync-scheme"];
localStorage.setItem("sync-scheme", scheme);
}
if (!rate) {
rate = settingsDefault["sync-rate"];
localStorage.setItem("sync-rate", rate);
}
return { scheme, rate };
}
export function getSearchSettings () {
let searchCriteria = localStorage.getItem("search-criteria");
if (!searchCriteria) {
searchCriteria = settingsDefault["search-criteria"];
localStorage.setItem("search-criteria", searchCriteria);
}
return searchCriteria;
}
export function setAppearance () {
let theme = localStorage.getItem("appearance-theme");
if (!theme) {
theme = "auto";
localStorage.setItem("appearance-theme", "auto");
theme = settingsDefault["appearance-theme"];
localStorage.setItem("appearance-theme", theme);
}
if (theme === "auto") {