diff --git a/src/components/NavUser.tsx b/src/components/NavUser.tsx index 6fd3fa9..1fab326 100644 --- a/src/components/NavUser.tsx +++ b/src/components/NavUser.tsx @@ -46,13 +46,13 @@ async function getUser() { } function NavUser() { - const [user] = createResource(() => - getUser().then((e) => { - if (!e.success) console.log(1, e.message); - console.log(2, e); - return e; - }), - ); + const [user] = createResource(async () => { + const user = await getUser(); + + if (!user.success) console.error("userInfo", user.message); + + return user; + }); return ( => { const id = event.params.guildId; - // const id = "598539452343648256"; - // const location = useLocation(); if (!event) return { success: false, message: "No request event!" }; const session = await getSession(event.request, authOptions); @@ -62,9 +60,8 @@ export const GET = async ( }, headers: { Authorization: `Bot ${import.meta.env.VITE_DISCORD_BOT_TOKEN}` }, }); - if (guildsRequest.error || channelsRequest.error) { - console.log(guildsRequest.error, channelsRequest.error, location.pathname); + console.log(guildsRequest.error, channelsRequest.error, event.path); return { success: false, message: "Error on one of the discord api requests!", @@ -94,8 +91,6 @@ export const GET = async ( }); }); - console.log("done"); - return { success: true, guild: { diff --git a/src/routes/api/config/index.tsx b/src/routes/api/config/index.tsx index 1eec136..7dfc0c8 100644 --- a/src/routes/api/config/index.tsx +++ b/src/routes/api/config/index.tsx @@ -45,8 +45,6 @@ export const GET = async ( headers: { Authorization: `Bearer ${DISCORD_ACCESS_TOKEN}` }, }); - console.log("guilds", guilds); - if (error) { console.log(error); return { success: false, message: "Error on discord api request!" }; diff --git a/src/routes/config/[guildId].tsx b/src/routes/config/[guildId].tsx index 9e372c9..75aefb9 100644 --- a/src/routes/config/[guildId].tsx +++ b/src/routes/config/[guildId].tsx @@ -8,6 +8,7 @@ import { createSignal, } from "solid-js"; import { createStore } from "solid-js/store"; +import { getRequestEvent } from "solid-js/web"; import { FontAwesomeIcon } from "~/components/FontAwesomeIcon"; import Layout from "~/components/Layout"; import "../../styles/pages/config.scss"; @@ -30,6 +31,8 @@ function config() { const params = useParams(); const navigator = useNavigate(); const location = useLocation(); + const event = getRequestEvent(); + const [timezoneRef, setTimezoneRef] = createSignal(); const [timePlanningRef, setTimePlanningRef] = createSignal(); @@ -41,7 +44,9 @@ function config() { const [payload] = createResource( params.guildId, async (id) => { - const payload = await fetch(`http://localhost:3000/api/config/${id}`) + const payload = await fetch(`http://localhost:3000/api/config/${id}`, { + headers: event?.headers, + }) .then( (res) => res.json() as Promise< @@ -56,17 +61,24 @@ function config() { ) .catch((e) => console.warn(e, id)); - if (!payload) return initialValue(params); + if (!payload) { + console.error(location.pathname, payload); + return initialValue(params); + } if (!payload.success) { console.log(payload); console.log(location.pathname, payload.message, "No success"); - // navigator("/config", { replace: false }); + navigator("/config", { replace: false }); return initialValue(params); } + return payload; }, - { initialValue: initialValue(params) }, + { + initialValue: initialValue(params), + deferStream: true, + }, ); const [config, setConfig] = createStore({ features: { @@ -78,53 +90,13 @@ function config() { }, }); - createEffect(() => console.log(payload.loading, payload())); - createEffect(() => console.log("timezone", timezone())); - createEffect(() => - console.log("timePlanning.enabled", config.features.timePlanning.enabled), - ); - createEffect(() => - console.log( - "timePlanning.channelId", - config.features.timePlanning.channelId, - ), - ); - createEffect(() => - console.log( - "timePlanning.pingableRoles", - config.features.timePlanning.pingableRoles, - ), - ); - - createEffect(() => { - const ref = timezoneRef(); - if (!ref) return; - ref.value = timezone(); - }); - createEffect(() => { - const ref = timePlanningRef(); - if (!ref) return; - ref.checked = config.features.timePlanning.enabled; - }); createEffect(() => { const channelId = payload().guild.channel; setConfig("features", "timePlanning", "channelId", channelId); - console.log(channelId, payload()); const ref = channelRef(); if (!ref) return; - if ( - !ref || - !channelId || - !payload().guild.channels.find((e) => e.id === channelId) - ) - return; ref.value = channelId; }); - createEffect(() => { - const ref = pingableRolesRef(); - if (!ref) return; - ref.checked = config.features.timePlanning.pingableRoles; - }); createEffect(() => { const ref = timezoneRef(); if (!ref) return; @@ -141,8 +113,6 @@ function config() { ref.checked = config.features.timePlanning.pingableRoles; }); - // console.log(payload()); - return (

Configure li'l Judd in

@@ -232,10 +202,7 @@ function config() { ) } > - diff --git a/src/routes/config/index.tsx b/src/routes/config/index.tsx index 207831a..278f8dc 100644 --- a/src/routes/config/index.tsx +++ b/src/routes/config/index.tsx @@ -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 & { - 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 & { + 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() {

Configure li'l Judd in

- - - {(guild, i) => { - return ( - + {(guild, i) => { + return ( + + - Server pfp -

{guild.name}

- -
- ); - }} -
-
+ alt="Server pfp" + /> +

{guild.name}

+ + + ); + }} +
);