feat: support settings

This commit is contained in:
Henry Li
2026-01-20 23:43:21 +08:00
parent 3191a3845f
commit 10d253f461
25 changed files with 1355 additions and 217 deletions

View File

@@ -0,0 +1,25 @@
import { env } from "@/env";
import type { Skill } from "./type";
export async function loadSkills() {
const skills = await fetch(`${env.NEXT_PUBLIC_BACKEND_BASE_URL}/api/skills`);
const json = await skills.json();
return json.skills as Skill[];
}
export async function enableSkill(skillName: string, enabled: boolean) {
const response = await fetch(
`${env.NEXT_PUBLIC_BACKEND_BASE_URL}/api/skills/${skillName}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
enabled,
}),
},
);
return response.json();
}

View File

@@ -0,0 +1,31 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { enableSkill } from "./api";
import { loadSkills } from ".";
export function useSkills() {
const { data, isLoading, error } = useQuery({
queryKey: ["skills"],
queryFn: () => loadSkills(),
});
return { skills: data ?? [], isLoading, error };
}
export function useEnableSkill() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
skillName,
enabled,
}: {
skillName: string;
enabled: boolean;
}) => {
await enableSkill(skillName, enabled);
},
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: ["skills"] });
},
});
}

View File

@@ -0,0 +1,2 @@
export * from "./api";
export * from "./type";

View File

@@ -0,0 +1,7 @@
export interface Skill {
name: string;
description: string;
category: string;
license: string;
enabled: boolean;
}