converted psa to ts

This commit is contained in:
Miodec 2022-02-15 15:40:02 +01:00
parent 2769255a2b
commit 2ab2c3530c

View file

@ -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<MonkeyTypes.PSA[]> {
const psa = await axiosInstance.get("/psa");
return psa.data;
}
export async function show() {
export async function show(): Promise<void> {
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(