userInfo component includes avatar; add default border image
This commit is contained in:
parent
8ed0fa5de2
commit
379dcdcd51
4 changed files with 42 additions and 21 deletions
3
components/borderSelect.js
Normal file
3
components/borderSelect.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default function BorderSelect() {
|
||||||
|
|
||||||
|
}
|
|
@ -1,19 +1,28 @@
|
||||||
import { useSession, signIn, signOut } from "next-auth/react";
|
import { useSession, signIn, signOut } from "next-auth/react";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import styles from "../styles/Components.module.css";
|
import styles from "../styles/Components.module.css";
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
borderInfo,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function UserInfo(borderInfo) {
|
export default function UserInfo(borderInfo) {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
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 (
|
return (
|
||||||
|
<div>{
|
||||||
|
isLoading ?
|
||||||
|
<p>Loading...</p>
|
||||||
|
:
|
||||||
|
<div>
|
||||||
<p className={styles.description}>
|
<p className={styles.description}>
|
||||||
{session ? `Signed in as ${session.user.name}` : "Not signed in"}
|
{session ? `Signed in as ${session.user.name} (${borderData.discordId})` : "Not signed in"}
|
||||||
<br />
|
<br />
|
||||||
{session ? (
|
{session ? (
|
||||||
<button onClick={() => signOut()}>Sign Out</button>
|
<button onClick={() => signOut()}>Sign Out</button>
|
||||||
|
@ -21,5 +30,16 @@ export default function UserInfo(borderInfo) {
|
||||||
<button onClick={() => signIn()}>Sign In</button>
|
<button onClick={() => signIn()}>Sign In</button>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
{
|
||||||
|
!!borderData ?
|
||||||
|
(<div>
|
||||||
|
<img src={session.user.image} />
|
||||||
|
<img src={`/api/border/${borderData.imageId ?? '0'}`} />
|
||||||
|
</div>)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,7 @@ export default function handler(req, res) {
|
||||||
getBorderById(id).then((result) => {
|
getBorderById(id).then((result) => {
|
||||||
const imageName = result?.imageName ?? "default.png";
|
const imageName = result?.imageName ?? "default.png";
|
||||||
|
|
||||||
console.log(result, imageName);
|
// return res.status(200).json(result);
|
||||||
|
return res.redirect(301, `/images/${imageName}`)
|
||||||
return res.status(200).json(result);
|
|
||||||
// return res.redirect(301, `/images/${imageName}`)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
BIN
public/images/default.png
Normal file
BIN
public/images/default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in a new issue