Fix some props issues

This commit is contained in:
2024-10-05 23:15:35 +02:00
parent 9de434ff2e
commit 6406265df6
5 changed files with 17 additions and 14 deletions

View File

@@ -44,6 +44,8 @@ const ContentView = ({
); );
} }
console.log('ContentView content', content);
return activeTab === 'source' ? ( return activeTab === 'source' ? (
<Editor <Editor
content={content} content={content}

View File

@@ -7,11 +7,13 @@ import { defaultKeymap } from '@codemirror/commands';
import { oneDark } from '@codemirror/theme-one-dark'; import { oneDark } from '@codemirror/theme-one-dark';
import { useSettings } from '../contexts/SettingsContext'; import { useSettings } from '../contexts/SettingsContext';
const Editor = (content, handleContentChange, handleSave, selectedFile) => { const Editor = ({ content, handleContentChange, handleSave, selectedFile }) => {
const { settings } = useSettings(); const { settings } = useSettings();
const editorRef = useRef(); const editorRef = useRef();
const viewRef = useRef(); const viewRef = useRef();
console.log('Editor content:', content);
useEffect(() => { useEffect(() => {
const handleEditorSave = (view) => { const handleEditorSave = (view) => {
handleSave(selectedFile, view.state.doc.toString()); handleSave(selectedFile, view.state.doc.toString());

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { useState, useCallback, useEffect } from 'react'; import { useState, useCallback, useEffect } from 'react';
import { Breadcrumbs, Grid, Tabs } from '@geist-ui/core'; import { Breadcrumbs, Dot, Grid, Tabs } from '@geist-ui/core';
import { Code, Eye } from '@geist-ui/icons'; import { Code, Eye } from '@geist-ui/icons';
import FileActions from './FileActions'; import FileActions from './FileActions';
@@ -18,7 +18,7 @@ import { useFileNavigation } from '../hooks/useFileNavigation';
const MainContent = () => { const MainContent = () => {
const [activeTab, setActiveTab] = useState('source'); const [activeTab, setActiveTab] = useState('source');
const [files, loadFileList] = useFileList(); const { files, loadFileList } = useFileList();
const { content, hasUnsavedChanges, handleContentChange } = useFileContent(); const { content, hasUnsavedChanges, handleContentChange } = useFileContent();
const { handleSave, handleCreate, handleDelete } = useFileOperations(); const { handleSave, handleCreate, handleDelete } = useFileOperations();
const { handleCommitAndPush, handlePull } = useGitOperations(); const { handleCommitAndPush, handlePull } = useGitOperations();
@@ -38,7 +38,7 @@ const MainContent = () => {
await handleCreate(fileName); await handleCreate(fileName);
await loadFileList(); await loadFileList();
}, },
[handleCreate] [handleCreate, loadFileList]
); );
const handleDeleteFile = useCallback( const handleDeleteFile = useCallback(
@@ -46,7 +46,7 @@ const MainContent = () => {
await handleDelete(filePath); await handleDelete(filePath);
await loadFileList(); await loadFileList();
}, },
[handleDelete] [handleDelete, loadFileList]
); );
const renderBreadcrumbs = () => { const renderBreadcrumbs = () => {

View File

@@ -7,7 +7,7 @@ import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
import 'katex/dist/katex.min.css'; import 'katex/dist/katex.min.css';
import { lookupFileByName } from '../services/api'; import { lookupFileByName } from '../services/api';
const MarkdownPreview = (content, handleLinkClick) => { const MarkdownPreview = ({ content, handleLinkClick }) => {
const [processedContent, setProcessedContent] = useState(content); const [processedContent, setProcessedContent] = useState(content);
const baseUrl = window.API_BASE_URL; const baseUrl = window.API_BASE_URL;

View File

@@ -1,8 +1,7 @@
// hooks/useFileNavigation.js
import { useState, useCallback } from 'react'; import { useState, useCallback } from 'react';
import { useToasts } from '@geist-ui/core'; import { useToasts } from '@geist-ui/core';
import { lookupFileByName } from '../services/api'; import { lookupFileByName } from '../services/api';
import { DEFAULT_FILE } from '../utils/constants'; // Assuming you have this constant defined import { DEFAULT_FILE } from '../utils/constants';
export const useFileNavigation = () => { export const useFileNavigation = () => {
const { setToast } = useToasts(); const { setToast } = useToasts();
@@ -10,6 +9,11 @@ export const useFileNavigation = () => {
const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path); const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path);
const [isNewFile, setIsNewFile] = useState(true); const [isNewFile, setIsNewFile] = useState(true);
const handleFileSelect = useCallback((filePath) => {
setSelectedFile(filePath);
setIsNewFile(filePath === DEFAULT_FILE.path);
}, []);
const handleLinkClick = useCallback( const handleLinkClick = useCallback(
async (filename) => { async (filename) => {
try { try {
@@ -27,13 +31,8 @@ export const useFileNavigation = () => {
}); });
} }
}, },
[handleFileSelect] [handleFileSelect, setToast]
); );
const handleFileSelect = useCallback(async (filePath) => {
setSelectedFile(filePath);
setIsNewFile(filePath === DEFAULT_FILE.path);
}, []);
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect }; return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };
}; };