diff --git a/frontend/src/scripts/controllers/tag-controller.js b/frontend/src/scripts/controllers/tag-controller.ts similarity index 68% rename from frontend/src/scripts/controllers/tag-controller.js rename to frontend/src/scripts/controllers/tag-controller.ts index 11de721e0..afe757c76 100644 --- a/frontend/src/scripts/controllers/tag-controller.js +++ b/frontend/src/scripts/controllers/tag-controller.ts @@ -1,11 +1,11 @@ import * as DB from "../db"; import * as ModesNotice from "../elements/modes-notice"; -export function saveActiveToLocalStorage() { - let tags = []; +export function saveActiveToLocalStorage(): void { + const tags: string[] = []; try { - DB.getSnapshot().tags.forEach((tag) => { + DB.getSnapshot().tags?.forEach((tag) => { if (tag.active === true) { tags.push(tag._id); } @@ -21,10 +21,10 @@ export function saveActiveToLocalStorage() { } catch (e) {} } -export function clear(nosave = false) { +export function clear(nosave = false): void { const snapshot = DB.getSnapshot(); - snapshot.tags = snapshot.tags.map((tag) => { + snapshot.tags = snapshot.tags?.map((tag) => { tag.active = false; return tag; @@ -35,10 +35,10 @@ export function clear(nosave = false) { if (!nosave) saveActiveToLocalStorage(); } -export function set(tagid, state, nosave = false) { +export function set(tagid: string, state: boolean, nosave = false): void { const snapshot = DB.getSnapshot(); - snapshot.tags = snapshot.tags.map((tag) => { + snapshot.tags = snapshot.tags?.map((tag) => { if (tag._id === tagid) { tag.active = state; } @@ -51,8 +51,8 @@ export function set(tagid, state, nosave = false) { if (!nosave) saveActiveToLocalStorage(); } -export function toggle(tagid, nosave = false) { - DB.getSnapshot().tags.forEach((tag) => { +export function toggle(tagid: string, nosave = false): void { + DB.getSnapshot().tags?.forEach((tag) => { if (tag._id === tagid) { if (tag.active === undefined) { tag.active = true; @@ -65,16 +65,18 @@ export function toggle(tagid, nosave = false) { if (!nosave) saveActiveToLocalStorage(); } -export function loadActiveFromLocalStorage() { +export function loadActiveFromLocalStorage(): void { // let newTags = $.cookie("activeTags"); - let newTags = window.localStorage.getItem("activeTags"); + let newTags: string[] | string = window.localStorage.getItem( + "activeTags" + ) as string; if (newTags != undefined && newTags !== "") { try { newTags = JSON.parse(newTags) ?? []; } catch (e) { newTags = []; } - newTags.forEach((ntag) => { + (newTags as string[]).forEach((ntag) => { toggle(ntag, true); }); saveActiveToLocalStorage(); diff --git a/frontend/src/scripts/pages/settings.ts b/frontend/src/scripts/pages/settings.ts index 696e35a00..cae7cbcb3 100644 --- a/frontend/src/scripts/pages/settings.ts +++ b/frontend/src/scripts/pages/settings.ts @@ -835,7 +835,7 @@ $(document).on( ".pageSettings .section.tags .tagsList .tag .tagButton", (e) => { const target = e.currentTarget; - const tagid = $(target).parent(".tag").attr("id"); + const tagid = $(target).parent(".tag").attr("id") as string; TagController.toggle(tagid); $(target).toggleClass("active"); }