fixed types and LocalStoragePlayer.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
import type { Match } from "@/api";
|
||||
import type { Match } from "@/types";
|
||||
|
||||
export type RootState = {
|
||||
matchDetails: Match;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
import type { Player } from "@/api";
|
||||
import type { Player } from "@/types";
|
||||
|
||||
export type RootState = {
|
||||
playerDetails: Player;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
import type { Player } from "@/api";
|
||||
import type { Player } from "@/types";
|
||||
|
||||
export type RootState = {
|
||||
playersArr: Player[];
|
||||
|
6
src/types/LocalStoragePlayer.ts
Normal file
6
src/types/LocalStoragePlayer.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface LocalStoragePlayer {
|
||||
steamId64: string;
|
||||
vanityUrl: string;
|
||||
name: string;
|
||||
avatar: string;
|
||||
}
|
@@ -6,3 +6,4 @@ export * from "@/types/MatchWeapons";
|
||||
export * from "@/types/Player";
|
||||
export * from "@/types/PlayerMate";
|
||||
export * from "@/types/PlayerMeta";
|
||||
export * from "@/types/LocalStoragePlayer";
|
||||
|
@@ -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<LocalStoragePlayer>;
|
||||
|
||||
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));
|
||||
|
@@ -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<Record<string, number | Player | undefined>> => {
|
||||
const arr: Array<Record<string, number | Player | undefined>> = [];
|
||||
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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user