diff --git a/frontend/src/scripts/elements/psa.js b/frontend/src/scripts/elements/psa.ts similarity index 65% rename from frontend/src/scripts/elements/psa.js rename to frontend/src/scripts/elements/psa.ts index 7e971ab45..53e84ef40 100644 --- a/frontend/src/scripts/elements/psa.js +++ b/frontend/src/scripts/elements/psa.ts @@ -1,32 +1,33 @@ import axiosInstance from "../axios-instance"; import * as Notifications from "./notifications"; +import * as MonkeyTypes from "../types/interfaces"; -function clearMemory() { +function clearMemory(): void { window.localStorage.setItem("confirmedPSAs", JSON.stringify([])); } -function getMemory() { - return JSON.parse(window.localStorage.getItem("confirmedPSAs")) ?? []; +function getMemory(): string[] { + return JSON.parse(window.localStorage.getItem("confirmedPSAs") ?? "") ?? []; } -function setMemory(id) { - let list = getMemory(); +function setMemory(id: string): void { + const list = getMemory(); list.push(id); window.localStorage.setItem("confirmedPSAs", JSON.stringify(list)); } -async function getLatest() { - let psa = await axiosInstance.get("/psa"); +async function getLatest(): Promise { + const psa = await axiosInstance.get("/psa"); return psa.data; } -export async function show() { +export async function show(): Promise { const latest = await getLatest(); if (latest == null || latest.length == 0) { clearMemory(); return; } - let localmemory = getMemory(); + const localmemory = getMemory(); latest.forEach((psa) => { if (localmemory.includes(psa._id) && psa.sticky === false) return; Notifications.addBanner(