From 1ba23b3d6507884ec475c2db6694c3460ee172d3 Mon Sep 17 00:00:00 2001 From: joseplayero Date: Wed, 21 Aug 2024 23:35:42 +0100 Subject: [PATCH 1/2] fix merge on absolute path issue --- src/components/Chat/Chat.tsx | 14 +++++++------- src/components/Common/TitleBar.tsx | 2 +- src/components/File/NewNote.tsx | 5 +++-- src/components/File/hooks/use-file-by-filepath.ts | 6 +++--- src/components/MainPage.tsx | 8 ++++---- src/components/Sidebars/IconsSidebar.tsx | 2 +- src/components/Sidebars/SimilarFilesSidebar.tsx | 2 +- src/components/Tabs/TabBar.tsx | 2 +- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/components/Chat/Chat.tsx b/src/components/Chat/Chat.tsx index 90ad3b30..2eba5bbd 100644 --- a/src/components/Chat/Chat.tsx +++ b/src/components/Chat/Chat.tsx @@ -70,8 +70,8 @@ function anonymizeChatFiltersForPosthog(chatFilters: ChatFilters): AnonymizedCha interface ChatWithLLMProps { vaultDirectory: string - openFileByPath: (path: string) => Promise - openAbsolutePath: (path: string, optionalContentToWriteOnCreate?: string) => void + openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => Promise + // openAbsolutePath: (path: string, optionalContentToWriteOnCreate?: string) => void currentChatHistory: ChatHistory | undefined setCurrentChatHistory: React.Dispatch> @@ -82,8 +82,8 @@ interface ChatWithLLMProps { const ChatWithLLM: React.FC = ({ vaultDirectory, - openFileByPath, - openAbsolutePath, + openFileAndOpenEditor, + // openAbsolutePath, currentChatHistory, setCurrentChatHistory, showSimilarFiles, @@ -277,8 +277,8 @@ const ChatWithLLM: React.FC = ({ 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)) + // openFileByPath(title) } return ( @@ -380,7 +380,7 @@ const ChatWithLLM: React.FC = ({ similarEntries={currentContext} titleText="Context used in chat" onFileSelect={(path: string) => { - openFileByPath(path) + openFileAndOpenEditor(path) posthog.capture('open_file_from_chat_context') }} saveCurrentFile={() => Promise.resolve()} diff --git a/src/components/Common/TitleBar.tsx b/src/components/Common/TitleBar.tsx index fb6de0ba..93ad0679 100644 --- a/src/components/Common/TitleBar.tsx +++ b/src/components/Common/TitleBar.tsx @@ -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 = ({ diff --git a/src/components/File/NewNote.tsx b/src/components/File/NewNote.tsx index 382b8257..7535e9ff 100644 --- a/src/components/File/NewNote.tsx +++ b/src/components/File/NewNote.tsx @@ -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 } @@ -52,7 +52,8 @@ const NewNoteComponent: React.FC = ({ 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() } diff --git a/src/components/File/hooks/use-file-by-filepath.ts b/src/components/File/hooks/use-file-by-filepath.ts index 114526a6..a9fccb02 100644 --- a/src/components/File/hooks/use-file-by-filepath.ts +++ b/src/components/File/hooks/use-file-by-filepath.ts @@ -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' @@ -87,8 +87,8 @@ const useFileByFilepath = () => { const fileExists = await window.fileSystem.checkFileExists(absolutePath) if (!fileExists) { - const basename = await window.path.basename(absolutePath) - const content = optionalContent || `## ${removeFileExtension(basename)}\n` + // const basename = await window.path.basename(absolutePath) + const content = optionalContent || `` // ## ${removeFileExtension(basename)}\n await window.fileSystem.createFile(absolutePath, content) setNeedToIndexEditorContent(true) } diff --git a/src/components/MainPage.tsx b/src/components/MainPage.tsx index 6c0b6192..d4b85c0c 100644 --- a/src/components/MainPage.tsx +++ b/src/components/MainPage.tsx @@ -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) => { @@ -259,8 +259,8 @@ const MainPageComponent: React.FC = () => {
void + openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => void sidebarShowing: SidebarAbleToShow makeSidebarShow: (show: SidebarAbleToShow) => void currentFilePath: string | null diff --git a/src/components/Sidebars/SimilarFilesSidebar.tsx b/src/components/Sidebars/SimilarFilesSidebar.tsx index f02821bb..1e0882e2 100644 --- a/src/components/Sidebars/SimilarFilesSidebar.tsx +++ b/src/components/Sidebars/SimilarFilesSidebar.tsx @@ -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 } diff --git a/src/components/Tabs/TabBar.tsx b/src/components/Tabs/TabBar.tsx index fd964c44..01d841fc 100644 --- a/src/components/Tabs/TabBar.tsx +++ b/src/components/Tabs/TabBar.tsx @@ -43,7 +43,7 @@ const Tooltip: React.FC = ({ filepath, position }) => { interface DraggableTabsProps { currentTab: string openTabContent: (path: string) => void - openFileAndOpenEditor: (path: string) => void + openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => void } const DraggableTabs: React.FC = ({ currentTab, openTabContent, openFileAndOpenEditor }) => { From dcf4fe7f92e5f07c505ba31019c9f06bd1eda072 Mon Sep 17 00:00:00 2001 From: joseplayero Date: Wed, 21 Aug 2024 23:38:14 +0100 Subject: [PATCH 2/2] minor cleanup --- src/components/Chat/Chat.tsx | 4 ---- src/components/File/hooks/use-file-by-filepath.ts | 4 +--- src/components/MainPage.tsx | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/Chat/Chat.tsx b/src/components/Chat/Chat.tsx index 2eba5bbd..74b22f74 100644 --- a/src/components/Chat/Chat.tsx +++ b/src/components/Chat/Chat.tsx @@ -71,8 +71,6 @@ function anonymizeChatFiltersForPosthog(chatFilters: ChatFilters): AnonymizedCha interface ChatWithLLMProps { vaultDirectory: string openFileAndOpenEditor: (path: string, optionalContentToWriteOnCreate?: string) => Promise - // openAbsolutePath: (path: string, optionalContentToWriteOnCreate?: string) => void - currentChatHistory: ChatHistory | undefined setCurrentChatHistory: React.Dispatch> showSimilarFiles: boolean @@ -83,7 +81,6 @@ interface ChatWithLLMProps { const ChatWithLLM: React.FC = ({ vaultDirectory, openFileAndOpenEditor, - // openAbsolutePath, currentChatHistory, setCurrentChatHistory, showSimilarFiles, @@ -278,7 +275,6 @@ const ChatWithLLM: React.FC = ({ const createNewNote = async (message: ChatMessageToDisplay) => { const title = `${(getDisplayMessage(message) ?? `${new Date().toDateString()}`).substring(0, 20)}...` openFileAndOpenEditor(title, getDisplayMessage(message)) - // openFileByPath(title) } return ( diff --git a/src/components/File/hooks/use-file-by-filepath.ts b/src/components/File/hooks/use-file-by-filepath.ts index a9fccb02..99296bb0 100644 --- a/src/components/File/hooks/use-file-by-filepath.ts +++ b/src/components/File/hooks/use-file-by-filepath.ts @@ -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) } diff --git a/src/components/MainPage.tsx b/src/components/MainPage.tsx index d4b85c0c..ce84f9df 100644 --- a/src/components/MainPage.tsx +++ b/src/components/MainPage.tsx @@ -260,7 +260,6 @@ const MainPageComponent: React.FC = () => {