import { Button, Card, Container, Grid, Input, Link, Modal, Spacer, 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 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, values: { socketAddr: undefined, useBeatLeader: false, 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")); this.setState({ steamId: json.steamId, values: json.values }); } 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] == "useBeatLeader" && value[1] === true) { values += `&beatLeader=${value[1]}`; 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); } render() { return this.state.loading ? (