From 74142d778cc1cfb7bd37e4bcd203c41eae11e462 Mon Sep 17 00:00:00 2001 From: samlhuillier Date: Thu, 17 Oct 2024 08:14:25 -0600 Subject: [PATCH 1/3] migrate new directory to dialog --- electron/main/index.ts | 8 ++- src/components/Common/CommonModals.tsx | 4 -- src/components/Common/EmptyPage.tsx | 7 ++- src/components/File/NewDirectory.tsx | 62 ++++++++----------- .../Sidebars/FileSideBar/FileItemRows.tsx | 2 +- src/components/Sidebars/IconsSidebar.tsx | 10 ++- src/contexts/ModalContext.tsx | 18 +----- 7 files changed, 46 insertions(+), 65 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 61e81619..4c5245c9 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -15,9 +15,11 @@ import { ollamaService, registerLLMSessionHandlers } from './llm/ipcHandlers' import registerPathHandlers from './path/ipcHandlers' import { registerDBSessionHandlers } from './vector-database/ipcHandlers' -Sentry.init({ - dsn: 'https://a764a6135d25ba91f0b25c0252be52f3@o4507840138903552.ingest.us.sentry.io/4507840140410880', -}) +if (process.env.NODE_ENV === 'production') { + Sentry.init({ + dsn: 'https://a764a6135d25ba91f0b25c0252be52f3@o4507840138903552.ingest.us.sentry.io/4507840140410880', + }) +} const store = new Store() // store.clear() // clear store for testing CAUTION: THIS WILL DELETE YOUR CHAT HISTORY diff --git a/src/components/Common/CommonModals.tsx b/src/components/Common/CommonModals.tsx index 200b01d7..c079c52d 100644 --- a/src/components/Common/CommonModals.tsx +++ b/src/components/Common/CommonModals.tsx @@ -6,12 +6,9 @@ import FlashcardMenuModal from '../Flashcard/FlashcardMenuModal' import { useFileContext } from '@/contexts/FileContext' import RenameNoteModal from '../File/RenameNote' import RenameDirModal from '../File/RenameDirectory' -import NewDirectoryComponent from '../File/NewDirectory' const CommonModals: React.FC = () => { const { - isNewDirectoryModalOpen, - setIsNewDirectoryModalOpen, isSettingsModalOpen, setIsSettingsModalOpen, isFlashcardModeOpen, @@ -26,7 +23,6 @@ const CommonModals: React.FC = () => { return (
- setIsNewDirectoryModalOpen(false)} />{' '} {noteToBeRenamed && } {fileDirToBeRenamed && } setIsSettingsModalOpen(false)} /> diff --git a/src/components/Common/EmptyPage.tsx b/src/components/Common/EmptyPage.tsx index be767ab4..b684106b 100644 --- a/src/components/Common/EmptyPage.tsx +++ b/src/components/Common/EmptyPage.tsx @@ -1,10 +1,10 @@ -import React from 'react' +import React, { useState } from 'react' import { ImFileEmpty } from 'react-icons/im' -import { useModalOpeners } from '../../contexts/ModalContext' import { useContentContext } from '@/contexts/ContentContext' +import NewDirectoryComponent from '../File/NewDirectory' const EmptyPage: React.FC = () => { - const { setIsNewDirectoryModalOpen } = useModalOpeners() + const [isNewDirectoryModalOpen, setIsNewDirectoryModalOpen] = useState(false) const { createUntitledNote } = useContentContext() return ( @@ -29,6 +29,7 @@ const EmptyPage: React.FC = () => { > Create a Folder +
) diff --git a/src/components/File/NewDirectory.tsx b/src/components/File/NewDirectory.tsx index 8ac15922..c034d988 100644 --- a/src/components/File/NewDirectory.tsx +++ b/src/components/File/NewDirectory.tsx @@ -1,19 +1,18 @@ import React, { useEffect, useState } from 'react' - -import { Button } from '@material-tailwind/react' import posthog from 'posthog-js' - -import ReorModal from '../Common/Modal' +import { Button } from '@/components/ui/button' +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' +import { Input } from '@/components/ui/input' import { getInvalidCharacterInFileName } from '@/lib/file' import { useFileContext } from '@/contexts/FileContext' interface NewDirectoryComponentProps { isOpen: boolean - onClose: () => void + onOpenChange: (open: boolean) => void parentDirectoryPath?: string } -const NewDirectoryComponent: React.FC = ({ isOpen, onClose, parentDirectoryPath }) => { +const NewDirectoryComponent: React.FC = ({ isOpen, onOpenChange, parentDirectoryPath }) => { const [directoryName, setDirectoryName] = useState('') const [errorMessage, setErrorMessage] = useState(null) @@ -59,40 +58,33 @@ const NewDirectoryComponent: React.FC = ({ isOpen, o const finalPath = await window.path.join(directoryPath, directoryName) window.fileSystem.createDirectory(finalPath) posthog.capture('created_new_directory_from_new_directory_modal') - onClose() + onOpenChange(false) } return ( - -
-

New Directory

- ) => { - if (e.key === 'Enter') { - sendNewDirectoryMsg() - } - }} - placeholder="Directory Name" - // eslint-disable-next-line jsx-a11y/no-autofocus - autoFocus - /> - -
- + + + + New Directory + +
+ ) => { + if (e.key === 'Enter') { + sendNewDirectoryMsg() + } + }} + placeholder="Directory Name" + autoFocus + /> {errorMessage &&

{errorMessage}

} +
-
- + + ) } diff --git a/src/components/Sidebars/FileSideBar/FileItemRows.tsx b/src/components/Sidebars/FileSideBar/FileItemRows.tsx index 22cd72a3..617113c5 100644 --- a/src/components/Sidebars/FileSideBar/FileItemRows.tsx +++ b/src/components/Sidebars/FileSideBar/FileItemRows.tsx @@ -111,7 +111,7 @@ const FileItemRows: React.FC = ({ index, style, data })
setIsNewDirectoryModalOpen(false)} + onOpenChange={setIsNewDirectoryModalOpen} parentDirectoryPath={parentDirectoryPathForNewDirectory} /> diff --git a/src/components/Sidebars/IconsSidebar.tsx b/src/components/Sidebars/IconsSidebar.tsx index d2c2776a..497b8292 100644 --- a/src/components/Sidebars/IconsSidebar.tsx +++ b/src/components/Sidebars/IconsSidebar.tsx @@ -11,13 +11,14 @@ import { HiOutlinePencilAlt } from 'react-icons/hi' import { useModalOpeners } from '../../contexts/ModalContext' import { useChatContext } from '@/contexts/ChatContext' import { useContentContext } from '@/contexts/ContentContext' +import NewDirectoryComponent from '../File/NewDirectory' const IconsSidebar: React.FC = () => { const { sidebarShowing, setSidebarShowing } = useChatContext() const [sidebarWidth, setSidebarWidth] = useState(40) + const [isNewDirectoryModalOpen, setIsNewDirectoryModalOpen] = useState(false) - const { setIsNewDirectoryModalOpen, isSettingsModalOpen, setIsSettingsModalOpen, setIsFlashcardModeOpen } = - useModalOpeners() + const { isSettingsModalOpen, setIsSettingsModalOpen, setIsFlashcardModeOpen } = useModalOpeners() const { createUntitledNote } = useContentContext() useEffect(() => { @@ -119,6 +120,11 @@ const IconsSidebar: React.FC = () => { > + ) } diff --git a/src/contexts/ModalContext.tsx b/src/contexts/ModalContext.tsx index a4a072c7..fa099133 100644 --- a/src/contexts/ModalContext.tsx +++ b/src/contexts/ModalContext.tsx @@ -8,8 +8,6 @@ interface ModalProviderProps { * Every modal requires a setter and opener */ interface ModalOpenContextType { - isNewDirectoryModalOpen: boolean - setIsNewDirectoryModalOpen: (newDir: boolean) => void isSettingsModalOpen: boolean setIsSettingsModalOpen: (settingsOpen: boolean) => void isFlashcardModeOpen: boolean @@ -31,7 +29,6 @@ export const useModalOpeners = (): ModalOpenContextType => { } export const ModalProvider: React.FC = ({ children }) => { - const [isNewDirectoryModalOpen, setIsNewDirectoryModalOpen] = useState(false) const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false) const [isFlashcardModeOpen, setIsFlashcardModeOpen] = useState(false) const [initialFileToCreateFlashcard, setInitialFileToCreateFlashcard] = useState('') @@ -51,15 +48,8 @@ export const ModalProvider: React.FC = ({ children }) => { } }, [setIsFlashcardModeOpen, setInitialFileToCreateFlashcard]) - // const renameDirectory = useCallback((parentDirectory?: string) => { - // setIsNewDirectoryModalOpen(true) - // setInitialFileToCreateFlashcard(parentDirectory) - // }, []) - const modalOpenContextValue = useMemo( () => ({ - isNewDirectoryModalOpen, - setIsNewDirectoryModalOpen, isSettingsModalOpen, setIsSettingsModalOpen, isFlashcardModeOpen, @@ -69,13 +59,7 @@ export const ModalProvider: React.FC = ({ children }) => { initialFileToReviewFlashcard, setInitialFileToReviewFlashcard, }), - [ - isNewDirectoryModalOpen, - isSettingsModalOpen, - isFlashcardModeOpen, - initialFileToReviewFlashcard, - initialFileToCreateFlashcard, - ], + [isSettingsModalOpen, isFlashcardModeOpen, initialFileToReviewFlashcard, initialFileToCreateFlashcard], ) return {children} From 8e77886d7c6fb2aad895a0378d6bab15a039f255 Mon Sep 17 00:00:00 2001 From: samlhuillier Date: Thu, 17 Oct 2024 14:24:50 -0600 Subject: [PATCH 2/3] confirm delete file or dir --- .../Sidebars/FileSideBar/FileItemRows.tsx | 13 ++++++++++++- src/main.tsx | 10 ++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/Sidebars/FileSideBar/FileItemRows.tsx b/src/components/Sidebars/FileSideBar/FileItemRows.tsx index 617113c5..11e91e63 100644 --- a/src/components/Sidebars/FileSideBar/FileItemRows.tsx +++ b/src/components/Sidebars/FileSideBar/FileItemRows.tsx @@ -71,6 +71,17 @@ const FileItemRows: React.FC = ({ index, style, data }) setIsNewDirectoryModalOpen(true) }, [file.path, isDirectory]) + const handleDelete = useCallback(() => { + const itemType = isDirectory ? 'directory' : 'file' + const confirmMessage = `Are you sure you want to delete this ${itemType}?${ + isDirectory ? ' This will delete all contents of the directory.' : '' + }` + + if (window.confirm(confirmMessage)) { + deleteFile(file.path) + } + }, [deleteFile, file.path, isDirectory]) + const itemClasses = `flex items-center cursor-pointer px-2 py-1 border-b border-gray-200 hover:bg-neutral-700 h-full mt-0 mb-0 text-cyan-100 font-sans text-xs leading-relaxed rounded-md ${ isSelected ? 'bg-neutral-700 text-white font-semibold' : 'text-gray-200' } ${isDragOver ? 'bg-neutral-500' : ''}` @@ -82,7 +93,7 @@ const FileItemRows: React.FC = ({ index, style, data }) New Folder setNoteToBeRenamed(file.path)}>Rename - deleteFile(file.path)}>Delete + Delete ) diff --git a/src/main.tsx b/src/main.tsx index 838100d8..61421556 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,16 +1,18 @@ import React from 'react' import ReactDOM from 'react-dom/client' -import { toast } from 'react-toastify' import * as Sentry from '@sentry/electron/renderer' +import { toast } from 'react-toastify' import App from './App' import './styles/global.css' import errorToStringRendererProcess from './lib/error' -Sentry.init({ - integrations: [], -}) +if (process.env.NODE_ENV === 'production') { + Sentry.init({ + integrations: [], + }) +} window.addEventListener('error', (event) => { event.preventDefault() From fa25e21042b3837b1e4fe6fb577c3898787ea114 Mon Sep 17 00:00:00 2001 From: samlhuillier Date: Thu, 17 Oct 2024 14:46:44 -0600 Subject: [PATCH 3/3] confirm delete chat --- src/components/Chat/ChatSidebar.tsx | 10 ++- src/components/Common/EmptyPage.tsx | 2 +- src/components/File/NewDirectory.tsx | 62 +++++++++++-------- .../Sidebars/FileSideBar/FileItemRows.tsx | 2 +- src/components/Sidebars/IconsSidebar.tsx | 2 +- 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/components/Chat/ChatSidebar.tsx b/src/components/Chat/ChatSidebar.tsx index cfbbf0e2..29aacf47 100644 --- a/src/components/Chat/ChatSidebar.tsx +++ b/src/components/Chat/ChatSidebar.tsx @@ -19,6 +19,14 @@ export const ChatItem: React.FC = ({ chatMetadata }) => { transition-colors duration-150 ease-in-out ${chatMetadata.id === currentChat?.id ? 'bg-neutral-700 text-white' : 'text-gray-300 hover:bg-neutral-800'} ` + + const handleDeleteChat = () => { + const isConfirmed = window.confirm(`Are you sure you want to delete the chat "${chatMetadata.displayName}"?`) + if (isConfirmed) { + deleteChat(chatMetadata.id) + } + } + return ( @@ -28,7 +36,7 @@ export const ChatItem: React.FC = ({ chatMetadata }) => { - deleteChat(chatMetadata.id)}>Delete Chat + Delete Chat ) diff --git a/src/components/Common/EmptyPage.tsx b/src/components/Common/EmptyPage.tsx index b684106b..02bc7e95 100644 --- a/src/components/Common/EmptyPage.tsx +++ b/src/components/Common/EmptyPage.tsx @@ -29,7 +29,7 @@ const EmptyPage: React.FC = () => { > Create a Folder - + setIsNewDirectoryModalOpen(false)} /> ) diff --git a/src/components/File/NewDirectory.tsx b/src/components/File/NewDirectory.tsx index c034d988..8ac15922 100644 --- a/src/components/File/NewDirectory.tsx +++ b/src/components/File/NewDirectory.tsx @@ -1,18 +1,19 @@ import React, { useEffect, useState } from 'react' + +import { Button } from '@material-tailwind/react' import posthog from 'posthog-js' -import { Button } from '@/components/ui/button' -import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' -import { Input } from '@/components/ui/input' + +import ReorModal from '../Common/Modal' import { getInvalidCharacterInFileName } from '@/lib/file' import { useFileContext } from '@/contexts/FileContext' interface NewDirectoryComponentProps { isOpen: boolean - onOpenChange: (open: boolean) => void + onClose: () => void parentDirectoryPath?: string } -const NewDirectoryComponent: React.FC = ({ isOpen, onOpenChange, parentDirectoryPath }) => { +const NewDirectoryComponent: React.FC = ({ isOpen, onClose, parentDirectoryPath }) => { const [directoryName, setDirectoryName] = useState('') const [errorMessage, setErrorMessage] = useState(null) @@ -58,33 +59,40 @@ const NewDirectoryComponent: React.FC = ({ isOpen, o const finalPath = await window.path.join(directoryPath, directoryName) window.fileSystem.createDirectory(finalPath) posthog.capture('created_new_directory_from_new_directory_modal') - onOpenChange(false) + onClose() } return ( - - - - New Directory - -
- ) => { - if (e.key === 'Enter') { - sendNewDirectoryMsg() - } - }} - placeholder="Directory Name" - autoFocus - /> + +
+

