fixed types and LocalStoragePlayer.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import type { Match } from "@/api";
|
import type { Match } from "@/types";
|
||||||
|
|
||||||
export type RootState = {
|
export type RootState = {
|
||||||
matchDetails: Match;
|
matchDetails: Match;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import type { Player } from "@/api";
|
import type { Player } from "@/types";
|
||||||
|
|
||||||
export type RootState = {
|
export type RootState = {
|
||||||
playerDetails: Player;
|
playerDetails: Player;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import type { Player } from "@/api";
|
import type { Player } from "@/types";
|
||||||
|
|
||||||
export type RootState = {
|
export type RootState = {
|
||||||
playersArr: Player[];
|
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/Player";
|
||||||
export * from "@/types/PlayerMate";
|
export * from "@/types/PlayerMate";
|
||||||
export * from "@/types/PlayerMeta";
|
export * from "@/types/PlayerMeta";
|
||||||
|
export * from "@/types/LocalStoragePlayer";
|
||||||
|
@@ -1,39 +1,49 @@
|
|||||||
export type LSPlayer = {
|
import type { LocalStoragePlayer } from "@/types";
|
||||||
steamId64: string;
|
|
||||||
vanityUrl: string;
|
|
||||||
name: string;
|
|
||||||
avatar: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SaveLastVisitedToLocalStorage = (data: LSPlayer): void => {
|
export const SaveLastVisitedToLocalStorage = (
|
||||||
const a = JSON.parse(localStorage.getItem("recent-visited") || "");
|
data: LocalStoragePlayer
|
||||||
console.log("hello");
|
): void => {
|
||||||
console.log("a: ", a);
|
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);
|
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));
|
localStorage.setItem("recent-visited", JSON.stringify(a));
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { GoToError } from "@/utils/GoTo";
|
import { GoToError } from "@/utils/GoTo";
|
||||||
import type { Player, Stats } from "@/api";
|
import type { MatchStats, Player } from "@/types";
|
||||||
|
|
||||||
enum ErrorPage {
|
enum ErrorPage {
|
||||||
INTERNAL_SERVER_ERROR = 500,
|
INTERNAL_SERVER_ERROR = 500,
|
||||||
@@ -75,7 +75,7 @@ type PlayerArrayTextStyle = {
|
|||||||
color: string;
|
color: string;
|
||||||
};
|
};
|
||||||
export const getPlayerArr = (
|
export const getPlayerArr = (
|
||||||
stats: Stats[],
|
stats: MatchStats[],
|
||||||
team: number,
|
team: number,
|
||||||
color = false
|
color = false
|
||||||
): PlayerArrayType[] => {
|
): PlayerArrayType[] => {
|
||||||
@@ -133,11 +133,11 @@ export const sortObjectValue = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const CreatePlayersArray = (
|
export const CreatePlayersArray = (
|
||||||
stats: Stats[]
|
stats: MatchStats[]
|
||||||
): Array<Record<string, number | Player | undefined>> => {
|
): Array<Record<string, number | Player | undefined>> => {
|
||||||
const arr: Array<Record<string, number | Player | undefined>> = [];
|
const arr: Array<Record<string, number | Player | undefined>> = [];
|
||||||
for (let i = 0; i < stats.length; i++) {
|
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;
|
return arr;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user