"use client"; import axios from "axios"; import * as React from 'react'; import { Check, ChevronsUpDown } from "lucide-react" import { useEffect, useReducer, useState } from "react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button" import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "@/components/ui/command" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; import voices from "@/data/tts"; import InfoNotice from "@/components/elements/info-notice"; const TTSVoiceFiltersPage = () => { const [open, setOpen] = useState(false) const [defaultVoice, setDefaultVoice] = useState("") const [loading, setLoading] = useState(true) function enabledVoicesReducer(enabledVoices: { [voice: string]: boolean }, action: { type: string, value: string }) { if (action.type == "enable") { return { ...enabledVoices, [action.value]: true } } else if (action.type == "disable") { return { ...enabledVoices, [action.value]: false } } return enabledVoices } const [enabledVoices, dispatchEnabledVoices] = useReducer(enabledVoicesReducer, Object.assign({}, ...voices.map(v => ({[v]: false}) ))) useEffect(() => { axios.get("/api/settings/tts/default") .then((voice) => { setDefaultVoice(voice.data) }) axios.get("/api/settings/tts") .then((d) => { const data: string[] = d.data; data.forEach(d => dispatchEnabledVoices({ type: "enable", value: d })) setLoading(false) }) }, []) const onDefaultChange = (voice: string) => { try { axios.post("/api/settings/tts/default", { voice }) .catch(e => console.error(e)) } catch (error) { console.log("[TTS/DEFAULT]", error); } } const onEnabledChanged = (voice: string, state: boolean) => { try { axios.post("/api/settings/tts", { voice: voice, state: state }) .catch(e => console.error(e)) } catch (error) { console.log("[TTS/ENABLED]", error); } } return (
Voices Enabled