diff --git a/pages/index.js b/pages/index.js index dc4b640..a14f0a9 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,69 +1,89 @@ import Head from 'next/head' -import Image from 'next/image' -import styles from '../styles/Home.module.css' +import { Component } from 'react' +import Avatar from '../components/Avatar'; +import PlayerStats from '../components/PlayerStats'; -export default function Home() { - return ( -
- - Create Next App - - - +// Why do u have to proxy requests... it's so dumb LOL +const API_URL = "https://bangor375.herokuapp.com/https://scoresaber.com/api/player/%s/full"; -
-

- Welcome to Next.js! -

+export default class Home extends Component { -

- Get started by editing{' '} - pages/index.js -

+ constructor(props) { + super(props); -
- -

Documentation →

-

Find in-depth information about Next.js features and API.

-
+ this.state = { + loading: true, + id: undefined, + isValidScoresaber: true, + data: undefined + } + } - -

Learn →

-

Learn about Next.js in an interactive course with quizzes!

-
+ async componentDidMount() { + const urlSearchParams = new URLSearchParams(window.location.search); + const params = Object.fromEntries(urlSearchParams.entries()); - -

Examples →

-

Discover and deploy boilerplate example Next.js projects.

-
+ const id = params.id; + if (!id) { // Check if the id pararm is valid + this.setState({ loading: false, isValidScoresaber: false }); + return; + } - -

Deploy →

-

- Instantly deploy your Next.js site to a public URL with Vercel. -

-
-
-
+ await this.updateData(id); + setTimeout(async () => { + if (!this.state.isValidScoresaber) { + return; + } + await this.updateData(id); + }, 30_000); // Update the scoresaber data every 30 seconds. + } - -
- ) -} + async updateData(id) { + const data = await fetch(API_URL.replace("%s", id), { + mode: 'cors' + }); + if (data.status == 422) { // invalid scoresaber + this.setState({ loading: false, isValidScoresaber: false }); + return; + } + const json = await data.json(); + if (json.errorMessage) { + this.setState({ loading: false, isValidScoresaber: false }); + return; + } + this.setState({ loading: false, id: id, data: json }); + console.log(json); + } + + render() { + const { loading, isValidScoresaber, data } = this.state; + + return <> + { loading ? + <> +

Loading...

+ + : !isValidScoresaber ? +
+

Provide a valid scoresaber id

+

Example: {document.location.origin}?id=76561198449412074

+
+

This is currently just a simple overlay displaying ScoreSaber stats.

+

If you have any suggestions you can message me on discord @ Fascinated#4719

+
+
: +
+
+ + +
+
+ } + + } +} \ No newline at end of file