Skip to content

Commit

Permalink
Merge pull request #368 from reorproject/fix-absolute-path
Browse files Browse the repository at this point in the history
Fix builds for absolute path issue again
  • Loading branch information
joseplayero authored Aug 21, 2024
2 parents 3e7b116 + dcf4fe7 commit 411d561
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 22 deletions.
12 changes: 4 additions & 8 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ function anonymizeChatFiltersForPosthog(chatFilters: ChatFilters): AnonymizedCha

interface ChatWithLLMProps {
vaultDirectory: string
openFileByPath: (path: string) => Promise<void>
openAbsolutePath: (path: string, optionalContentToWriteOnCreate?: string) => void

openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => Promise<void>
currentChatHistory: ChatHistory | undefined
setCurrentChatHistory: React.Dispatch<React.SetStateAction<ChatHistory | undefined>>
showSimilarFiles: boolean
Expand All @@ -82,8 +80,7 @@ interface ChatWithLLMProps {

const ChatWithLLM: React.FC<ChatWithLLMProps> = ({
vaultDirectory,
openFileByPath,
openAbsolutePath,
openFileAndOpenEditor,
currentChatHistory,
setCurrentChatHistory,
showSimilarFiles,
Expand Down Expand Up @@ -277,8 +274,7 @@ const ChatWithLLM: React.FC<ChatWithLLMProps> = ({

const createNewNote = async (message: ChatMessageToDisplay) => {
const title = `${(getDisplayMessage(message) ?? `${new Date().toDateString()}`).substring(0, 20)}...`
openAbsolutePath(title, getDisplayMessage(message))
openFileByPath(title)
openFileAndOpenEditor(title, getDisplayMessage(message))
}

return (
Expand Down Expand Up @@ -380,7 +376,7 @@ const ChatWithLLM: React.FC<ChatWithLLMProps> = ({
similarEntries={currentContext}
titleText="Context used in chat"
onFileSelect={(path: string) => {
openFileByPath(path)
openFileAndOpenEditor(path)
posthog.capture('open_file_from_chat_context')
}}
saveCurrentFile={() => Promise.resolve()}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/TitleBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface TitleBarProps {
toggleSimilarFiles: () => void
history: string[]
setHistory: (string: string[]) => void
openFileAndOpenEditor: (path: string) => void
openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => void
}

const TitleBar: React.FC<TitleBarProps> = ({
Expand Down
5 changes: 3 additions & 2 deletions src/components/File/NewNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getInvalidCharacterInFilePath } from '@/utils/strings'
interface NewNoteComponentProps {
isOpen: boolean
onClose: () => void
openFileAndOpenEditor: (path: string) => void
openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => void
currentOpenFilePath: string | null
}

Expand Down Expand Up @@ -52,7 +52,8 @@ const NewNoteComponent: React.FC<NewNoteComponentProps> = ({
const directoryName = await window.path.dirname(currentOpenFilePath)
finalPath = await window.path.join(directoryName, fileName)
}
openFileAndOpenEditor(finalPath)
const basename = await window.path.basename(finalPath)
openFileAndOpenEditor(finalPath, `# ${basename}\n`)
posthog.capture('created_new_note_from_new_note_modal')
onClose()
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/File/hooks/use-file-by-filepath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import StarterKit from '@tiptap/starter-kit'
import { toast } from 'react-toastify'
import { Markdown } from 'tiptap-markdown'
import { useDebounce } from 'use-debounce'
import { getInvalidCharacterInFilePath, removeFileExtension } from '@/utils/strings'
import { getInvalidCharacterInFilePath } from '@/utils/strings'

import { BacklinkExtension } from '@/components/Editor/BacklinkExtension'
import { SuggestionsState } from '@/components/Editor/BacklinkSuggestionsDisplay'
Expand Down Expand Up @@ -87,9 +87,7 @@ const useFileByFilepath = () => {

const fileExists = await window.fileSystem.checkFileExists(absolutePath)
if (!fileExists) {
const basename = await window.path.basename(absolutePath)
const content = optionalContent || `## ${removeFileExtension(basename)}\n`
await window.fileSystem.createFile(absolutePath, content)
await window.fileSystem.createFile(absolutePath, optionalContent || ``)
setNeedToIndexEditorContent(true)
}

Expand Down
7 changes: 3 additions & 4 deletions src/components/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ const MainPageComponent: React.FC = () => {
setCurrentChatHistory(chatHistory)
}

const openFileAndOpenEditor = async (path: string) => {
const openFileAndOpenEditor = async (path: string, optionalContentToWriteOnCreate?: string) => {
setShowChatbot(false)
setSidebarShowing('files')
openOrCreateFile(path)
openOrCreateFile(path, optionalContentToWriteOnCreate)
}

const openTabContent = async (path: string) => {
Expand Down Expand Up @@ -259,8 +259,7 @@ const MainPageComponent: React.FC = () => {
<div className="h-below-titlebar w-full">
<ChatWithLLM
vaultDirectory={vaultDirectory}
openFileByPath={openFileAndOpenEditor}
openAbsolutePath={openAbsolutePath}
openFileAndOpenEditor={openFileAndOpenEditor}
currentChatHistory={currentChatHistory}
setCurrentChatHistory={setCurrentChatHistory}
showSimilarFiles={showSimilarFiles} // This might need to be managed differently now
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebars/IconsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SidebarAbleToShow } from './MainSidebar'
import { useModalOpeners } from '../Providers/ModalProvider'

interface IconsSidebarProps {
openFileAndOpenEditor: (path: string) => void
openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => void
sidebarShowing: SidebarAbleToShow
makeSidebarShow: (show: SidebarAbleToShow) => void
currentFilePath: string | null
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebars/SimilarFilesSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import HighlightButton from './SemanticSidebar/HighlightButton'
interface SimilarFilesSidebarComponentProps {
filePath: string
highlightData: HighlightData
openFileAndOpenEditor: (filePath: string) => void
openFileAndOpenEditor: (filePath: string, optionalContentToWriteOnCreate?: string) => void

saveCurrentlyOpenedFile: () => Promise<void>
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tabs/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Tooltip: React.FC<TooltipProps> = ({ filepath, position }) => {
interface DraggableTabsProps {
currentTab: string
openTabContent: (path: string) => void
openFileAndOpenEditor: (path: string) => void
openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => void
}

const DraggableTabs: React.FC<DraggableTabsProps> = ({ currentTab, openTabContent, openFileAndOpenEditor }) => {
Expand Down

0 comments on commit 411d561

Please sign in to comment.