Compare commits
No commits in common. "19a94f927e9c5406d3b0111357c5dd940be2d762" and "379dcdcd512d4fe45292da0d2ff3ca90d4c316a8" have entirely different histories.
19a94f927e
...
379dcdcd51
2
.gitignore
vendored
|
@ -35,5 +35,3 @@ yarn-error.log*
|
|||
# prisma data
|
||||
/prisma/migrations
|
||||
/prisma/borders.db
|
||||
|
||||
/public/images
|
|
@ -1,43 +0,0 @@
|
|||
import Image from "next/image";
|
||||
import styles from "../styles/Components.module.css";
|
||||
|
||||
export default function Select(props) {
|
||||
const { data, onSelect, selected = {} } = props;
|
||||
console.log("data", data, "selected", selected);
|
||||
return (
|
||||
<div className={styles.select}>
|
||||
{data &&
|
||||
data.map((border, index) => {
|
||||
return (
|
||||
<div
|
||||
className={[
|
||||
styles.borderKeeper,
|
||||
selected == border.id ? styles.selected : undefined,
|
||||
].join(" ")}
|
||||
key={border.id}>
|
||||
<Image
|
||||
className={styles.userImage}
|
||||
src="/user.png"
|
||||
alt="user image"
|
||||
width={128}
|
||||
height={128}
|
||||
onClick={(ev) => {
|
||||
onSelect(border.id);
|
||||
}}
|
||||
/>
|
||||
<Image
|
||||
className={styles.borderImage}
|
||||
src={`/images/${border.imageName}`}
|
||||
alt={`border with id ${border.id}`}
|
||||
width={132}
|
||||
height={132}
|
||||
onClick={(ev) => {
|
||||
onSelect(border.id);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -2,23 +2,44 @@ import { useSession, signIn, signOut } from "next-auth/react";
|
|||
import { useEffect, useState } from "react";
|
||||
import styles from "../styles/Components.module.css";
|
||||
|
||||
export default function UserInfo(props) {
|
||||
export default function UserInfo(borderInfo) {
|
||||
const { data: session } = useSession();
|
||||
const { borderData } = props;
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
const [borderData, setBorderData] = useState(undefined);
|
||||
|
||||
useEffect(async () => {
|
||||
setLoading(true);
|
||||
const res = await fetch('api/user/border/@me');
|
||||
const data = await res.json();
|
||||
setBorderData(data);
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p className={styles.description}>
|
||||
{session
|
||||
? `Signed in as ${session.user.name} (${borderData?.discordId})`
|
||||
: "Not signed in"}
|
||||
<br />
|
||||
{session ? (
|
||||
<button onClick={() => signOut()}>Sign Out</button>
|
||||
) : (
|
||||
<button onClick={() => signIn()}>Sign In</button>
|
||||
)}
|
||||
</p>
|
||||
<div>{
|
||||
isLoading ?
|
||||
<p>Loading...</p>
|
||||
:
|
||||
<div>
|
||||
<p className={styles.description}>
|
||||
{session ? `Signed in as ${session.user.name} (${borderData.discordId})` : "Not signed in"}
|
||||
<br />
|
||||
{session ? (
|
||||
<button onClick={() => signOut()}>Sign Out</button>
|
||||
) : (
|
||||
<button onClick={() => signIn()}>Sign In</button>
|
||||
)}
|
||||
</p>
|
||||
{
|
||||
!!borderData ?
|
||||
(<div>
|
||||
<img src={session.user.image} />
|
||||
<img src={`/api/border/${borderData.imageId ?? '0'}`} />
|
||||
</div>)
|
||||
: undefined
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,14 +4,10 @@ import prisma from "./prisma";
|
|||
export const getBorderById = async (id) => {
|
||||
return await prisma.borderImage.findFirst({
|
||||
where: {
|
||||
id: parseInt(id),
|
||||
},
|
||||
id: parseInt(id)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const getAllBorders = async () => {
|
||||
return await prisma.borderImage.findMany();
|
||||
};
|
||||
}
|
||||
|
||||
export const getUserBorders = async (req) => {
|
||||
const session = await getSession({ req });
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import { getBorderById } from "../../../lib/borders";
|
||||
|
||||
export default function handler(req, res) {
|
||||
const id = req.query.id;
|
||||
getBorderById(id).then((result) => {
|
||||
return res.status(200).json(result);
|
||||
});
|
||||
}
|
||||
const id = req.query.id;
|
||||
|
||||
console.log(id);
|
||||
|
||||
getBorderById(id).then((result) => {
|
||||
const imageName = result?.imageName ?? "default.png";
|
||||
|
||||
// return res.status(200).json(result);
|
||||
return res.redirect(301, `/images/${imageName}`)
|
||||
});
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
import { getAllBorders } from "../../../lib/borders";
|
||||
|
||||
export default function handler(req, res) {
|
||||
getAllBorders().then((result) => {
|
||||
return res.status(200).json(result);
|
||||
});
|
||||
}
|
|
@ -2,29 +2,8 @@ import Head from "next/head";
|
|||
import Image from "next/image";
|
||||
import styles from "../styles/Home.module.css";
|
||||
import UserInfo from "../components/userInfo";
|
||||
import Select from "../components/select";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function Home() {
|
||||
const [data, setData] = useState(null);
|
||||
const [borderData, setBorderData] = useState(null);
|
||||
const [selected, setSelected] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("api/border/all")
|
||||
.then((res) => res.json())
|
||||
.then((data) => setData(data));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("api/user/border/@me")
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setBorderData(data);
|
||||
setSelected(data?.borderId || 0);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
|
@ -32,14 +11,10 @@ export default function Home() {
|
|||
<meta name="description" content="Generated by create next app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<header>
|
||||
|
||||
<main className={styles.main}>
|
||||
<h1 className={styles.title}>Steam Borders</h1>
|
||||
<div className={styles.userinfo}>
|
||||
<UserInfo borderData={borderData} />
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<Select data={data} onSelect={setSelected} selected={selected} />
|
||||
<UserInfo />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
|
BIN
public/images/00b9a62e09a1e452d6840170849e8ac06f6d3ef5.png
Normal file
After Width: | Height: | Size: 526 KiB |
BIN
public/images/083c19cc935001ee0508aff3b948da62b6a093f6.png
Normal file
After Width: | Height: | Size: 897 KiB |
BIN
public/images/18717998311ff5e68b1246dbdb43cbc0fa00a35d.png
Normal file
After Width: | Height: | Size: 573 KiB |
BIN
public/images/27ef3d62a0e42bf4ac60d426f2f172e1790ec0fd.png
Normal file
After Width: | Height: | Size: 236 KiB |
BIN
public/images/2d876cff5940a8724340a5798c1c8e48880c675f.png
Normal file
After Width: | Height: | Size: 622 KiB |
BIN
public/images/359032c610e13a8f370594b200b9ddf8b29aa8af.png
Normal file
After Width: | Height: | Size: 588 KiB |
BIN
public/images/3fd73db5d33e9b6597e6975eb654e89b89b5db5c.png
Normal file
After Width: | Height: | Size: 1.9 MiB |
BIN
public/images/420efee31f0b0a3fe39cb7409dbe9c3a3e0a0e3a.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
public/images/46461aaea39b18a4a3da2e6d3cf253006f2d6193.png
Normal file
After Width: | Height: | Size: 653 KiB |
BIN
public/images/4718aad9a4b04c3cfb049bb7cbf2bd35c2e2eb11.png
Normal file
After Width: | Height: | Size: 569 KiB |
BIN
public/images/537ab433b4dbf1c225e5809ad53d690ee73438d8.png
Normal file
After Width: | Height: | Size: 346 KiB |
BIN
public/images/558efce86af3043bda6ac5078e1801dc7b587de7.png
Normal file
After Width: | Height: | Size: 1.9 MiB |
BIN
public/images/68439f85ae83ce6429b845234e28de62a88b1f88.png
Normal file
After Width: | Height: | Size: 686 KiB |
BIN
public/images/950172e5379f52079835a2b295e93de1d8a8fbf3.png
Normal file
After Width: | Height: | Size: 140 KiB |
BIN
public/images/984f18d4bcc76669bcbd8971f962d1b75716dd11.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
public/images/babb8c618b2c8eafaad9bc3fac3304a1837ac4fb.png
Normal file
After Width: | Height: | Size: 1 MiB |
BIN
public/images/bd04ee3a8e6c35c39f8670c034a5ea7fd15ca3f1.png
Normal file
After Width: | Height: | Size: 938 KiB |
BIN
public/images/beaee5e90d93bfafa5f5f55acb23abfd28ad180c.png
Normal file
After Width: | Height: | Size: 470 KiB |
BIN
public/images/c30260bb120bf1379f075802653c8eb86da7a7e9.png
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
public/images/e0de1bf39208a3c1230bca5bc69561e9d2f0971f.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
public/images/e89b3a70625c980c3d68869f5cdb1da9baa447f8.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
public/user.png
Before Width: | Height: | Size: 566 B |
|
@ -1,40 +0,0 @@
|
|||
.select {
|
||||
min-height: 90vh;
|
||||
max-height: 90vh;
|
||||
max-width: 50vw;
|
||||
left: 45vw;
|
||||
position: relative;
|
||||
overflow-y: scroll;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.borderKeeper {
|
||||
width: 132px !important;
|
||||
height: 132px !important;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.borderKeeper > span {
|
||||
display: inline-table !important;
|
||||
}
|
||||
|
||||
.userImage,
|
||||
.borderImage {
|
||||
position: relative;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.userImage {
|
||||
z-index: -1;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.borderImage {
|
||||
z-index: 3;
|
||||
top: -256px !important;
|
||||
}
|
||||
|
||||
.selected {
|
||||
border: 1px solid black;
|
||||
}
|
|
@ -12,19 +12,6 @@
|
|||
align-items: center;
|
||||
}
|
||||
|
||||
.userinfo {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: end;
|
||||
align-items: flex-end;
|
||||
text-align: right;
|
||||
width: 50vw;
|
||||
top: 0;
|
||||
left: 50vw;
|
||||
padding-right: 32px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
|
@ -56,12 +43,11 @@
|
|||
margin: 0;
|
||||
line-height: 1.15;
|
||||
font-size: 4rem;
|
||||
width: 50vw;
|
||||
}
|
||||
|
||||
.title,
|
||||
.description {
|
||||
text-align: left;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.description {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
console.log("a");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Prisma = require("@prisma/client");
|
||||
|
||||
const prisma = new Prisma.PrismaClient();
|
||||
|
@ -9,41 +9,32 @@ console.log("processing new border images");
|
|||
|
||||
const cwd = process.cwd();
|
||||
|
||||
const folder = path.join(
|
||||
cwd,
|
||||
cwd.includes("util") ? ".." : "",
|
||||
"public/images"
|
||||
);
|
||||
const folder = path.join(cwd, cwd.includes("util") ? ".." : "", "public/images");
|
||||
const list = fs.readdirSync(folder);
|
||||
|
||||
(async () => {
|
||||
let numAdded = 0;
|
||||
for (let item of list) {
|
||||
// console.log(item);
|
||||
let numAdded = 0;
|
||||
for (let item of list) {
|
||||
// console.log(item);
|
||||
|
||||
const result = await prisma.borderImage.findFirst({
|
||||
where: {
|
||||
imageName: item,
|
||||
},
|
||||
});
|
||||
if (!result && item == "default.png") {
|
||||
const added = await prisma.borderImage.create({
|
||||
data: {
|
||||
id: 0,
|
||||
imageName: item,
|
||||
},
|
||||
});
|
||||
numAdded++;
|
||||
console.log(added);
|
||||
} else if (!result) {
|
||||
const added = await prisma.borderImage.create({
|
||||
data: {
|
||||
imageName: item,
|
||||
},
|
||||
});
|
||||
numAdded++;
|
||||
console.log(added);
|
||||
const result = await prisma.borderImage.findFirst(
|
||||
{
|
||||
where: {
|
||||
imageName: item
|
||||
}
|
||||
}
|
||||
);
|
||||
if (!result) {
|
||||
const added = await prisma.borderImage.create(
|
||||
{
|
||||
data: {
|
||||
imageName: item
|
||||
},
|
||||
}
|
||||
);
|
||||
numAdded++;
|
||||
console.log(added);
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(`Processed ${numAdded} new images.`);
|
||||
})();
|
||||
console.log(`Processed ${numAdded} new images.`);
|
||||
})();
|