Added redemptions & redeemable actions. Fixed a few bugs.
This commit is contained in:
@@ -230,7 +230,7 @@ const TTSFiltersPage = () => {
|
||||
<Form {...usernameFilteredForm}>
|
||||
<form onSubmit={usernameFilteredForm.handleSubmit(onAdd)}>
|
||||
<div className="flex w-full items-center justify-between rounded-md border px-4 py-2 gap-3 mt-2">
|
||||
<Label className="rounded-lg bg-primary px-2 py-1 text-xs text-primary-foreground ">
|
||||
<Label className="rounded-lg bg-primary px-2 py-1 text-xs text-primary-foreground">
|
||||
{tag}
|
||||
</Label>
|
||||
<FormField
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
import axios from "axios";
|
||||
import * as React from 'react';
|
||||
import { Check, ChevronsUpDown } from "lucide-react"
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useEffect, useReducer, useState } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "@/components/ui/command"
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
|
||||
@@ -16,49 +14,50 @@ import voices from "@/data/tts";
|
||||
import InfoNotice from "@/components/elements/info-notice";
|
||||
|
||||
const TTSVoiceFiltersPage = () => {
|
||||
const { data: session, status } = useSession();
|
||||
const [loading, setLoading] = useState<boolean>(true)
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
const [value, setValue] = useState(0)
|
||||
const [enabled, setEnabled] = useState(0)
|
||||
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) => {
|
||||
setValue(Number.parseInt(voice.data.value))
|
||||
setDefaultVoice(voice.data)
|
||||
})
|
||||
|
||||
|
||||
axios.get("/api/settings/tts")
|
||||
.then((d) => {
|
||||
const total = d.data.reduce((acc: number, item: {value: number, label: string, gender: string, language: string}) => acc |= 1 << (item.value - 1), 0)
|
||||
setEnabled(total)
|
||||
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 })
|
||||
.then(d => {
|
||||
console.log(d)
|
||||
})
|
||||
.catch(e => console.error(e))
|
||||
} catch (error) {
|
||||
console.log("[TTS/DEFAULT]", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const onEnabledChanged = (val: number) => {
|
||||
const onEnabledChanged = (voice: string, state: boolean) => {
|
||||
try {
|
||||
axios.post("/api/settings/tts", { voice: val })
|
||||
.then(d => {
|
||||
console.log(d)
|
||||
})
|
||||
axios.post("/api/settings/tts", { voice: voice, state: state })
|
||||
.catch(e => console.error(e))
|
||||
} catch (error) {
|
||||
console.log("[TTS]", error);
|
||||
return;
|
||||
console.log("[TTS/ENABLED]", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ const TTSVoiceFiltersPage = () => {
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="w-[200px] justify-between">
|
||||
{value ? voices.find(v => Number.parseInt(v.value) == value)?.label : "Select voice..."}
|
||||
{defaultVoice ? voices.find(v => v == defaultVoice) : "Select voice..."}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
@@ -89,20 +88,20 @@ const TTSVoiceFiltersPage = () => {
|
||||
<CommandGroup>
|
||||
{voices.map((voice) => (
|
||||
<CommandItem
|
||||
key={voice.value + "-" + voice.label}
|
||||
value={voice.value}
|
||||
onSelect={(currentValue) => {
|
||||
setValue(Number.parseInt(currentValue))
|
||||
onDefaultChange(voice.label)
|
||||
key={voice}
|
||||
value={voice}
|
||||
onSelect={(currentVoice) => {
|
||||
setDefaultVoice(voice)
|
||||
onDefaultChange(voice)
|
||||
setOpen(false)
|
||||
}}>
|
||||
<Check
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
value === Number.parseInt(voice.value) ? "opacity-100" : "opacity-0"
|
||||
defaultVoice === voice ? "opacity-100" : "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{voice.label}
|
||||
{voice}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
@@ -116,14 +115,14 @@ const TTSVoiceFiltersPage = () => {
|
||||
<InfoNotice message="Voices can be disabled from being used. Default voice will always work." hidden={false} />
|
||||
<div className="grid grid-cols-4 grid-flow-row gap-4 pt-[20px]">
|
||||
{voices.map((v, i) => (
|
||||
<div key={v.label + "-enabled"} className="h-[30px] row-span-1 col-span-1 align-middle flex items-center justify-center">
|
||||
<div key={v + "-enabled"} className="h-[30px] row-span-1 col-span-1 align-middle flex items-center justify-center">
|
||||
<Checkbox onClick={() => {
|
||||
const newVal = enabled ^ (1 << (Number.parseInt(v.value) - 1))
|
||||
setEnabled(newVal)
|
||||
onEnabledChanged(newVal)
|
||||
dispatchEnabledVoices({ type: enabledVoices[v] ? "disable" : "enable", value: v })
|
||||
onEnabledChanged(v, !enabledVoices[v])
|
||||
}}
|
||||
checked={(enabled & (1 << (Number.parseInt(v.value) - 1))) > 0} />
|
||||
<div className="pl-[5px]">{v.label}</div>
|
||||
disabled={loading}
|
||||
checked={enabledVoices[v]} />
|
||||
<div className="pl-[5px]">{v}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user