|
|
@ -1,4 +1,4 @@
|
|
|
|
import { useState, useEffect, useRef, useMemo } from "react";
|
|
|
|
import { useState, useEffect, useMemo, HTMLProps } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
import EmojiPicker, { Theme as EmojiTheme } from "emoji-picker-react";
|
|
|
|
import EmojiPicker, { Theme as EmojiTheme } from "emoji-picker-react";
|
|
|
|
|
|
|
|
|
|
|
@ -8,6 +8,8 @@ import ResetIcon from "../icons/reload.svg";
|
|
|
|
import CloseIcon from "../icons/close.svg";
|
|
|
|
import CloseIcon from "../icons/close.svg";
|
|
|
|
import ClearIcon from "../icons/clear.svg";
|
|
|
|
import ClearIcon from "../icons/clear.svg";
|
|
|
|
import EditIcon from "../icons/edit.svg";
|
|
|
|
import EditIcon from "../icons/edit.svg";
|
|
|
|
|
|
|
|
import EyeIcon from "../icons/eye.svg";
|
|
|
|
|
|
|
|
import EyeOffIcon from "../icons/eye-off.svg";
|
|
|
|
|
|
|
|
|
|
|
|
import { List, ListItem, Popover, showToast } from "./ui-lib";
|
|
|
|
import { List, ListItem, Popover, showToast } from "./ui-lib";
|
|
|
|
|
|
|
|
|
|
|
@ -47,6 +49,28 @@ function SettingItem(props: {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function PasswordInput(props: HTMLProps<HTMLInputElement>) {
|
|
|
|
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function changeVisibility() {
|
|
|
|
|
|
|
|
setVisible(!visible);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<span style={{ display: "flex", justifyContent: "end" }}>
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
|
|
|
{...props}
|
|
|
|
|
|
|
|
style={{ minWidth: "150px" }}
|
|
|
|
|
|
|
|
type={visible ? "text" : "password"}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<IconButton
|
|
|
|
|
|
|
|
icon={visible ? <EyeIcon /> : <EyeOffIcon />}
|
|
|
|
|
|
|
|
onClick={changeVisibility}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function Settings(props: { closeSettings: () => void }) {
|
|
|
|
export function Settings(props: { closeSettings: () => void }) {
|
|
|
|
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
|
|
|
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
|
|
|
const [config, updateConfig, resetConfig, clearAllData, clearSessions] =
|
|
|
|
const [config, updateConfig, resetConfig, clearAllData, clearSessions] =
|
|
|
@ -103,6 +127,13 @@ export function Settings(props: { closeSettings: () => void }) {
|
|
|
|
const builtinCount = SearchService.count.builtin;
|
|
|
|
const builtinCount = SearchService.count.builtin;
|
|
|
|
const customCount = promptStore.prompts.size ?? 0;
|
|
|
|
const customCount = promptStore.prompts.size ?? 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const showUsage = accessStore.token !== "";
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
if (showUsage) {
|
|
|
|
|
|
|
|
checkUsage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [showUsage]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<div className={styles["window-header"]}>
|
|
|
|
<div className={styles["window-header"]}>
|
|
|
@ -327,14 +358,14 @@ export function Settings(props: { closeSettings: () => void }) {
|
|
|
|
title={Locale.Settings.AccessCode.Title}
|
|
|
|
title={Locale.Settings.AccessCode.Title}
|
|
|
|
subTitle={Locale.Settings.AccessCode.SubTitle}
|
|
|
|
subTitle={Locale.Settings.AccessCode.SubTitle}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
<PasswordInput
|
|
|
|
value={accessStore.accessCode}
|
|
|
|
value={accessStore.accessCode}
|
|
|
|
type="text"
|
|
|
|
type="text"
|
|
|
|
placeholder={Locale.Settings.AccessCode.Placeholder}
|
|
|
|
placeholder={Locale.Settings.AccessCode.Placeholder}
|
|
|
|
onChange={(e) => {
|
|
|
|
onChange={(e) => {
|
|
|
|
accessStore.updateCode(e.currentTarget.value);
|
|
|
|
accessStore.updateCode(e.currentTarget.value);
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
></input>
|
|
|
|
/>
|
|
|
|
</SettingItem>
|
|
|
|
</SettingItem>
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
<></>
|
|
|
@ -344,25 +375,27 @@ export function Settings(props: { closeSettings: () => void }) {
|
|
|
|
title={Locale.Settings.Token.Title}
|
|
|
|
title={Locale.Settings.Token.Title}
|
|
|
|
subTitle={Locale.Settings.Token.SubTitle}
|
|
|
|
subTitle={Locale.Settings.Token.SubTitle}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
<PasswordInput
|
|
|
|
value={accessStore.token}
|
|
|
|
value={accessStore.token}
|
|
|
|
type="text"
|
|
|
|
type="text"
|
|
|
|
placeholder={Locale.Settings.Token.Placeholder}
|
|
|
|
placeholder={Locale.Settings.Token.Placeholder}
|
|
|
|
onChange={(e) => {
|
|
|
|
onChange={(e) => {
|
|
|
|
accessStore.updateToken(e.currentTarget.value);
|
|
|
|
accessStore.updateToken(e.currentTarget.value);
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
></input>
|
|
|
|
/>
|
|
|
|
</SettingItem>
|
|
|
|
</SettingItem>
|
|
|
|
|
|
|
|
|
|
|
|
<SettingItem
|
|
|
|
<SettingItem
|
|
|
|
title={Locale.Settings.Usage.Title}
|
|
|
|
title={Locale.Settings.Usage.Title}
|
|
|
|
subTitle={
|
|
|
|
subTitle={
|
|
|
|
loadingUsage
|
|
|
|
showUsage
|
|
|
|
|
|
|
|
? loadingUsage
|
|
|
|
? Locale.Settings.Usage.IsChecking
|
|
|
|
? Locale.Settings.Usage.IsChecking
|
|
|
|
: Locale.Settings.Usage.SubTitle(usage?.used ?? "[?]")
|
|
|
|
: Locale.Settings.Usage.SubTitle(usage?.used ?? "[?]")
|
|
|
|
|
|
|
|
: Locale.Settings.Usage.NoAccess
|
|
|
|
}
|
|
|
|
}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{loadingUsage ? (
|
|
|
|
{!showUsage || loadingUsage ? (
|
|
|
|
<div />
|
|
|
|
<div />
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
|
<IconButton
|
|
|
|
<IconButton
|
|
|
|