Migrated leaderboard type to radios

This commit is contained in:
Liam 2022-10-19 16:37:20 +01:00
parent 5f10bea7e8
commit 4648f7c4f5

@ -6,6 +6,7 @@ import {
Input, Input,
Link, Link,
Modal, Modal,
Radio,
Spacer, Spacer,
Switch, Switch,
Text, Text,
@ -31,7 +32,7 @@ export default class Home extends Component {
values: { values: {
socketAddr: undefined, socketAddr: undefined,
useBeatLeader: false, leaderboard: "ScoreSaber",
showPlayerStats: true, showPlayerStats: true,
showScoreInfo: false, showScoreInfo: false,
showSongInfo: false, showSongInfo: false,
@ -58,7 +59,15 @@ export default class Home extends Component {
); );
} else { } else {
const json = JSON.parse(localStorage.getItem("values")); const json = JSON.parse(localStorage.getItem("values"));
this.setState({ steamId: json.steamId, values: json.values }); let values = {};
Object.entries(json.values).forEach((value) => {
if (value[0] === undefined) {
return;
}
values[value[0]] = value[1];
});
this.setState({ steamId: json.steamId, values: values });
} }
this.setState({ loading: false }); this.setState({ loading: false });
} }
@ -76,8 +85,8 @@ export default class Home extends Component {
if (value[1] === undefined) { if (value[1] === undefined) {
return; return;
} }
if (value[0] == "useBeatLeader" && value[1] === true) { if (value[0] == "leaderboard" && value[1] === "BeatLeader") {
values += `&beatLeader=${value[1]}`; values += `&beatLeader=true`;
return; return;
} }
values += `&${value[0]}=${value[1]}`; values += `&${value[0]}=${value[1]}`;
@ -112,7 +121,6 @@ export default class Home extends Component {
} }
render() { render() {
console.log(this.state.steamId);
return this.state.loading ? ( return this.state.loading ? (
<h1>Loading...</h1> <h1>Loading...</h1>
) : ( ) : (
@ -171,7 +179,7 @@ export default class Home extends Component {
<Grid xs={12} lg={9}> <Grid xs={12} lg={9}>
<Card> <Card>
<Card.Body> <Card.Body>
<Spacer y={1} /> <Spacer y={1.2} />
<Input <Input
underlined underlined
@ -195,27 +203,42 @@ export default class Home extends Component {
}} }}
/> />
<Spacer y={1} /> <Spacer y={1} />
<Text> <Text>Ranked leaderboard</Text>
Do you want to use BeatLeader rather than ScoreSaber? <Radio.Group
</Text> defaultValue={this.state.values.leaderboard || "ScoreSaber"}
<Switch onChange={(value) => {
onChange={(event) => this.updateValue("leaderboard", value);
this.updateValue("useBeatLeader", event.target.checked) }}
} >
checked={this.state.values.useBeatLeader} <Radio
size="md" value="ScoreSaber"
/> description="Uses the leaderboard from https://scoresaber.com/"
size="sm"
>
ScoreSaber
</Radio>
<Radio
value="BeatLeader"
description="Uses the leaderboard from https://www.beatleader.xyz/"
size="sm"
>
BeatLeader
</Radio>
</Radio.Group>
<Spacer y={1} />
<Text> <Text>
Do you want to show Player Stats (Current PP, global pos, Do you want to show Player Stats (Current PP, global pos,
etc) etc)
</Text> </Text>
<Switch <Switch
label="Ranked leaderboard"
onChange={(event) => onChange={(event) =>
this.updateValue("showPlayerStats", event.target.checked) this.updateValue("showPlayerStats", event.target.checked)
} }
checked={this.state.values.showPlayerStats} checked={this.state.values.showPlayerStats}
size="md" size="md"
/> />
<Spacer y={1.2} />
<Text> <Text>
Do you want to show Score Info (Current swing values, total Do you want to show Score Info (Current swing values, total
score, etc) score, etc)
@ -227,6 +250,7 @@ export default class Home extends Component {
checked={this.state.values.showScoreInfo} checked={this.state.values.showScoreInfo}
size="md" size="md"
/> />
<Spacer y={1.2} />
<Text> <Text>
Do you want to show Song Info (Song name, bsr, song art, Do you want to show Song Info (Song name, bsr, song art,
etc) etc)
@ -238,13 +262,13 @@ export default class Home extends Component {
checked={this.state.values.showSongInfo} checked={this.state.values.showSongInfo}
size="md" size="md"
/> />
<Spacer y={1} /> <Spacer y={1.2} />
<Button.Group> <Button.Group>
<Button <Button
flat flat
auto auto
onClick={() => { onPress={() => {
if (!this.state.steamId) { if (!this.state.steamId) {
toast.error("Please provide a Steam ID"); toast.error("Please provide a Steam ID");
return; return;
@ -257,7 +281,7 @@ export default class Home extends Component {
<Button <Button
flat flat
auto auto
onClick={() => { onPress={() => {
if (!this.state.steamId) { if (!this.state.steamId) {
toast.error("Please provide a Steam ID"); toast.error("Please provide a Steam ID");
return; return;