"use client"; import ClientOnly from "@/components/ClientOnly"; import { StoragePathSelector } from "@/components/form/StoragePathSelector"; import TextInput from "@/components/form/TextInput"; import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling"; import { useGlobalSettingsQuery, useUpdateGlobalSettingsMutation, } from "@/features/local/globalSettings/globalSettingsHooks"; import { useDirectoryIsCourseQuery } from "@/features/local/utils/storageDirectoryHooks"; import { FC, useEffect, useRef, useState } from "react"; export const AddExistingCourseToGlobalSettings = () => { const [showForm, setShowForm] = useState(false); return (
{showForm && }
); }; const ExistingCourseForm: FC = () => { const [path, setPath] = useState("./"); const [name, setName] = useState(""); const nameInputRef = useRef(null); const directoryIsCourseQuery = useDirectoryIsCourseQuery(path); const { data: globalSettings } = useGlobalSettingsQuery(); const updateSettingsMutation = useUpdateGlobalSettingsMutation(); // Focus name input when directory becomes a valid course useEffect(() => { console.log("Checking directory:", directoryIsCourseQuery.data); if (directoryIsCourseQuery.data) { console.log("Focusing name input"); nameInputRef.current?.focus(); } }, [directoryIsCourseQuery.data]); return (
{ e.preventDefault(); console.log(path); await updateSettingsMutation.mutateAsync({ globalSettings: { ...globalSettings, courses: [ ...globalSettings.courses, { name, path, }, ], }, }); setName(""); setPath("./"); }} className="min-w-3xl" >

Add Existing Course

{directoryIsCourseQuery.isLoading ? ( <> Checking directory... ) : directoryIsCourseQuery.data ? ( <> This is a valid course directory. ) : ( <> Not a course directory. )}
{directoryIsCourseQuery.data && ( <>
)} ); };