perf: attribute

This commit is contained in:
archer
2023-07-08 10:37:25 +08:00
parent 23642af6e2
commit aef42cef9d
17 changed files with 1177 additions and 351 deletions

View File

@@ -125,7 +125,7 @@ const PcSliderBar = ({
w={'100%'}
h={'100%'}
leftIcon={<AddIcon />}
onClick={() => router.replace(`/chat?modelId=${modelId}`)}
onClick={() => router.replace(`/chat?appId=${modelId}`)}
>
</Button>
@@ -176,9 +176,9 @@ const PcSliderBar = ({
onClick={() => {
if (item._id === chatId) return;
if (isPc) {
router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
router.replace(`/chat?appId=${item.modelId}&chatId=${item._id}`);
} else {
router.push(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
router.push(`/chat?appId=${item.modelId}&chatId=${item._id}`);
}
}}
onContextMenu={(e) => onclickContextMenu(e, item)}
@@ -251,7 +251,7 @@ const PcSliderBar = ({
try {
await onclickDelHistory(contextMenuData.history._id);
if (contextMenuData.history._id === chatId) {
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${modelId}`);
}
} catch (error) {
console.log(error);

View File

@@ -30,7 +30,7 @@ const ModelList = ({ models, modelId }: { models: AppListItemType[]; modelId: st
}
: {})}
onClick={() => {
router.replace(`/chat?modelId=${item._id}`);
router.replace(`/chat?appId=${item._id}`);
}}
>
<Avatar src={item.avatar} w={'34px'} h={'34px'} />

View File

@@ -95,7 +95,7 @@ const PhoneSliderBar = ({
color={'white'}
leftIcon={<AddIcon />}
onClick={() => {
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${modelId}`);
onClose();
}}
>
@@ -128,7 +128,7 @@ const PhoneSliderBar = ({
: {})}
onClick={async () => {
if (item._id === modelId) return;
router.replace(`/chat?modelId=${item._id}`);
router.replace(`/chat?appId=${item._id}`);
onClose();
}}
>
@@ -159,7 +159,7 @@ const PhoneSliderBar = ({
: {})}
onClick={() => {
if (item._id === chatId) return;
router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
router.replace(`/chat?appId=${item.modelId}&chatId=${item._id}`);
onClose();
}}
>
@@ -177,7 +177,7 @@ const PhoneSliderBar = ({
await delChatHistoryById(item._id);
loadHistory({ pageNum: 1, init: true });
if (item._id === chatId) {
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${modelId}`);
}
}}
/>

View File

@@ -65,7 +65,7 @@ const textareaMinH = '22px';
const Chat = () => {
const router = useRouter();
const { modelId = '', chatId = '' } = router.query as { modelId: string; chatId: string };
const { appId = '', chatId = '' } = router.query as { appId: string; chatId: string };
const theme = useTheme();
const ChatBox = useRef<HTMLDivElement>(null);
@@ -179,7 +179,7 @@ const Chat = () => {
data: {
messages,
chatId,
appId: modelId,
appId,
model: ''
},
onMessage: (text: string) => {
@@ -206,7 +206,7 @@ const Chat = () => {
// save chat
if (newChatId) {
setForbidLoadChatData(true);
router.replace(`/chat?modelId=${modelId}&chatId=${newChatId}`);
router.replace(`/chat?appId=${appId}&chatId=${newChatId}`);
}
abortSignal.signal.aborted && (await delay(500));
@@ -243,7 +243,7 @@ const Chat = () => {
},
[
chatId,
modelId,
appId,
setChatData,
generatingMessage,
setForbidLoadChatData,
@@ -474,17 +474,17 @@ const Chat = () => {
// 获取对话信息
const loadChatInfo = useCallback(
async ({
modelId,
appId,
chatId,
loading = false
}: {
modelId: string;
appId: string;
chatId: string;
loading?: boolean;
}) => {
try {
loading && setIsLoading(true);
const res = await getInitChatSiteInfo(modelId, chatId);
const res = await getInitChatSiteInfo(appId, chatId);
setChatData({
...res,
@@ -502,9 +502,9 @@ const Chat = () => {
}
// 空 modelId 请求, 重定向到新的 model 聊天
if (res.modelId !== modelId) {
if (res.modelId !== appId) {
setForbidLoadChatData(true);
router.replace(`/chat?modelId=${res.modelId}`);
router.replace(`/chat?appId=${res.modelId}`);
}
} catch (e: any) {
// reset all chat tore
@@ -529,15 +529,15 @@ const Chat = () => {
]
);
// 初始化聊天框
useQuery(['init', modelId, chatId], () => {
useQuery(['init', appId, chatId], () => {
// pc: redirect to latest model chat
if (!modelId && lastChatModelId) {
router.replace(`/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`);
if (!appId && lastChatModelId) {
router.replace(`/chat?appId=${lastChatModelId}&chatId=${lastChatId}`);
return null;
}
// store id
modelId && setLastChatModelId(modelId);
appId && setLastChatModelId(appId);
setLastChatId(chatId);
if (forbidLoadChatData) {
@@ -546,7 +546,7 @@ const Chat = () => {
}
return loadChatInfo({
modelId,
appId,
chatId,
loading: true
});
@@ -559,7 +559,7 @@ const Chat = () => {
isLeavePage.current = true;
controller.current?.abort();
};
}, [modelId, chatId]);
}, [appId, chatId]);
// context menu component
const RenderContextMenu = useCallback(
@@ -611,14 +611,14 @@ const Chat = () => {
backgroundColor={useColorModeValue('#fdfdfd', '')}
>
{/* pc always show history. */}
{(isPc || !modelId) && (
{(isPc || !appId) && (
<SideBar>
<History onclickDelHistory={onclickDelHistory} onclickExportChat={onclickExportChat} />
</SideBar>
)}
{/* 聊天内容 */}
{modelId && (
{appId && (
<Flex
position={'relative'}
h={[0, '100%']}
@@ -667,15 +667,13 @@ const Chat = () => {
/>
</MenuButton>
<MenuList minW={`90px !important`}>
<MenuItem onClick={() => router.replace(`/chat?modelId=${modelId}`)}>
</MenuItem>
<MenuItem onClick={() => router.replace(`/chat?appId=${appId}`)}></MenuItem>
<MenuItem
onClick={async () => {
try {
setIsLoading(true);
await onclickDelHistory(chatData.chatId);
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${appId}`);
} catch (err) {
console.log(err);
}
@@ -901,7 +899,7 @@ const Chat = () => {
<Drawer isOpen={isOpenSlider} placement="left" size={'xs'} onClose={onCloseSlider}>
<DrawerOverlay backgroundColor={'rgba(255,255,255,0.5)'} />
<DrawerContent maxW={'70%'}>
<PhoneSliderBar chatId={chatId} modelId={modelId} onClose={onCloseSlider} />
<PhoneSliderBar chatId={chatId} modelId={appId} onClose={onCloseSlider} />
</DrawerContent>
</Drawer>
)}