mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(component): add LanguageServerAccordion for language server settings
This commit is contained in:
parent
1acd915459
commit
bd085751b6
@ -0,0 +1,70 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Accordion,
|
||||||
|
AccordionContent,
|
||||||
|
AccordionItem,
|
||||||
|
AccordionTrigger,
|
||||||
|
} from "@/components/ui/accordion";
|
||||||
|
import { Loading } from "@/components/loading";
|
||||||
|
import { useAdminSettingsStore } from "@/store/useAdminSettingsStore";
|
||||||
|
import { EditorLanguage, LanguageServerConfig } from "@prisma/client";
|
||||||
|
import { SettingsLanguageServerForm } from "@/app/(app)/dashboard/@admin/settings/language-server/form";
|
||||||
|
|
||||||
|
interface LanguageServerAccordionProps {
|
||||||
|
configs: {
|
||||||
|
language: EditorLanguage;
|
||||||
|
config: LanguageServerConfig | null;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LanguageServerAccordion({
|
||||||
|
configs,
|
||||||
|
}: LanguageServerAccordionProps) {
|
||||||
|
const { hydrated, activeLanguageServerSetting, setActiveLanguageServerSetting } =
|
||||||
|
useAdminSettingsStore();
|
||||||
|
|
||||||
|
if (!hydrated) return <Loading />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Accordion
|
||||||
|
type="single"
|
||||||
|
collapsible
|
||||||
|
className="w-full space-y-2"
|
||||||
|
value={activeLanguageServerSetting}
|
||||||
|
onValueChange={setActiveLanguageServerSetting}
|
||||||
|
>
|
||||||
|
{configs.map(({ language, config }) => (
|
||||||
|
<AccordionItem
|
||||||
|
key={language}
|
||||||
|
value={language}
|
||||||
|
className="has-focus-visible:border-ring has-focus-visible:ring-ring/50 rounded-md border outline-none last:border-b has-focus-visible:ring-[3px]"
|
||||||
|
>
|
||||||
|
<AccordionTrigger className="px-4 py-3 justify-start gap-3 text-[15px] leading-6 hover:no-underline focus-visible:ring-0 [&>svg]:-order-1">
|
||||||
|
{language.toUpperCase()}
|
||||||
|
</AccordionTrigger>
|
||||||
|
<AccordionContent className="text-muted-foreground pb-0">
|
||||||
|
<div className="px-4 py-3">
|
||||||
|
<SettingsLanguageServerForm
|
||||||
|
defaultValues={
|
||||||
|
config
|
||||||
|
? {
|
||||||
|
protocol: config.protocol,
|
||||||
|
hostname: config.hostname,
|
||||||
|
port: config.port,
|
||||||
|
path: config.path,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
port: null,
|
||||||
|
path: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
language={language}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</AccordionContent>
|
||||||
|
</AccordionItem>
|
||||||
|
))}
|
||||||
|
</Accordion>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user