2024-02-07 21:07:41 +05:30
|
|
|
import { useQueryClient } from "@tanstack/react-query"
|
2024-03-23 14:44:05 +05:30
|
|
|
import { useDarkMode } from "~/hooks/useDarkmode"
|
|
|
|
|
import { useMessageOption } from "~/hooks/useMessageOption"
|
|
|
|
|
import { PageAssitDatabase } from "~/libs/db"
|
2024-02-15 00:26:13 +05:30
|
|
|
import { Select } from "antd"
|
2024-03-23 14:44:05 +05:30
|
|
|
import { SUPPORTED_LANGUAGES } from "~/utils/supporetd-languages"
|
2024-02-25 18:55:29 +05:30
|
|
|
import { MoonIcon, SunIcon } from "lucide-react"
|
2024-03-04 00:32:01 +05:30
|
|
|
import { SearchModeSettings } from "./search-mode"
|
2024-03-24 12:43:43 +05:30
|
|
|
import { useTranslation } from "react-i18next"
|
2024-02-07 21:07:41 +05:30
|
|
|
|
|
|
|
|
export const SettingOther = () => {
|
2024-02-15 00:26:13 +05:30
|
|
|
const { clearChat, speechToTextLanguage, setSpeechToTextLanguage } =
|
|
|
|
|
useMessageOption()
|
2024-02-07 21:07:41 +05:30
|
|
|
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
|
|
|
|
|
|
const { mode, toggleDarkMode } = useDarkMode()
|
2024-03-24 12:43:43 +05:30
|
|
|
const { t } = useTranslation("option")
|
|
|
|
|
|
2024-02-07 21:07:41 +05:30
|
|
|
|
|
|
|
|
return (
|
2024-03-24 12:43:43 +05:30
|
|
|
<dl className="flex flex-col space-y-6 text-sm">
|
2024-03-03 19:55:43 +05:30
|
|
|
<div>
|
|
|
|
|
<h2 className="text-base font-semibold leading-7 text-gray-900 dark:text-white">
|
2024-03-24 12:43:43 +05:30
|
|
|
{t("generalSettings.heading")}
|
2024-03-03 19:55:43 +05:30
|
|
|
</h2>
|
|
|
|
|
<div className="border border-b border-gray-200 dark:border-gray-600 mt-3"></div>
|
|
|
|
|
</div>
|
2024-02-07 21:07:41 +05:30
|
|
|
<div className="flex flex-row justify-between">
|
2024-03-24 12:43:43 +05:30
|
|
|
<span className="text-gray-500 dark:text-neutral-50">
|
|
|
|
|
{t("generalSettings.settings.speechRecognitionLang.label")}
|
2024-02-15 00:26:13 +05:30
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<Select
|
2024-03-24 12:43:43 +05:30
|
|
|
placeholder={t("generalSettings.settings.speechRecognitionLang.placeholder")}
|
2024-02-15 00:26:13 +05:30
|
|
|
allowClear
|
|
|
|
|
showSearch
|
|
|
|
|
options={SUPPORTED_LANGUAGES}
|
|
|
|
|
value={speechToTextLanguage}
|
|
|
|
|
filterOption={(input, option) =>
|
2024-03-24 12:43:43 +05:30
|
|
|
option!.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
|
|
|
|
|
option!.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
2024-02-25 23:45:07 +05:30
|
|
|
}
|
2024-02-15 00:26:13 +05:30
|
|
|
onChange={(value) => {
|
|
|
|
|
setSpeechToTextLanguage(value)
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-row justify-between">
|
2024-03-24 12:43:43 +05:30
|
|
|
<span className="text-gray-500 dark:text-neutral-50 ">
|
|
|
|
|
{t("generalSettings.settings.darkMode.label")}
|
|
|
|
|
</span>
|
2024-02-07 21:07:41 +05:30
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
onClick={toggleDarkMode}
|
2024-02-15 00:26:13 +05:30
|
|
|
className={`inline-flex mt-4 items-center rounded-md border border-transparent bg-black px-2 py-2 text-sm font-medium leading-4 text-white shadow-sm dark:bg-white dark:text-gray-800 disabled:opacity-50 `}>
|
|
|
|
|
{mode === "dark" ? (
|
2024-02-25 18:55:29 +05:30
|
|
|
<SunIcon className="w-4 h-4 mr-2" />
|
2024-02-15 00:26:13 +05:30
|
|
|
) : (
|
2024-02-25 18:55:29 +05:30
|
|
|
<MoonIcon className="w-4 h-4 mr-2" />
|
2024-02-15 00:26:13 +05:30
|
|
|
)}
|
2024-03-24 12:43:43 +05:30
|
|
|
{mode === "dark" ? t("generalSettings.settings.darkMode.options.light") : t("generalSettings.settings.darkMode.options.dark")}
|
2024-02-07 21:07:41 +05:30
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-03-10 12:52:53 +05:30
|
|
|
<SearchModeSettings />
|
2024-02-07 21:07:41 +05:30
|
|
|
<div className="flex flex-row justify-between">
|
2024-03-10 12:52:53 +05:30
|
|
|
<span className="text-gray-500 dark:text-neutral-50 ">
|
2024-03-24 12:43:43 +05:30
|
|
|
{t("generalSettings.settings.deleteChatHistory.label")}
|
2024-02-07 21:07:41 +05:30
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
const confirm = window.confirm(
|
2024-03-24 12:43:43 +05:30
|
|
|
t("generalSettings.settings.deleteChatHistory.confirm")
|
2024-02-07 21:07:41 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (confirm) {
|
|
|
|
|
const db = new PageAssitDatabase()
|
|
|
|
|
await db.deleteChatHistory()
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
queryKey: ["fetchChatHistory"]
|
|
|
|
|
})
|
|
|
|
|
clearChat()
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
className="bg-red-500 dark:bg-red-600 text-white dark:text-gray-200 px-4 py-2 rounded-md">
|
2024-03-24 12:43:43 +05:30
|
|
|
{t("generalSettings.settings.deleteChatHistory.button")}
|
2024-02-07 21:07:41 +05:30
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-03-03 19:55:43 +05:30
|
|
|
</dl>
|
2024-02-07 21:07:41 +05:30
|
|
|
)
|
|
|
|
|
}
|