diff --git a/package-lock.json b/package-lock.json index c59185c2..6fa1c8bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "reor-project", - "version": "0.2.26", + "version": "0.2.29", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "reor-project", - "version": "0.2.26", + "version": "0.2.29", "license": "AGPL-3.0", "dependencies": { "@aarkue/tiptap-math-extension": "^1.2.2", diff --git a/src/components/Editor/DocumentStats.tsx b/src/components/Editor/DocumentStats.tsx new file mode 100644 index 00000000..54720b15 --- /dev/null +++ b/src/components/Editor/DocumentStats.tsx @@ -0,0 +1,36 @@ +import React, { useEffect, useState } from 'react' +import { Editor } from '@tiptap/react' + +interface DocumentStatsProps { + editor: Editor | null +} + +const DocumentStats: React.FC = ({ editor }) => { + const [show, setShow] = useState(false) + + useEffect(() => { + const initDocumentStats = async () => { + const showStats = await window.electronStore.getDocumentStats() + setShow(showStats) + } + + initDocumentStats() + + const handleDocStatsChange = (event: Electron.IpcRendererEvent, value: boolean) => { + setShow(value) + } + + window.ipcRenderer.on('show-doc-stats-changed', handleDocStatsChange) + }, []) + + if (!editor || !show) return null + + return ( +
+
Characters: {editor.storage.characterCount.characters()}
+
Words: {editor.storage.characterCount.words()}
+
+ ) +} + +export default DocumentStats diff --git a/src/components/Editor/EditorManager.tsx b/src/components/Editor/EditorManager.tsx index e47db2ef..52ae374b 100644 --- a/src/components/Editor/EditorManager.tsx +++ b/src/components/Editor/EditorManager.tsx @@ -1,10 +1,9 @@ import React, { useEffect, useState } from 'react' import { EditorContent } from '@tiptap/react' -import InEditorBacklinkSuggestionsDisplay from './BacklinkSuggestionsDisplay' import EditorContextMenu from './EditorContextMenu' import SearchBar from './Search/SearchBar' import { useFileContext } from '@/contexts/FileContext' -import { useContentContext } from '@/contexts/ContentContext' +import DocumentStats from './DocumentStats' const EditorManager: React.FC = () => { const [showSearchBar, setShowSearchBar] = useState(false) @@ -12,9 +11,7 @@ const EditorManager: React.FC = () => { const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 }) const [editorFlex, setEditorFlex] = useState(true) - const { editor, suggestionsState, vaultFilesFlattened } = useFileContext() - const [showDocumentStats, setShowDocumentStats] = useState(false) - const { openContent } = useContentContext() + const { editor } = useFileContext() const handleContextMenu = (event: React.MouseEvent) => { event.preventDefault() @@ -29,15 +26,6 @@ const EditorManager: React.FC = () => { if (contextMenuVisible) setContextMenuVisible(false) } - const handleClick = (event: React.MouseEvent) => { - const { target } = event - if (target instanceof HTMLElement && target.getAttribute('data-backlink') === 'true') { - event.preventDefault() - const backlinkPath = target.textContent - if (backlinkPath) openContent(backlinkPath) - } - } - useEffect(() => { const initEditorContentCenter = async () => { const isCenter = await window.electronStore.getEditorFlexCenter() @@ -52,21 +40,6 @@ const EditorManager: React.FC = () => { window.ipcRenderer.on('editor-flex-center-changed', handleEditorChange) }, []) - useEffect(() => { - const initDocumentStats = async () => { - const showStats = await window.electronStore.getDocumentStats() - setShowDocumentStats(showStats) - } - - initDocumentStats() - - const handleDocStatsChange = (event: Electron.IpcRendererEvent, value: boolean) => { - setShowDocumentStats(value) - } - - window.ipcRenderer.on('show-doc-stats-changed', handleDocStatsChange) - }, []) - return (
{ /> )} -
+
{ wordBreak: 'break-word', }} onContextMenu={handleContextMenu} - onClick={handleClick} editor={editor} />
- {suggestionsState && ( - file.relativePath)} - /> - )} - {editor && showDocumentStats && ( -
-
Characters: {editor.storage.characterCount.characters()}
-
Words: {editor.storage.characterCount.words()}
-
- )} +
) } diff --git a/src/contexts/FileContext.tsx b/src/contexts/FileContext.tsx index 3480dc77..87a02965 100644 --- a/src/contexts/FileContext.tsx +++ b/src/contexts/FileContext.tsx @@ -28,7 +28,6 @@ import { getNextAvailableFileNameGivenBaseName, sortFilesAndDirectories, } from '@/lib/file' -import { SuggestionsState } from '@/components/Editor/BacklinkSuggestionsDisplay' import HighlightExtension, { HighlightData } from '@/components/Editor/HighlightExtension' import { RichTextLink } from '@/components/Editor/RichTextLink' import '@/styles/tiptap.scss' @@ -49,7 +48,6 @@ type FileContextType = { navigationHistory: string[] addToNavigationHistory: (value: string) => void openOrCreateFile: (filePath: string, optionalContentToWriteOnCreate?: string) => Promise - suggestionsState: SuggestionsState | null | undefined spellCheckEnabled: boolean highlightData: HighlightData noteToBeRenamed: string @@ -57,7 +55,6 @@ type FileContextType = { fileDirToBeRenamed: string setFileDirToBeRenamed: React.Dispatch> renameFile: (oldFilePath: string, newFilePath: string) => Promise - setSuggestionsState: React.Dispatch> setSpellCheckEnabled: React.Dispatch> deleteFile: (path: string | undefined) => Promise selectedDirectory: string | null @@ -80,7 +77,6 @@ export const FileProvider: React.FC<{ children: ReactNode }> = ({ children }) => const [expandedDirectories, setExpandedDirectories] = useState>(new Map()) const [selectedDirectory, setSelectedDirectory] = useState(null) const [currentlyOpenFilePath, setCurrentlyOpenFilePath] = useState(null) - const [suggestionsState, setSuggestionsState] = useState() const [needToWriteEditorContentToDisk, setNeedToWriteEditorContentToDisk] = useState(false) const [needToIndexEditorContent, setNeedToIndexEditorContent] = useState(false) const [spellCheckEnabled, setSpellCheckEnabled] = useState(false) @@ -369,7 +365,6 @@ export const FileProvider: React.FC<{ children: ReactNode }> = ({ children }) => navigationHistory, addToNavigationHistory, openOrCreateFile, - suggestionsState, spellCheckEnabled, highlightData, noteToBeRenamed, @@ -377,7 +372,6 @@ export const FileProvider: React.FC<{ children: ReactNode }> = ({ children }) => fileDirToBeRenamed, setFileDirToBeRenamed, renameFile, - setSuggestionsState, setSpellCheckEnabled, deleteFile, selectedDirectory,