From 2ab2c3530cae43b8105452f1d653b1f133582de0 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 15 Feb 2022 15:40:02 +0100 Subject: [PATCH] converted psa to ts --- .../src/scripts/elements/{psa.js => psa.ts} | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) rename frontend/src/scripts/elements/{psa.js => psa.ts} (65%) 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(