Skip to content

Commit

Permalink
push changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sk337 committed Jan 23, 2024
1 parent 7ce7b3c commit b1800e7
Show file tree
Hide file tree
Showing 9 changed files with 1,238 additions and 37 deletions.
1,111 changes: 1,102 additions & 9 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "src/App.jsx",
"homepage": "https://sk337.github.io/SwordManager",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down Expand Up @@ -34,7 +34,8 @@
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.3.3",
"vite": "^5.0.12"
"vite": "^5.0.12",
"vite-plugin-plain-text": "^1.4.2"
},
"devDependencies": {
"autoprefixer": "^10.4.17",
Expand Down
7 changes: 6 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
@tailwind base;
@tailwind components;
@tailwind utilities;


@font-face {
font-family: 'nf-symbol';
src: url('./SymbolsNerdFont-Regular.ttf') format('truetype');
}

@layer base {

:root {
Expand Down
127 changes: 114 additions & 13 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ import {
} from "@/components/ui/select";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";

import loading from "@/loading.svg";

export default function App() {
const ApiUrl = "https://sb-api-fb48ef34a197.herokuapp.com/";

const [isLogin, setIsLogin] = useState("load");
const [userData, setUserData] = useState(false);
const [pubInfo, setPubInfo] = useState(false);
const [skin, setSkin] = useState(false);
const [eskin, setEskin] = useState(false);
// Use effect to fetch the login status when the component mounts
useEffect(() => {
const fetchLoginStatus = async () => {
Expand All @@ -66,13 +66,12 @@ 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();
Expand Down Expand Up @@ -209,10 +208,65 @@ export default function App() {
});
}

// function setSkin(sskin){
// setSkin(sskin)
// }

function buySkin() {
let skin = document.getElementById("skin").value;
if (!skin) {
alert("Please select a skin");
return;
}
fetch(`${ApiUrl}profile/cosmetics/skins/buy/${skin}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "bearer " + window.localStorage.getItem("token"),
},
body: JSON.stringify({
token: window.localStorage.getItem("token"),
}),
}).then((req) => {
console.log(req);
req.json().then((obj) => {
console.log(obj);
if (Object.prototype.hasOwnProperty.call(obj, "error")) {
alert(`buy failed: ${obj.error}`);
return;
}
alert(`skin bought: ${id2skin(skin).name}`);
window.location.reload();
});
});
}

function equipSkin() {
if (!eskin) {
alert("Please select a skin");
return;
}
fetch(`${ApiUrl}profile/cosmetics/skins/equip/${eskin}`, {
method: "POST",
headers: {
Authorization: "bearer " + window.localStorage.getItem("token"),
"Content-Type": "appliction/json",
},
body: JSON.stringify({
token: window.localStorage.getItem("token"),
}),
}).then((req) => {
req.json().then((obj) => {
console.log(req)
console.log(obj)
if (Object.prototype.hasOwnProperty.call(obj, "error")) {
alert(`equip failed: ${obj.error}`);
return;
}
alert(`skin equipped: ${id2skin(eskin).name}`);
// window.location.reload();
});
});
}
// console.log(pubInfo)
if (userData && pubInfo) {
console.log(pubInfo);
Expand Down Expand Up @@ -279,10 +333,10 @@ export default function App() {
</p>
<div className="flex flex-row w-full mt-5">
<Sheet className="w-full">
<SheetTrigger className="w-full ">
<SheetTrigger className="w-full">
<Button className="w-full">Manage Account</Button>
</SheetTrigger>
<SheetContent>
<SheetContent className="overflow-x-auto">
<p className="text-3xl font-bold m-3">Settings</p>

<p className="font-bold mt-5">Change Username</p>
Expand Down Expand Up @@ -310,7 +364,10 @@ export default function App() {
<span className="text-sky-500">Gems: </span>
{prettyNum(userData.account.gems)}
</p>
<Select className="mt-10">
<Select
className="mt-10"
onValueChange={(value) => setSkin(value)}
>
<SelectTrigger className="w-[180px] mt-3">
<SelectValue placeholder="Select a Skin " />
</SelectTrigger>
Expand All @@ -321,7 +378,7 @@ export default function App() {
if (
!skin.og &&
!userData.account.skins.owned.includes(
skin.id
skin.id,
) &&
skin.price <= userData.account.gems
) {
Expand All @@ -338,7 +395,51 @@ export default function App() {
</SelectGroup>
</SelectContent>
</Select>
<Button className="mt-3">Buy</Button>
<Button className="mt-3" onClick={buySkin}>
Buy
</Button>
<p className="font-bold mt-5">Equip Skin</p>
<hr />
<Select
className="mt-10"
onValueChange={(value) => setEskin(value)}
>
<SelectTrigger className="w-[180px] mt-3">
<SelectValue placeholder="Select a Skin" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Skins</SelectLabel>
{cosmetics.skins.map((skin) => {
if (
userData.account.skins.owned.includes(skin.id)
) {
return (
<SelectItem key={skin.id} value={skin.id}>
{skin.name}{" "}
{skin.og ? (
<span className="text-red-500">(OG)</span>
) : (
""
)}{" "}
{skin.id ==
userData.account.skins.equipped ? (
<span className="text-green-500">
(Equipped)
</span>
) : (
""
)}
</SelectItem>
);
}
})}
</SelectGroup>
</SelectContent>
</Select>
<Button className="mt-3" onClick={equipSkin}>
Equip Skin
</Button>
</SheetContent>
</Sheet>
</div>
Expand Down Expand Up @@ -423,7 +524,7 @@ export default function App() {
return (
<main>
<h1 className="m-5 text-3xl font-bold text-center">Loading...</h1>
<svg src={loading} className="m-5 animate-spin" alt="loading" />
<p className="font-symbol text-center text-6xl animate-spin"></p>
</main>
);
}
Expand Down
Binary file added src/SymbolsNerdFont-Regular.ttf
Binary file not shown.
Binary file added src/SymbolsNerdFontMono-Regular.ttf
Binary file not shown.
5 changes: 0 additions & 5 deletions src/loading.svg

This file was deleted.

5 changes: 5 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/** @type {import('tailwindcss').Config} */

module.exports = {
darkMode: ["class"],
content: [
'./pages/**/*.{ts,tsx,js,jsx}',
'./components/**/*.{ts,tsx,js,jsx}',
'./app/**/*.{ts,tsx,js,jsx}',
'./src/**/*.{ts,tsx,js,jsx}',

],
prefix: "",
theme: {
Expand Down Expand Up @@ -71,6 +73,9 @@ module.exports = {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
fontFamily: {
'symbol': ['nf-symbol', 'sans-serif'],
},
},
},
plugins: [require("tailwindcss-animate")],
Expand Down
15 changes: 8 additions & 7 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { defineConfig } from 'vite';
import path from "path"
import path from "path";
import react from '@vitejs/plugin-react';
import dotenv from 'dotenv';
dotenv.config();


// https://vitejs.dev/config/
export default defineConfig({
plugins: [react({
babel: {
plugins: ["@babel/plugin-syntax-import-attributes"]
}
}
)],
plugins: [
react({
babel: {
plugins: ["@babel/plugin-syntax-import-attributes"]
}
}),
],
base: process.env.VITE_BASE_URL || "/",
server: {
hmr: false,
Expand Down

0 comments on commit b1800e7

Please sign in to comment.