mirror of
https://git.moonleay.net/Websites/liljudd-website.git
synced 2025-07-25 11:02:04 +02:00
Fix: Cleanup and SSR auth header fix
This commit is contained in:
parent
b28ceb8659
commit
2b9b5198fa
5 changed files with 92 additions and 128 deletions
|
@ -3,8 +3,9 @@ import {
|
|||
faCircleExclamation,
|
||||
faPlus,
|
||||
} from "@fortawesome/pro-regular-svg-icons";
|
||||
import { useLocation, useNavigate } from "@solidjs/router";
|
||||
import { For, Suspense, createEffect, createResource } from "solid-js";
|
||||
import { useNavigate } from "@solidjs/router";
|
||||
import { For, createResource } from "solid-js";
|
||||
import { getRequestEvent } from "solid-js/web";
|
||||
import { FontAwesomeIcon } from "~/components/FontAwesomeIcon";
|
||||
import Layout from "~/components/Layout";
|
||||
import "../../styles/pages/config.scss";
|
||||
|
@ -20,38 +21,43 @@ const initialValue = () => ({
|
|||
|
||||
function index() {
|
||||
const navigator = useNavigate();
|
||||
const location = useLocation();
|
||||
const event = getRequestEvent();
|
||||
|
||||
const [payload] = createResource(async () => {
|
||||
const payload = await fetch("http://localhost:3000/api/config")
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<
|
||||
| {
|
||||
success: false;
|
||||
message: string;
|
||||
}
|
||||
| (ReturnType<typeof initialValue> & {
|
||||
success: true;
|
||||
})
|
||||
>,
|
||||
)
|
||||
.catch((e) => console.warn(e));
|
||||
const [payload] = createResource(
|
||||
// eslint-disable-next-line solid/reactivity
|
||||
async () => {
|
||||
const payload = await fetch("http://localhost:3000/api/config", {
|
||||
headers: event?.headers,
|
||||
})
|
||||
.then(
|
||||
(res) =>
|
||||
res.json() as Promise<
|
||||
| {
|
||||
success: false;
|
||||
message: string;
|
||||
}
|
||||
| (ReturnType<typeof initialValue> & {
|
||||
success: true;
|
||||
})
|
||||
>,
|
||||
)
|
||||
.catch((e) => console.warn(e));
|
||||
|
||||
if (!payload) return;
|
||||
if (!payload) {
|
||||
console.error("/config", payload);
|
||||
return initialValue();
|
||||
}
|
||||
|
||||
if (!payload.success) {
|
||||
console.log(location.pathname, payload.message, "No success");
|
||||
navigator("/", { replace: false });
|
||||
return initialValue();
|
||||
}
|
||||
console.log(location.pathname, "success");
|
||||
return payload;
|
||||
});
|
||||
createEffect(() => console.log(payload()?.guilds, payload()?.guilds.length));
|
||||
// createRenderEffect(() =>
|
||||
// console.log(payload()?.guilds, payload()?.guilds.length),
|
||||
// );
|
||||
if (!payload.success) {
|
||||
console.log("/config", payload.message, "No success");
|
||||
navigator("/", { replace: false });
|
||||
return initialValue();
|
||||
}
|
||||
|
||||
return payload;
|
||||
},
|
||||
{ deferStream: true },
|
||||
);
|
||||
|
||||
const icons = [faPlus, faCircleExclamation, faBadgeCheck];
|
||||
const colors = [undefined, "orange", "green"];
|
||||
|
@ -60,39 +66,37 @@ function index() {
|
|||
<Layout site="config">
|
||||
<h3 class="text-center">Configure li'l Judd in</h3>
|
||||
<div>
|
||||
<Suspense>
|
||||
<For each={payload()?.guilds}>
|
||||
{(guild, i) => {
|
||||
return (
|
||||
<a
|
||||
href={
|
||||
i() % 3 === 0
|
||||
? `/config/${guild.id}`
|
||||
: `https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_BOT_PERMISSIONS}&scope=bot&guild_id=${guild.id}`
|
||||
<For each={payload()?.guilds}>
|
||||
{(guild, i) => {
|
||||
return (
|
||||
<a
|
||||
href={
|
||||
i() % 3 === 0
|
||||
? `/config/${guild.id}`
|
||||
: `https://discord.com/api/oauth2/authorize?client_id=${import.meta.env.VITE_DISCORD_CLIENT_ID}&permissions=${import.meta.env.VITE_DISCORD_BOT_PERMISSIONS}&scope=bot&guild_id=${guild.id}`
|
||||
}
|
||||
class="flex-row centered"
|
||||
>
|
||||
<img
|
||||
class="guildpfp"
|
||||
src={
|
||||
guild.icon
|
||||
? `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp?size=240`
|
||||
: "https://cdn.discordapp.com/icons/1040502664506646548/bb5a51c4659cf47bdd942bb11e974da7.webp?size=240"
|
||||
}
|
||||
class="flex-row centered"
|
||||
>
|
||||
<img
|
||||
class="guildpfp"
|
||||
src={
|
||||
guild.icon
|
||||
? `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp?size=240`
|
||||
: "https://cdn.discordapp.com/icons/1040502664506646548/bb5a51c4659cf47bdd942bb11e974da7.webp?size=240"
|
||||
}
|
||||
alt="Server pfp"
|
||||
/>
|
||||
<h1>{guild.name}</h1>
|
||||
<FontAwesomeIcon
|
||||
// beat={i() % 3 === 1}
|
||||
color={colors[i() % 3]}
|
||||
icon={icons[i() % 3]}
|
||||
size="xl"
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
</Suspense>
|
||||
alt="Server pfp"
|
||||
/>
|
||||
<h1>{guild.name}</h1>
|
||||
<FontAwesomeIcon
|
||||
// beat={i() % 3 === 1}
|
||||
color={colors[i() % 3]}
|
||||
icon={icons[i() % 3]}
|
||||
size="xl"
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue