nise/nise-replay-viewer/src/interface/App.tsx

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-03-03 15:22:03 +00:00
import {AboutDialog} from "./composites/about-dialog";
import {Navbar} from "./composites/Menu";
import {SongSlider} from "./composites/song-slider";
import {Helper} from "./composites/helper";
import {useEffect} from "react";
2024-03-03 15:22:03 +00:00
import {OsuRenderer} from "@/osu/OsuRenderer";
2024-03-03 22:27:54 +00:00
import {Stats} from "@/interface/composites/stats";
import {LoadingDialog} from "@/interface/composites/loading-dialog";
2024-03-03 15:22:03 +00:00
export function App() {
const loadReplay = async (replayId: number) => {
await OsuRenderer.loadReplayFromUrl(replayId);
};
const loadReplayPair = async (replayId1: number, replayId2: number) => {
await OsuRenderer.loadReplayPairFromUrl(replayId1, replayId2);
}
2024-03-03 15:22:03 +00:00
useEffect(() => {
2025-05-14 18:03:27 +00:00
// We might be beind a reverse proxy - remove the proxied URL
const path = location.pathname.replace("/replay-viewer", "");
// This pattern matches one or more digits followed by an optional slash and any characters (non-greedy)
const pathRegex = /^\/(\d+)(?:\/(\d+))?/;
2025-05-14 18:03:27 +00:00
const match = path.match(pathRegex);
2024-03-03 15:22:03 +00:00
if (match) {
// match[1] will contain the first ID, match[2] (if present) will contain the second ID
const pathReplayId1 = Number.parseInt(match[1]);
const pathReplayId2 = match[2] ? Number.parseInt(match[2]) : null;
2024-03-03 15:22:03 +00:00
if(pathReplayId2 != null) {
loadReplayPair(pathReplayId1, pathReplayId2);
} else {
loadReplay(pathReplayId1);
}
2024-03-03 15:22:03 +00:00
}
}, [location.pathname]);
return (
<>
<Navbar/>
<AboutDialog/>
<LoadingDialog/>
2024-03-03 15:22:03 +00:00
<SongSlider/>
2024-03-03 22:27:54 +00:00
<Stats/>
2024-03-03 15:22:03 +00:00
<Helper/>
</>
);
}