forked from simrail/map-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectedTrainPopup.tsx
More file actions
51 lines (44 loc) · 1.43 KB
/
Copy pathSelectedTrainPopup.tsx
File metadata and controls
51 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { getSteamProfileOrBot } from "@/components/steam";
import { readLocalStorageValue } from "@mantine/hooks";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { useSelectedTrain } from "../contexts/SelectedTrainContext";
import styles from "../styles/SelectedTrainPopup.module.css";
import TrainText from "./TrainText";
const SelectedTrainPopup = () => {
const { selectedTrain } = useSelectedTrain();
const renderPopup = readLocalStorageValue({
key: "renderPopup",
defaultValue: true,
});
const [avatar, setAvatar] = useState<string | null>(null);
const [username, setUsername] = useState<string | null>(null);
const router = useRouter();
const { trainId } = router.query;
type Profile = [string | null, string | null];
const setData = ([avatarUrl, username]: Profile) => {
setAvatar(avatarUrl);
setUsername(username);
};
// biome-ignore lint/correctness/useExhaustiveDependencies:
useEffect(() => {
if (selectedTrain)
getSteamProfileOrBot(selectedTrain.TrainData.ControlledBySteamID).then( // support xbox players
// @ts-ignore
setData,
);
}, [selectedTrain]);
if (renderPopup === true) {
return selectedTrain ? (
<div className={styles.popup} style={trainId ? { top: "0px" } : {}}>
<TrainText
train={selectedTrain}
username={username ?? ""}
avatar={avatar}
/>
</div>
) : null;
}
return null;
};
export default SelectedTrainPopup;