mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: start of homepage tracking
This commit is contained in:
1 parent
477c35db34
commit
8e2302a6d4
1 file changed
+84
-27
@@ -15,6 +15,7 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
Link,
|
Link,
|
||||||
Select,
|
Select,
|
||||||
|
Spinner,
|
||||||
Table,
|
Table,
|
||||||
Text,
|
Text,
|
||||||
TextField,
|
TextField,
|
||||||
@@ -52,7 +53,12 @@ import mutateSession, {
|
|||||||
} from '../../../stores/session';
|
} from '../../../stores/session';
|
||||||
import { IndividualTankStats } from '../../../types/tanksStats';
|
import { IndividualTankStats } from '../../../types/tanksStats';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page({
|
||||||
|
searchParams,
|
||||||
|
}: {
|
||||||
|
searchParams: { id?: string };
|
||||||
|
}) {
|
||||||
|
const [loaded, setLoaded] = useState(false);
|
||||||
const wideFormat = useWideFormat(640);
|
const wideFormat = useWideFormat(640);
|
||||||
const awaitedTankDefinitions = use(tankDefinitions);
|
const awaitedTankDefinitions = use(tankDefinitions);
|
||||||
const awaitedTankAvearges = use(tankAverages);
|
const awaitedTankAvearges = use(tankAverages);
|
||||||
@@ -105,6 +111,7 @@ export default function Page() {
|
|||||||
: undefined,
|
: undefined,
|
||||||
[delta],
|
[delta],
|
||||||
);
|
);
|
||||||
|
const [showLinkOverridePrompt, setShowLinkOverridePrompt] = useState(true);
|
||||||
|
|
||||||
const search = debounce(async () => {
|
const search = debounce(async () => {
|
||||||
if (!input.current) return;
|
if (!input.current) return;
|
||||||
@@ -113,6 +120,32 @@ export default function Page() {
|
|||||||
setSearching(false);
|
setSearching(false);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
async function track(id: number) {
|
||||||
|
const region = idToRegion(id);
|
||||||
|
const player = await getAccountInfo(region, id);
|
||||||
|
const stats = await getTankStats(region, id);
|
||||||
|
|
||||||
|
if (stats === null) {
|
||||||
|
setShowCCInaccessibilityPrompt(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setShowSearch(false);
|
||||||
|
mutateSession((draft) => {
|
||||||
|
if (!input.current) return;
|
||||||
|
|
||||||
|
draft.tracking = true;
|
||||||
|
(draft as SessionTracking).player = {
|
||||||
|
id,
|
||||||
|
region,
|
||||||
|
since: Date.now(),
|
||||||
|
stats,
|
||||||
|
};
|
||||||
|
|
||||||
|
input.current.value = player.nickname;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function update() {
|
async function update() {
|
||||||
if (!session.tracking) return;
|
if (!session.tracking) return;
|
||||||
@@ -130,6 +163,22 @@ export default function Page() {
|
|||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [session.tracking && session.player.id]);
|
}, [session.tracking && session.player.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoaded(true);
|
||||||
|
|
||||||
|
if (searchParams.id && !session.tracking) {
|
||||||
|
track(Number(searchParams.id));
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!loaded) {
|
||||||
|
return (
|
||||||
|
<PageWrapper align="center" justify="center">
|
||||||
|
<Spinner />
|
||||||
|
</PageWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper>
|
<PageWrapper>
|
||||||
<AlertDialog.Root
|
<AlertDialog.Root
|
||||||
@@ -154,6 +203,39 @@ export default function Page() {
|
|||||||
</AlertDialog.Content>
|
</AlertDialog.Content>
|
||||||
</AlertDialog.Root>
|
</AlertDialog.Root>
|
||||||
|
|
||||||
|
{searchParams.id &&
|
||||||
|
session.tracking &&
|
||||||
|
Number(searchParams.id) !== session.player.id && (
|
||||||
|
<AlertDialog.Root
|
||||||
|
open={showLinkOverridePrompt}
|
||||||
|
onOpenChange={setShowLinkOverridePrompt}
|
||||||
|
>
|
||||||
|
<AlertDialog.Content>
|
||||||
|
<AlertDialog.Title>
|
||||||
|
You are currently tracking {accountInfo?.nickname}
|
||||||
|
</AlertDialog.Title>
|
||||||
|
<AlertDialog.Description>
|
||||||
|
Would you like to stop tracking {accountInfo?.nickname} and
|
||||||
|
start tracking a new player?
|
||||||
|
</AlertDialog.Description>
|
||||||
|
|
||||||
|
<Flex mt="4" justify="end">
|
||||||
|
<AlertDialog.Action>
|
||||||
|
<Button
|
||||||
|
variant="solid"
|
||||||
|
onClick={() => {
|
||||||
|
setShowLinkOverridePrompt(false);
|
||||||
|
track(Number(searchParams.id));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Proceed
|
||||||
|
</Button>
|
||||||
|
</AlertDialog.Action>
|
||||||
|
</Flex>
|
||||||
|
</AlertDialog.Content>
|
||||||
|
</AlertDialog.Root>
|
||||||
|
)}
|
||||||
|
|
||||||
{!session.tracking && (
|
{!session.tracking && (
|
||||||
<Flex
|
<Flex
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
@@ -222,32 +304,7 @@ export default function Page() {
|
|||||||
<Button
|
<Button
|
||||||
key={player.account_id}
|
key={player.account_id}
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={async () => {
|
onClick={() => track(player.account_id)}
|
||||||
const stats = await getTankStats(
|
|
||||||
player.region,
|
|
||||||
player.account_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (stats === null) {
|
|
||||||
setShowCCInaccessibilityPrompt(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setShowSearch(false);
|
|
||||||
mutateSession((draft) => {
|
|
||||||
if (!input.current) return;
|
|
||||||
|
|
||||||
draft.tracking = true;
|
|
||||||
(draft as SessionTracking).player = {
|
|
||||||
id: player.account_id,
|
|
||||||
region: player.region,
|
|
||||||
since: Date.now(),
|
|
||||||
stats,
|
|
||||||
};
|
|
||||||
|
|
||||||
input.current.value = player.nickname;
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{player.nickname} (
|
{player.nickname} (
|
||||||
{UNLOCALIZED_REGION_NAMES_SHORT[player.region]})
|
{UNLOCALIZED_REGION_NAMES_SHORT[player.region]})
|
||||||
|
|||||||
Reference in new issue
Block a user