From 6900e1e27bbc104cd365f3ce70a31b6f70e97e9f Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Fri, 21 Jun 2024 11:59:02 +0800 Subject: [PATCH] feat(playground): refine opened files --- .../src/components/biz/files-panel/actions.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/playground/src/components/biz/files-panel/actions.tsx b/packages/playground/src/components/biz/files-panel/actions.tsx index 114b993..cf1712c 100644 --- a/packages/playground/src/components/biz/files-panel/actions.tsx +++ b/packages/playground/src/components/biz/files-panel/actions.tsx @@ -159,7 +159,14 @@ function RenameFileDialog() { function DelFileAlertDialog() { const { - state: { allFiles, setAllFiles, activeFileId, setActiveFileId }, + state: { + allFiles, + setAllFiles, + activeFileId, + setActiveFileId, + openedFiles, + setOpenedFiles + }, api: { delFile } } = useFilesContext() @@ -174,7 +181,11 @@ function DelFileAlertDialog() { } await delFile(activeFileId) setAllFiles((pre) => pre.filter((f) => f.id !== activeFileId)) - setActiveFileId(null) + + const nextOpenedFiles = openedFiles.filter((f) => f.id !== activeFileId) + setOpenedFiles(nextOpenedFiles) + + setActiveFileId(nextOpenedFiles[0]?.id ?? null) } const queryClient = useQueryClient()