import { Button, Card, Container, Grid, Input, Link, Modal, Radio, Spacer, Spinner, Switch, Text, } from "@nextui-org/react"; import { Component } from "react"; import NavBar from "../src/components/Navbar"; import { toast, ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; import Utils from "../src/utils/utils"; import styles from "../styles/main.module.css"; export default class Home extends Component { constructor(props) { super(props); this.state = { loading: true, steamId: undefined, isPreviewVisible: false, previewUrl: undefined, overlayUrl: undefined, avatarUrl: undefined, values: { socketAddr: undefined, leaderboard: "ScoreSaber", showPlayerStats: true, showScoreInfo: false, showSongInfo: false, }, }; } async componentDidMount() { const urlSearchParams = new URLSearchParams(window.location.search); const params = Object.fromEntries(urlSearchParams.entries()); if (params.id) { document.location.href = "/overlay/" + window.location.search; return; } if (localStorage.getItem("values") == undefined) { localStorage.setItem( "values", JSON.stringify({ steamId: this.state.steamId, values: this.state.values, }) ); } else { const json = JSON.parse(localStorage.getItem("values")); let values = {}; Object.entries(json.values).forEach((value) => { if (value[0] !== undefined) { values[value[0]] = value[1]; } }); this.setState({ steamId: json.steamId, values: values }); this.validateSteamId(json.steamId || ""); } this.setState({ loading: false }); } loadPreview() { this.setState({ isPreviewVisible: true, previewUrl: this.generateUrl(true), }); } generateUrl(withTc = false) { let values = ""; Object.entries(this.state.values).forEach((value) => { if (value[1] === undefined) { return; } if (value[0] == "leaderboard" && value[1] === "BeatLeader") { values += `&beatLeader=true`; return; } values += `&${value[0]}=${value[1]}`; }); return ( window.location.origin + "/overlay?id=" + this.state.steamId + values + (withTc ? "&textColor=black" : "") ); } updateValue(key, value) { let values = this.state.values; values[key] = value; this.setState({ values: values }); this.updateStorage(); } updateStorage() { setTimeout(() => { localStorage.setItem( "values", JSON.stringify({ steamId: this.state.steamId, values: this.state.values, }) ); }, 5); } async validateSteamId(steamId) { if (steamId.length !== 17) { // Steam ID is invalid return this.setState({ avatarUrl: undefined }); } const data = await fetch("/api/validateid?steamid=" + steamId); const json = await data.json(); if (json.message === "Valid") { this.setState({ avatarUrl: `/api/steamavatar?steamid=${steamId}`, }); } else { this.setState({ avatarUrl: undefined }); } } render() { return this.state.loading ? (
) : (
{/* Preview */} {this.state.isPreviewVisible ? ( this.setState({ isPreviewVisible: false })} > Overlay Preview ) : ( <> )}
BeatSaber Overlay Welcome to the Setup panel
this.updateValue("socketAddr", event.target.value) } checked={true} /> { const id = event.target.value; await this.validateSteamId(id); this.setState({ steamId: id }); this.updateStorage(); }} /> Ranked leaderboard { this.updateValue("leaderboard", value); }} > ScoreSaber BeatLeader Do you want to show Player Stats (Current PP, global pos, etc) this.updateValue("showPlayerStats", event.target.checked) } checked={this.state.values.showPlayerStats} size="md" /> Do you want to show Score Info (Current swing values, total score, etc) this.updateValue("showScoreInfo", event.target.checked) } checked={this.state.values.showScoreInfo} size="md" /> Do you want to show Song Info (Song name, bsr, song art, etc) this.updateValue("showSongInfo", event.target.checked) } checked={this.state.values.showSongInfo} size="md" /> { Utils.openInNewTab( "https://github.com/RealFascinated/beatsaber-overlay" ); }} > If you like this project and want to support it. Come check out the project on GitHub!
); } }