2022-10-28 18:52:47 +00:00
|
|
|
import axios from "axios";
|
2022-10-28 19:55:43 +00:00
|
|
|
import { NextSeo } from "next-seo";
|
2022-10-28 18:52:47 +00:00
|
|
|
import { useEffect } from "react";
|
2022-10-29 12:17:24 +00:00
|
|
|
import CutStats from "../components/CutStats";
|
2022-10-28 18:52:47 +00:00
|
|
|
import PlayerStats from "../components/PlayerStats";
|
|
|
|
import ScoreStats from "../components/ScoreStats";
|
|
|
|
import SongInfo from "../components/SongInfo";
|
|
|
|
import { connectClient } from "../helpers/websocketClient";
|
|
|
|
import { useSettingsStore } from "../store/overlaySettingsStore";
|
|
|
|
import { usePlayerDataStore } from "../store/playerDataStore";
|
2022-10-17 11:58:07 +00:00
|
|
|
|
2022-10-14 19:00:47 +00:00
|
|
|
import styles from "../styles/overlay.module.css";
|
2022-10-10 08:34:38 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
export default function Overlay(props) {
|
|
|
|
const query = JSON.parse(props.query);
|
|
|
|
const [setOverlaySettings, mounted, setMounted] = useSettingsStore(
|
|
|
|
(state) => [state.setOverlaySettings, state.mounted, state.setMounted]
|
|
|
|
);
|
|
|
|
const updatePlayerData = usePlayerDataStore(
|
|
|
|
(state) => state.updatePlayerData
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!mounted && props.isValidSteamId) {
|
|
|
|
setMounted(true);
|
|
|
|
|
|
|
|
async function setup() {
|
|
|
|
await setOverlaySettings(query);
|
|
|
|
const showSongInfo = useSettingsStore.getState().showSongInfo;
|
|
|
|
const showScoreInfo = useSettingsStore.getState().showScoreInfo;
|
|
|
|
if (showSongInfo || (showScoreInfo && typeof window !== "undefined")) {
|
|
|
|
await connectClient();
|
|
|
|
}
|
|
|
|
const showPlayerStats = useSettingsStore.getState().showPlayerStats;
|
|
|
|
if (showPlayerStats) {
|
|
|
|
await updatePlayerData();
|
|
|
|
}
|
2022-10-10 08:34:38 +00:00
|
|
|
}
|
2022-10-28 18:52:47 +00:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
query,
|
|
|
|
props.isValidSteamId,
|
|
|
|
setOverlaySettings,
|
|
|
|
mounted,
|
|
|
|
setMounted,
|
|
|
|
updatePlayerData,
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!props.isValidSteamId) {
|
|
|
|
return (
|
|
|
|
<div className={styles.invalidPlayer}>
|
|
|
|
<h1>Invalid Steam ID</h1>
|
|
|
|
<h3>Please check the id field in the url</h3>
|
|
|
|
</div>
|
2022-10-14 19:00:47 +00:00
|
|
|
);
|
2022-10-10 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
return (
|
|
|
|
<div className={styles.main}>
|
2022-10-28 19:55:43 +00:00
|
|
|
<NextSeo title="Overlay"></NextSeo>
|
2022-10-28 18:52:47 +00:00
|
|
|
<PlayerStats />
|
2022-10-29 12:17:24 +00:00
|
|
|
<CutStats />
|
2022-10-28 18:52:47 +00:00
|
|
|
<ScoreStats />
|
|
|
|
<SongInfo />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-10-25 12:02:35 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
export async function getServerSideProps(context) {
|
|
|
|
const steamId = context.query.id;
|
|
|
|
const steamIdResponse = await axios.get(
|
|
|
|
`${process.env.REACT_APP_SITE_URL}/api/validateid?steamid=${steamId}`
|
|
|
|
);
|
2022-10-25 12:02:35 +00:00
|
|
|
|
2022-10-28 18:52:47 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
isValidSteamId: steamIdResponse.data.message === "Valid",
|
|
|
|
query: JSON.stringify(context.query),
|
2022-10-10 08:34:38 +00:00
|
|
|
},
|
2022-10-14 19:00:47 +00:00
|
|
|
};
|
|
|
|
}
|