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,25 +1,45 @@
|
||||||
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 (
|
||||||
<p className={styles.description}>
|
<div>{
|
||||||
{session ? `Signed in as ${session.user.name}` : "Not signed in"}
|
isLoading ?
|
||||||
<br />
|
<p>Loading...</p>
|
||||||
{session ? (
|
:
|
||||||
<button onClick={() => signOut()}>Sign Out</button>
|
<div>
|
||||||
) : (
|
<p className={styles.description}>
|
||||||
<button onClick={() => signIn()}>Sign In</button>
|
{session ? `Signed in as ${session.user.name} (${borderData.discordId})` : "Not signed in"}
|
||||||
)}
|
<br />
|
||||||
</p>
|
{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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,8 @@ 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.status(200).json(result);
|
||||||
// return res.redirect(301, `/images/${imageName}`)
|
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