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
Filter by selected folder
  • Loading branch information
joriskalz committed Jan 1, 2024
commit 1f1bf65c14e08920ea95cb84c9a9b16a344f5ed1
6 changes: 4 additions & 2 deletions src/apps/chat/components/applayout/ChatDrawerItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@ import AddIcon from '@mui/icons-material/Add';
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
import FileUploadIcon from '@mui/icons-material/FileUpload';

import { DConversationId, useChatStore } from '~/common/state/store-chats';
import { DConversationId, useChatStore, useConversationsByFolder } from '~/common/state/store-chats';
import { OpenAIIcon } from '~/common/components/icons/OpenAIIcon';
import { useOptimaDrawers } from '~/common/layout/optima/useOptimaDrawers';
import { useUIPreferencesStore } from '~/common/state/store-ui';
Expand Down Expand Up @@ -39,7 39,9 @@ function ChatDrawerItems(props: {

// external state
const { closeDrawer } = useOptimaDrawers();
const conversations = useChatStore(state => state.conversations, shallow);
//const conversations = useChatStore(state => state.conversations, shallow);
const conversations = useConversationsByFolder(selectedFolderId);

const showSymbols = useUIPreferencesStore(state => state.zenMode !== 'cleaner');
const labsEnhancedUI = useUXLabsStore(state => state.labsEnhancedUI);
const createFolder = useFolderStore((state) => state.createFolder);
Expand Down
12 changes: 12 additions & 0 deletions src/common/state/store-chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 8,7 @@ import { DLLMId, useModelsStore } from '~/modules/llms/store-llms';
import { countModelTokens } from '../util/token-counter';
import { defaultSystemPurposeId, SystemPurposeId } from '../../data';
import { IDB_MIGRATION_INITIAL, idbStateStorage } from '../util/idbUtils';
import { useFolderStore } from './store-folders';


export type DConversationId = string;
Expand Down Expand Up @@ -562,3 563,14 @@ export const useConversation = (conversationId: DConversationId | null) => useCh
setMessages: state.setMessages,
};
}, shallow);

export const useConversationsByFolder = (folderId: string | null) => useChatStore(state => {
if (folderId) {
const { conversations } = state;
const folder = useFolderStore.getState().folders.find(_f => _f.id === folderId);
if (folder)
return conversations.filter(_c => folder.conversationIds.includes(_c.id));
}
// return all conversations if all folder is selected
return state.conversations;
}, shallow);