New Directory

+ ) => { + if (e.key === 'Enter') { + sendNewDirectoryMsg() + } + }} + placeholder="Directory Name" + // eslint-disable-next-line jsx-a11y/no-autofocus + autoFocus + /> + +
+ {errorMessage &&

{errorMessage}

} -
- -
+ +
) } diff --git a/src/components/Sidebars/FileSideBar/FileItemRows.tsx b/src/components/Sidebars/FileSideBar/FileItemRows.tsx index 11e91e63..53717bc5 100644 --- a/src/components/Sidebars/FileSideBar/FileItemRows.tsx +++ b/src/components/Sidebars/FileSideBar/FileItemRows.tsx @@ -122,7 +122,7 @@ const FileItemRows: React.FC = ({ index, style, data }) setIsNewDirectoryModalOpen(false)} parentDirectoryPath={parentDirectoryPathForNewDirectory} /> diff --git a/src/components/Sidebars/IconsSidebar.tsx b/src/components/Sidebars/IconsSidebar.tsx index 497b8292..d9c0569b 100644 --- a/src/components/Sidebars/IconsSidebar.tsx +++ b/src/components/Sidebars/IconsSidebar.tsx @@ -122,7 +122,7 @@ const IconsSidebar: React.FC = () => { setIsNewDirectoryModalOpen(false)} // parentDirectoryPath={parentDirectoryPathForNewDirectory} />