crush-level-web/src/app/(main)/chat/[id]/Drawer/index.tsx

108 lines
3.2 KiB
TypeScript
Raw Normal View History

2025-12-17 10:13:47 +00:00
'use client';
import Profile from './Profile';
import MaskList from './MaskList';
2025-12-17 10:13:47 +00:00
import VoiceActor from './VoiceActor';
import Font from './Font';
import MaxToken from './MaxToken';
import Background from './Background';
import ChatModel from './ChatModel';
import { IconButton } from '@/components/ui/button';
import React, { useState } from 'react';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
2025-12-18 10:14:12 +00:00
import { useStreamChatStore } from '../stream-chat';
import IconFont from '@/components/ui/iconFont';
import MaskCreate from './MaskCreate';
2025-12-23 06:35:26 +00:00
import { useTranslations } from 'next-intl';
2025-12-17 10:13:47 +00:00
type SettingProps = {
open: boolean;
onOpenChange: (open: boolean) => void;
};
export type ActiveTabType =
| 'profile'
| 'mask'
| 'mask_create'
2025-12-17 10:13:47 +00:00
| 'history'
| 'voice_actor'
| 'font'
| 'max_token'
| 'background'
2025-12-18 10:14:12 +00:00
| 'model';
2025-12-17 10:13:47 +00:00
const backMap = {
mask: 'profile',
mask_create: 'mask',
history: 'profile',
voice_actor: 'profile',
font: 'profile',
max_token: 'profile',
background: 'profile',
model: 'profile',
} as const;
2025-12-17 10:13:47 +00:00
export default function SettingDialog({ open, onOpenChange }: SettingProps) {
2025-12-23 06:35:26 +00:00
const t = useTranslations('chat.drawer');
2025-12-17 10:13:47 +00:00
const [activeTab, setActiveTab] = useState<ActiveTabType>('profile');
2025-12-18 10:14:12 +00:00
const updateUserChatSetting = useStreamChatStore((store) => store.updateUserChatSetting);
2025-12-23 06:35:26 +00:00
const titleMap = {
mask: t('maskedIdentityMode'),
mask_create: t('createMask'),
history: t('history'),
voice_actor: t('voiceActorTitle'),
font: t('fontTitle'),
max_token: t('maxToken'),
background: t('background'),
model: t('model'),
};
2025-12-18 10:14:12 +00:00
const handleChange = (open: boolean) => {
if (!open) {
updateUserChatSetting();
}
onOpenChange(open);
};
2025-12-17 10:13:47 +00:00
return (
2025-12-18 10:14:12 +00:00
<AlertDialog open={open} onOpenChange={handleChange}>
2025-12-18 10:59:55 +00:00
<AlertDialogContent className="max-w-[500px]" showCloseButton={activeTab === 'profile'}>
2025-12-17 10:13:47 +00:00
<AlertDialogTitle className="flex justify-between">
{activeTab === 'profile' ? (
<IconButton variant="tertiary" size="small" iconfont="icon-Like" />
) : (
titleMap[activeTab]
)}
{activeTab !== 'profile' && (
<IconButton
variant="tertiary"
size="small"
onClick={() => setActiveTab(backMap[activeTab])}
>
<IconFont size={24} className="text-white cursor-pointer" type="icon-jiantou" />
2025-12-17 10:13:47 +00:00
</IconButton>
)}
</AlertDialogTitle>
<div className="w-full h-[calc(100vh-160px)] pr-1 mt-4">
{activeTab === 'profile' && <Profile onActiveTab={setActiveTab} />}
{activeTab === 'mask' && <MaskList onActiveTab={setActiveTab} />}
{activeTab === 'mask_create' && <MaskCreate onActiveTab={setActiveTab} />}
2025-12-17 10:13:47 +00:00
{activeTab === 'voice_actor' && <VoiceActor />}
{activeTab === 'font' && <Font />}
{activeTab === 'max_token' && <MaxToken />}
{activeTab === 'background' && <Background />}
{activeTab === 'model' && <ChatModel />}
</div>
</AlertDialogContent>
</AlertDialog>
);
}