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
Add folder selector
  • Loading branch information
joriskalz committed Jan 1, 2024
commit c90139923c11f75ff1412f1e47497776c34322cc
5 changes: 5 additions & 0 deletions src/apps/chat/components/applayout/ChatDropdowns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 8,7 @@ import { useUXLabsStore } from '~/common/state/store-ux-labs';

import { useChatLLMDropdown } from './useLLMDropdown';
import { usePersonaIdDropdown } from './usePersonaDropdown';
import { useFolderDropdown } from './folder/useFolderDropdown';


export function ChatDropdowns(props: {
Expand All @@ -19,6 20,7 @@ export function ChatDropdowns(props: {
// state
const { chatLLMDropdown } = useChatLLMDropdown();
const { personaDropdown } = usePersonaIdDropdown(props.conversationId);
const { folderDropdown } = useFolderDropdown(props.conversationId);

// external state
const labsSplitBranching = useUXLabsStore(state => state.labsSplitBranching);
Expand All @@ -31,6 33,9 @@ export function ChatDropdowns(props: {
{/* Model selector */}
{chatLLMDropdown}

{/* Folder selector */}
{folderDropdown}

{/* Split Panes button */}
{labsSplitBranching && <IconButton
variant={props.isSplitPanes ? 'solid' : undefined}
Expand Down
50 changes: 50 additions & 0 deletions src/apps/chat/components/applayout/folder/useFolderDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 1,50 @@
import * as React from 'react';
import { shallow } from 'zustand/shallow';
import FolderIcon from '@mui/icons-material/Folder';
import { useFolderStore } from '~/common/state/store-folders';
import { DropdownItems, GoodDropdown } from '~/common/components/GoodDropdown';
import { DConversationId } from '~/common/state/store-chats';

export function useFolderDropdown(conversationId: DConversationId | null) {
// Get folders from the store
const folders = useFolderStore(state => state.folders);

// Prepare items for the dropdown
const folderItems: DropdownItems = folders.reduce((items, folder) => {
items[folder.id] = {
title: folder.title,
icon: <FolderIcon sx={{ color: folder.color }} />,
};
return items;
}, {} as DropdownItems);

// Handle folder change
const handleFolderChange = (_event: any, folderId: string | null) => {
if (conversationId && folderId) {
// Remove conversation from all folders
folders.forEach(folder => {
if (folder.conversationIds.includes(conversationId)) {
useFolderStore.getState().removeConversationFromFolder(folder.id, conversationId);
}
});
// Add conversation to the selected folder
useFolderStore.getState().addConversationToFolder(folderId, conversationId);
}
};

// Get the current folder ID for the selected conversation
const currentFolderId = folders.find(folder => folder.conversationIds.includes(conversationId || ''))?.id || null;

// Create the dropdown component
const folderDropdown = (
<GoodDropdown
items={folderItems}
value={currentFolderId}
onChange={handleFolderChange}
placeholder="Select a folder"
showSymbols={true}
/>
);

return { folderDropdown };
}
2 changes: 1 addition & 1 deletion src/common/components/GoodDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 80,7 @@ export function GoodDropdown<TValue extends string>(props: {

return (
<Option key={'key-' idx} value={key} sx={{ whiteSpace: 'nowrap' }}>
{props.showSymbols && <ListItemDecorator sx={{ fontSize: 'xl' }}>{item?.symbol ' '}</ListItemDecorator>}
{props.showSymbols && item?.symbol && <ListItemDecorator sx={{ fontSize: 'xl' }}>{item?.symbol ' '}</ListItemDecorator>}
{props.showSymbols && !!item.icon && <ListItemDecorator>{item?.icon}</ListItemDecorator>}
{item.title}
{/*{key === props.value && (*/}
Expand Down