Fix: Cleanup and SSR auth header fix

This commit is contained in:
aronmal 2024-02-11 23:01:42 +01:00
parent b28ceb8659
commit 2b9b5198fa
Signed by: aronmal
GPG key ID: 816B7707426FC612
5 changed files with 92 additions and 128 deletions

View file

@ -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<HTMLInputElement>();
const [timePlanningRef, setTimePlanningRef] =
createSignal<HTMLInputElement>();
@ -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 (
<Layout site="config">
<h3 class="text-center">Configure li&apos;l Judd in</h3>
@ -232,10 +202,7 @@ function config() {
)
}
>
<option
disabled={!!config.features.timePlanning.channelId}
value=""
>
<option disabled value="">
--Select a Channel--
</option>
<For each={payload().guild.channels}>