Skip to content

Commit

Permalink
Merge pull request #459 from reorproject/migrate-to-dialog
Browse files Browse the repository at this point in the history
migrate new directory to dialog
  • Loading branch information
samlhuillier authored Oct 17, 2024
2 parents 9c78aca + fa25e21 commit 9e0ce43
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 35 deletions.
8 changes: 5 additions & 3 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreSchema>()
// store.clear() // clear store for testing CAUTION: THIS WILL DELETE YOUR CHAT HISTORY
Expand Down
10 changes: 9 additions & 1 deletion src/components/Chat/ChatSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export const ChatItem: React.FC<ChatItemProps> = ({ 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}"?`)

Check warning on line 24 in src/components/Chat/ChatSidebar.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (macos-13)

Unexpected confirm

Check warning on line 24 in src/components/Chat/ChatSidebar.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (macos-latest)

Unexpected confirm

Check warning on line 24 in src/components/Chat/ChatSidebar.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (windows-latest)

Unexpected confirm

Check warning on line 24 in src/components/Chat/ChatSidebar.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (ubuntu-latest, x64)

Unexpected confirm
if (isConfirmed) {
deleteChat(chatMetadata.id)
}
}

return (
<ContextMenu>
<ContextMenuTrigger>
Expand All @@ -28,7 +36,7 @@ export const ChatItem: React.FC<ChatItemProps> = ({ chatMetadata }) => {
</div>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem onClick={() => deleteChat(chatMetadata.id)}>Delete Chat</ContextMenuItem>
<ContextMenuItem onClick={handleDeleteChat}>Delete Chat</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
)
Expand Down
4 changes: 0 additions & 4 deletions src/components/Common/CommonModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,7 +23,6 @@ const CommonModals: React.FC = () => {

return (
<div>
<NewDirectoryComponent isOpen={isNewDirectoryModalOpen} onClose={() => setIsNewDirectoryModalOpen(false)} />{' '}
{noteToBeRenamed && <RenameNoteModal />}
{fileDirToBeRenamed && <RenameDirModal />}
<SettingsModal isOpen={isSettingsModalOpen} onClose={() => setIsSettingsModalOpen(false)} />
Expand Down
7 changes: 4 additions & 3 deletions src/components/Common/EmptyPage.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -29,6 +29,7 @@ const EmptyPage: React.FC = () => {
>
Create a Folder
</button>
<NewDirectoryComponent isOpen={isNewDirectoryModalOpen} onClose={() => setIsNewDirectoryModalOpen(false)} />
</div>
</div>
)
Expand Down
13 changes: 12 additions & 1 deletion src/components/Sidebars/FileSideBar/FileItemRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ const FileItemRows: React.FC<ListChildComponentProps> = ({ 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)) {

Check warning on line 80 in src/components/Sidebars/FileSideBar/FileItemRows.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (macos-13)

Unexpected confirm

Check warning on line 80 in src/components/Sidebars/FileSideBar/FileItemRows.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (macos-latest)

Unexpected confirm

Check warning on line 80 in src/components/Sidebars/FileSideBar/FileItemRows.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (windows-latest)

Unexpected confirm

Check warning on line 80 in src/components/Sidebars/FileSideBar/FileItemRows.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (ubuntu-latest, x64)

Unexpected confirm
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' : ''}`
Expand All @@ -82,7 +93,7 @@ const FileItemRows: React.FC<ListChildComponentProps> = ({ index, style, data })
</ContextMenuItem>
<ContextMenuItem onClick={openNewDirectoryModal}>New Folder</ContextMenuItem>
<ContextMenuItem onClick={() => setNoteToBeRenamed(file.path)}>Rename</ContextMenuItem>
<ContextMenuItem onClick={() => deleteFile(file.path)}>Delete</ContextMenuItem>
<ContextMenuItem onClick={handleDelete}>Delete</ContextMenuItem>
</>
)

Expand Down
10 changes: 8 additions & 2 deletions src/components/Sidebars/IconsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(40)
const [isNewDirectoryModalOpen, setIsNewDirectoryModalOpen] = useState(false)

const { setIsNewDirectoryModalOpen, isSettingsModalOpen, setIsSettingsModalOpen, setIsFlashcardModeOpen } =
useModalOpeners()
const { isSettingsModalOpen, setIsSettingsModalOpen, setIsFlashcardModeOpen } = useModalOpeners()
const { createUntitledNote } = useContentContext()

useEffect(() => {
Expand Down Expand Up @@ -119,6 +120,11 @@ const IconsSidebar: React.FC = () => {
>
<MdSettings color="gray" size={18} className="mb-3 size-6 text-gray-100" title="Settings" />
</button>
<NewDirectoryComponent
isOpen={isNewDirectoryModalOpen}
onClose={() => setIsNewDirectoryModalOpen(false)}
// parentDirectoryPath={parentDirectoryPathForNewDirectory}
/>
</div>
)
}
Expand Down
18 changes: 1 addition & 17 deletions src/contexts/ModalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +29,6 @@ export const useModalOpeners = (): ModalOpenContextType => {
}

export const ModalProvider: React.FC<ModalProviderProps> = ({ children }) => {
const [isNewDirectoryModalOpen, setIsNewDirectoryModalOpen] = useState(false)
const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false)
const [isFlashcardModeOpen, setIsFlashcardModeOpen] = useState(false)
const [initialFileToCreateFlashcard, setInitialFileToCreateFlashcard] = useState('')
Expand All @@ -51,15 +48,8 @@ export const ModalProvider: React.FC<ModalProviderProps> = ({ children }) => {
}
}, [setIsFlashcardModeOpen, setInitialFileToCreateFlashcard])

// const renameDirectory = useCallback((parentDirectory?: string) => {
// setIsNewDirectoryModalOpen(true)
// setInitialFileToCreateFlashcard(parentDirectory)
// }, [])

const modalOpenContextValue = useMemo(
() => ({
isNewDirectoryModalOpen,
setIsNewDirectoryModalOpen,
isSettingsModalOpen,
setIsSettingsModalOpen,
isFlashcardModeOpen,
Expand All @@ -69,13 +59,7 @@ export const ModalProvider: React.FC<ModalProviderProps> = ({ children }) => {
initialFileToReviewFlashcard,
setInitialFileToReviewFlashcard,
}),
[
isNewDirectoryModalOpen,
isSettingsModalOpen,
isFlashcardModeOpen,
initialFileToReviewFlashcard,
initialFileToCreateFlashcard,
],
[isSettingsModalOpen, isFlashcardModeOpen, initialFileToReviewFlashcard, initialFileToCreateFlashcard],
)

return <ModalContext.Provider value={modalOpenContextValue}>{children}</ModalContext.Provider>
Expand Down
10 changes: 6 additions & 4 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 9e0ce43

Please sign in to comment.