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