-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Su Weijie
committed
Sep 6, 2023
1 parent
f44ebad
commit 596660e
Showing
10 changed files
with
193 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
packages/ChatGPT/src/components/FolderSelect/FolderSelectItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/ChatGPT/src/features/Home/FolderDetail/components/FolderHeader/MoveFolder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
FormLabel, | ||
IconButton, | ||
Tooltip, | ||
} from '@mui/material'; | ||
import DriveFileMoveIcon from '@mui/icons-material/DriveFileMove'; | ||
import { useCallback, useState } from 'react'; | ||
import FolderSelect from '@chatgpt/components/FolderSelect'; | ||
import { Controller, useForm } from 'react-hook-form'; | ||
import { MoveFolderParams, moveFolder } from '@chatgpt/service/chat'; | ||
import { useAppDispatch } from '@chatgpt/app/hooks'; | ||
import { fetchConversations } from '@chatgpt/features/Conversations/conversationSlice'; | ||
import { Folder } from '@chatgpt/types/folder'; | ||
|
||
export interface MoveFolderProps { | ||
folder: Folder; | ||
} | ||
|
||
export default function MoveFolder({ folder }: MoveFolderProps) { | ||
const dispatch = useAppDispatch(); | ||
const [open, setOpen] = useState(false); | ||
const handleOpen = useCallback(() => setOpen(true), []); | ||
const handleClose = useCallback(() => setOpen(false), []); | ||
const { control, handleSubmit } = useForm<Pick<MoveFolderParams, 'parentId'>>({ | ||
defaultValues: { | ||
parentId: folder.parentId, | ||
}, | ||
}); | ||
const onSubmit = useCallback( | ||
async ({ parentId }: Pick<MoveFolderParams, 'parentId'>) => { | ||
await moveFolder({ parentId, id: folder.id }); | ||
dispatch(fetchConversations()); | ||
handleClose(); | ||
}, | ||
[folder.id, dispatch, handleClose], | ||
); | ||
return ( | ||
<> | ||
<Tooltip title="Move"> | ||
<IconButton onClick={handleOpen}> | ||
<DriveFileMoveIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
<Dialog | ||
component="form" | ||
onSubmit={handleSubmit(onSubmit)} | ||
open={open} | ||
onClose={handleClose} | ||
fullWidth | ||
sx={{ | ||
height: '500px', | ||
'& .MuiDialog-paper': { | ||
backgroundColor: (theme) => theme.palette.background.paper + 'a0', | ||
backdropFilter: 'blur(20px)', | ||
}, | ||
}} | ||
> | ||
<DialogTitle>Move Folder</DialogTitle> | ||
<DialogContent> | ||
<FormLabel sx={{ display: 'block' }}>Parent Folder :</FormLabel> | ||
<Controller | ||
control={control} | ||
name="parentId" | ||
render={({ field }) => <FolderSelect {...field} disabledFolderIds={[folder.id]} />} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button variant="text" type="submit"> | ||
Move | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/ChatGPT/src/features/Home/FolderDetail/components/FolderHeader/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Box, IconButton, Typography } from '@mui/material'; | ||
import { useCallback } from 'react'; | ||
import { useAppDispatch } from '@chatgpt/app/hooks'; | ||
import { fetchConversations } from '@chatgpt/features/Conversations/conversationSlice'; | ||
import { Folder } from '@chatgpt/types/folder'; | ||
import { Delete } from '@mui/icons-material'; | ||
import { deleteFolder } from '@chatgpt/service/chat'; | ||
import UpdateFolder from './UpdateFolder'; | ||
import MoveFolder from './MoveFolder'; | ||
export interface FolderHeaderProps { | ||
folder: Folder; | ||
} | ||
|
||
export default function FolderHeader({ folder }: FolderHeaderProps) { | ||
const dispatch = useAppDispatch(); | ||
const handleDelete = useCallback(async () => { | ||
await deleteFolder({ id: folder.id }); | ||
dispatch(fetchConversations()); | ||
}, [dispatch, folder.id]); | ||
|
||
return ( | ||
<Box | ||
data-tauri-drag-region | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
p: 1, | ||
justifyContent: 'center', | ||
boxShadow: (theme) => theme.shadows[3].split(',0px')[0], | ||
}} | ||
> | ||
<Box sx={{ flexGrow: 1, display: 'flex', alignItems: 'center', ml: 1 }} data-tauri-drag-region> | ||
<Typography data-tauri-drag-region variant="h6" component="span" paragraph={false}> | ||
{folder.name} | ||
</Typography> | ||
<Typography | ||
sx={{ ml: 1 }} | ||
data-tauri-drag-region | ||
variant="body2" | ||
color="inherit" | ||
component="span" | ||
paragraph={false} | ||
> | ||
{folder.path} | ||
</Typography> | ||
</Box> | ||
<UpdateFolder folder={folder} /> | ||
<IconButton onClick={handleDelete}> | ||
<Delete /> | ||
</IconButton> | ||
<MoveFolder folder={folder} /> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.