Fix: ref is undefined

This commit is contained in:
Aron Malcher 2024-02-02 19:31:53 +01:00
parent 6b07599a68
commit 2ced092aa4
Signed by: aronmal
GPG key ID: 816B7707426FC612

View file

@ -98,9 +98,10 @@ const getPayload = async (
function config() {
const params = useParams();
const navigator = useNavigate();
let timezoneRef: HTMLInputElement;
let timePlanningRef: HTMLInputElement;
let pingableRolesRef: HTMLInputElement;
let [timezoneRef, setTimezoneRef] = createSignal<HTMLInputElement>();
let [timePlanningRef, setTimePlanningRef] = createSignal<HTMLInputElement>();
let [pingableRolesRef, setPingableRolesRef] =
createSignal<HTMLInputElement>();
const [timezone, setTimezone] = createSignal(guessTZ());
const [payload] = createResource(params.guildId, async (id) => {
@ -136,14 +137,21 @@ function config() {
),
);
createEffect(() => (timezoneRef.value = timezone()));
createEffect(
() => (timePlanningRef.checked = config.features.timePlanning.enabled),
);
createEffect(
() =>
(pingableRolesRef.checked = 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 ref = pingableRolesRef();
if (!ref) return;
ref.checked = config.features.timePlanning.pingableRoles;
});
return (
<Layout site="config">
@ -155,8 +163,9 @@ function config() {
class="guildpfp"
src={
guild()?.icon
? `https://cdn.discordapp.com/icons/${guild()?.id}/${guild()
?.icon}.webp?size=240`
? `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"
@ -174,7 +183,7 @@ function config() {
type="text"
list="timezones"
id="timezone"
ref={timezoneRef!}
ref={(e) => setTimezoneRef(e)}
// disabled={!tzNames().find((e) => e === timezone())}
onInput={(e) => setTimezone(e.target.value)}
/>
@ -211,7 +220,7 @@ function config() {
hidden
type="checkbox"
id="timePlanning"
ref={timePlanningRef!}
ref={(e) => setTimePlanningRef(e)}
onInput={(e) =>
setConfig("features", "timePlanning", "enabled", e.target.checked)
}
@ -246,7 +255,7 @@ function config() {
hidden
type="checkbox"
id="pingableRoles"
ref={pingableRolesRef!}
ref={(e) => setPingableRolesRef(e)}
onInput={(e) =>
setConfig(
"features",