From 29d56db5194f22d7fed6e650a97ecb11caf1d42a Mon Sep 17 00:00:00 2001 From: sk337 Date: Tue, 23 Jan 2024 19:36:57 -0800 Subject: [PATCH] add a ton of code --- .editorconfig | 7 +++ .gitmodules | 3 ++ package.json | 2 + src/App.jsx | 61 ++++++---------------- src/Leaderboard.jsx | 86 ++++++++++++++++++++++++++++---- src/components/ui/avatar.tsx | 48 ++++++++++++++++++ src/components/ui/hover-card.tsx | 27 ++++++++++ src/components/ui/skeleton.tsx | 15 ++++++ src/components/usercard.jsx | 53 ++++++++++++++++++++ src/index.jsx | 10 ++-- src/utils/jsutils.js | 37 ++++++++++++++ src/utils/leaderboard.js | 46 +++++++++++------ vendor/swordbattle.io | 1 + 13 files changed, 319 insertions(+), 77 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitmodules create mode 100644 src/components/ui/avatar.tsx create mode 100644 src/components/ui/hover-card.tsx create mode 100644 src/components/ui/skeleton.tsx create mode 100644 src/components/usercard.jsx create mode 100644 src/utils/jsutils.js create mode 160000 vendor/swordbattle.io diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1105878 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ + +root=true + +[*.{js,jsx,ts,tsx}] + +indent_size = 2 +indent_style = space \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..569f73c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/swordbattle.io"] + path = vendor/swordbattle.io + url = https://github.com/codergautam/swordbattle.io diff --git a/package.json b/package.json index bf9942a..d846c5d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "license": "ISC", "dependencies": { "@babel/plugin-syntax-import-attributes": "^7.23.3", + "@radix-ui/react-avatar": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", + "@radix-ui/react-hover-card": "^1.0.7", "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-navigation-menu": "^1.1.4", "@radix-ui/react-select": "^2.0.0", diff --git a/src/App.jsx b/src/App.jsx index 3b891bb..0a74485 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import { checkLogin, tokenlogin, getPubInfo, login } from "@/utils/login"; -import cosmetics from "../cosmetics.json"; +import cosmetics from "@/../cosmetics.json"; import { Card, CardContent, @@ -33,11 +33,12 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; -import Login from './Login'; +import { id2skin, playtimeParse, prettyNum } from "@/utils/jsutils"; -import Nav from "@/components/nav" +import Login from "./Login"; + +import Nav from "@/components/nav"; export default function App() { const ApiUrl = "https://sb-api-fb48ef34a197.herokuapp.com/"; @@ -69,12 +70,13 @@ export default function App() { function flogin() { login( document.getElementById("username").value, - document.getElementById("password").value, + document.getElementById("password").value ).then((res) => { if (res.error) { document.getElementById("error").classList.remove("hidden"); - document.getElementById("desc").innerHTML = - `${res.error}: ${res.message}`; + document.getElementById( + "desc" + ).innerHTML = `${res.error}: ${res.message}`; } else { window.localStorage.setItem("token", res.token); window.location.reload(); @@ -83,44 +85,10 @@ export default function App() { } if (isLogin == false) { - return (); - } - - function playtimeParse(seconds) { - let days = Math.floor(seconds / 86400); - let remainder = seconds % 86400; - let hours = Math.floor(remainder / 3600); - remainder %= 3600; - let minutes = Math.floor(remainder / 60); - let secs = remainder % 60; - - let result = ""; - - if (days > 0) { - result += `${days}d `; - } - if (hours > 0 || days > 0) { - result += `${hours}h `; - } - if (minutes > 0 || hours > 0 || days > 0) { - result += `${minutes}m `; - } - result += `${secs}s`; - - return result.trim(); + return ; } - function prettyNum(num) { - return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); - } // console.log(cosmetics) - function id2skin(id) { - for (let i = 0; i < cosmetics.skins.length; i++) { - if (cosmetics.skins[i].id == id) { - return cosmetics.skins[i]; - } - } - } // console.log(userData) function email(userData) { @@ -225,8 +193,8 @@ export default function App() { }), }).then((req) => { req.json().then((obj) => { - console.log(req) - console.log(obj) + console.log(req); + console.log(obj); if (Object.prototype.hasOwnProperty.call(obj, "error")) { alert(`equip failed: ${obj.error}`); return; @@ -238,10 +206,9 @@ export default function App() { } // console.log(pubInfo) if (userData && pubInfo) { - console.log(pubInfo); return (
-