export type LSPlayer = { steamId64: string; vanityUrl: string; name: string; avatar: string; }; export const SaveLastVisitedToLocalStorage = (data: LSPlayer): void => { const a = JSON.parse(localStorage.getItem("recent-visited") || ""); console.log("hello"); console.log("a: ", a); if (a.length === 0) { a.unshift(data); } else if (a.length === 9) { if (a.find((p: LSPlayer) => p.steamId64 === data.steamId64)) { a.shift(); a.splice( a.findIndex((p: LSPlayer) => p.steamId64 === data.steamId64), 1 ); a.unshift(data); } else if (!a.find((p: LSPlayer) => p.steamId64 === data.steamId64)) { a.shift(); a.unshift(data); } } else if (a.length > 0 && a.length < 9) { if (a.find((p: LSPlayer) => p.steamId64 === data.steamId64)) { a.splice( a.findIndex((p: LSPlayer) => p.steamId64 === data.steamId64), 1 ); a.unshift(data); } else if (!a.find((p: LSPlayer) => p.steamId64 === data.steamId64)) { a.unshift(data); } } localStorage.setItem("recent-visited", JSON.stringify(a)); };