diff --git a/src/stores/matchDetails.ts b/src/stores/matchDetails.ts index e62f0e5..7c17bac 100644 --- a/src/stores/matchDetails.ts +++ b/src/stores/matchDetails.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import type { Match } from "@/api"; +import type { Match } from "@/types"; export type RootState = { matchDetails: Match; diff --git a/src/stores/playerDetails.ts b/src/stores/playerDetails.ts index 99cfd62..b75b278 100644 --- a/src/stores/playerDetails.ts +++ b/src/stores/playerDetails.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import type { Player } from "@/api"; +import type { Player } from "@/types"; export type RootState = { playerDetails: Player; diff --git a/src/stores/playersArr.ts b/src/stores/playersArr.ts index c8b8284..b06d0a2 100644 --- a/src/stores/playersArr.ts +++ b/src/stores/playersArr.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import type { Player } from "@/api"; +import type { Player } from "@/types"; export type RootState = { playersArr: Player[]; diff --git a/src/types/LocalStoragePlayer.ts b/src/types/LocalStoragePlayer.ts new file mode 100644 index 0000000..e859b39 --- /dev/null +++ b/src/types/LocalStoragePlayer.ts @@ -0,0 +1,6 @@ +export interface LocalStoragePlayer { + steamId64: string; + vanityUrl: string; + name: string; + avatar: string; +} diff --git a/src/types/index.ts b/src/types/index.ts index c9bbbfe..d83cf0c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,3 +6,4 @@ export * from "@/types/MatchWeapons"; export * from "@/types/Player"; export * from "@/types/PlayerMate"; export * from "@/types/PlayerMeta"; +export * from "@/types/LocalStoragePlayer"; diff --git a/src/utils/LocalStorage.ts b/src/utils/LocalStorage.ts index fc781d9..849cd2f 100644 --- a/src/utils/LocalStorage.ts +++ b/src/utils/LocalStorage.ts @@ -1,39 +1,49 @@ -export type LSPlayer = { - steamId64: string; - vanityUrl: string; - name: string; - avatar: string; -}; +import type { LocalStoragePlayer } from "@/types"; -export const SaveLastVisitedToLocalStorage = (data: LSPlayer): void => { - const a = JSON.parse(localStorage.getItem("recent-visited") || ""); - console.log("hello"); - console.log("a: ", a); +export const SaveLastVisitedToLocalStorage = ( + data: LocalStoragePlayer +): void => { + const localData = localStorage.getItem("recent-visited"); + let a: Array; - if (a.length === 0) { + if (localData !== null) { + a = JSON.parse(localData); + + if (a.length === 0) { + } else if (a.length === 9) { + if (a.find((p: LocalStoragePlayer) => p.steamId64 === data.steamId64)) { + a.shift(); + a.splice( + a.findIndex( + (p: LocalStoragePlayer) => p.steamId64 === data.steamId64 + ), + 1 + ); + a.unshift(data); + } else if ( + !a.find((p: LocalStoragePlayer) => p.steamId64 === data.steamId64) + ) { + a.shift(); + a.unshift(data); + } + } else if (a.length > 0 && a.length < 9) { + if (a.find((p: LocalStoragePlayer) => p.steamId64 === data.steamId64)) { + a.splice( + a.findIndex( + (p: LocalStoragePlayer) => p.steamId64 === data.steamId64 + ), + 1 + ); + a.unshift(data); + } else if ( + !a.find((p: LocalStoragePlayer) => p.steamId64 === data.steamId64) + ) { + a.unshift(data); + } + } + } else { + a = []; 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)); diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index c1f128b..658521f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -1,5 +1,5 @@ import { GoToError } from "@/utils/GoTo"; -import type { Player, Stats } from "@/api"; +import type { MatchStats, Player } from "@/types"; enum ErrorPage { INTERNAL_SERVER_ERROR = 500, @@ -75,7 +75,7 @@ type PlayerArrayTextStyle = { color: string; }; export const getPlayerArr = ( - stats: Stats[], + stats: MatchStats[], team: number, color = false ): PlayerArrayType[] => { @@ -133,11 +133,11 @@ export const sortObjectValue = ( }; export const CreatePlayersArray = ( - stats: Stats[] + stats: MatchStats[] ): Array> => { const arr: Array> = []; for (let i = 0; i < stats.length; i++) { - arr.push({ team_id: stats[i].teamId, player: stats[i].player }); + arr.push({ team_id: stats[i].team_id, player: stats[i].player }); } return arr; };