Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Conversation Organization with Optimized Folder Structure #321

Merged
merged 13 commits into from
Jan 3, 2024
Prev Previous commit
Next Next commit
Refactor "Add Folder" button into a separate file
  • Loading branch information
joriskalz committed Jan 1, 2024
commit d0ac1d8e1a7c55582a55d579c7b4d351cbcd0b87
62 changes: 62 additions & 0 deletions src/apps/chat/components/applayout/folder/AddFolderButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 1,62 @@
import * as React from 'react';
import { useState } from 'react';
import { Box, IconButton, Input, Button } from '@mui/joy';
import AddIcon from '@mui/icons-material/Add';
import CloseIcon from '@mui/icons-material/Close';
import DoneIcon from '@mui/icons-material/Done';
import OutlineFolderIcon from '@mui/icons-material/Folder';
import { useFolderStore } from '~/common/state/store-folders';

export function AddFolderButton() {
const [isAddingFolder, setIsAddingFolder] = useState(false);
const [newFolderName, setNewFolderName] = useState('');

const { createFolder } = useFolderStore((state) => ({
createFolder: state.createFolder,
}));

const handleCreateFolder = () => {
if (newFolderName.trim() !== '') {
createFolder(newFolderName.trim());
setNewFolderName('');
setIsAddingFolder(false);
}
};

const handleCancelAddFolder = () => {
setNewFolderName('');
setIsAddingFolder(false);
};

return isAddingFolder ? (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<OutlineFolderIcon sx={{ ml: '13px' }} />
<Input
placeholder="Folder name"
value={newFolderName}
onChange={(e) => setNewFolderName(e.target.value)}
onKeyPress={(e) => {
if (e.key === 'Enter') handleCreateFolder();
}}
autoFocus
sx={{ ml: '0px' }}
/>
<IconButton color="success" onClick={handleCreateFolder}>
<DoneIcon />
</IconButton>
<IconButton color="danger" onClick={handleCancelAddFolder}>
<CloseIcon />
</IconButton>
</Box>
) : (
<Button
color="primary"
variant="plain"
startDecorator={<AddIcon />}
sx={{ display: 'flex', justifyContent: 'flex-start' }}
onClick={() => setIsAddingFolder(true)}
>
New folder
</Button>
);
}
64 changes: 2 additions & 62 deletions src/apps/chat/components/applayout/folder/ChatFolderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 2,27 @@ import * as React from 'react';

import Sheet, { sheetClasses } from '@mui/joy/Sheet';
import Typography from '@mui/joy/Typography';
import { Box, Button, IconButton, Input } from '@mui/joy';

import { DFolder, useFolderStore } from '~/common/state/store-folders';
import { DConversation } from '~/common/state/store-chats';
import { useState } from 'react';


import AddIcon from '@mui/icons-material/Add';
import CloseIcon from '@mui/icons-material/Close';
import DoneIcon from '@mui/icons-material/Done';
import OutlineFolderIcon from '@mui/icons-material/Folder';
import { AddFolderButton } from './AddFolderButton';


export function ChatFolderList() {
// local state
const [isAddingFolder, setIsAddingFolder] = useState(false);
const [newFolderName, setNewFolderName] = useState('');

// external state

// Get the createFolder action from the store
const { createFolder } = useFolderStore((state) => ({
createFolder: state.createFolder,
}));


// handlers

// Handler to create a new folder
const handleCreateFolder = () => {
// check min length
if (newFolderName.trim() !== '') {
createFolder(newFolderName.trim());
setNewFolderName('');
setIsAddingFolder(false);
}
};

// Handler to cancel adding a new folder
const handleCancelAddFolder = () => {
setNewFolderName('');
setIsAddingFolder(false);
};

return (
<Sheet variant="soft" sx={{ width: 343, p: 2, borderRadius: 'sm' }}>
<Typography level="h3" fontSize="xl" fontWeight="xl" mb={1}>
Folders
</Typography>
<div>Folder List</div>
{isAddingFolder ? (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<OutlineFolderIcon sx={{ ml: '13px' }} />
<Input
placeholder="Folder name"
value={newFolderName}
onChange={(e) => setNewFolderName(e.target.value)}
onKeyPress={(e) => {
if (e.key === 'Enter') handleCreateFolder();
}}
autoFocus
sx={{ ml: '0px' }}
/>
<IconButton color="success" onClick={handleCreateFolder}>
<DoneIcon />
</IconButton>
<IconButton color="danger" onClick={handleCancelAddFolder}>
<CloseIcon />
</IconButton>
</Box>
) : (
<Button
color="primary"
variant="plain"
startDecorator={<AddIcon />}
sx={{ display: 'flex', justifyContent: 'flex-start' }}
onClick={() => setIsAddingFolder(true)}
>
New folder
</Button>
)}
<AddFolderButton />
</Sheet>
);
}