fix(frontend): display file content when opening existing files
Fix issue where file content was not displayed when opening files. Added fileContent state to store and pass file content to MarkdownEditor component.
This commit is contained in:
File diff suppressed because one or more lines are too long
2
frontend/dist/index.html
vendored
2
frontend/dist/index.html
vendored
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Markdown Editor</title>
|
<title>Markdown Editor</title>
|
||||||
<script type="module" crossorigin src="/assets/index-39f1aff0.js"></script>
|
<script type="module" crossorigin src="/assets/index-47e80c4a.js"></script>
|
||||||
<link rel="stylesheet" href="/assets/index-8d1b4242.css">
|
<link rel="stylesheet" href="/assets/index-8d1b4242.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { ThemeSwitcher } from './components/ThemeSwitcher'
|
|||||||
function App() {
|
function App() {
|
||||||
const [currentFile, setCurrentFile] = useState<string | null>(null)
|
const [currentFile, setCurrentFile] = useState<string | null>(null)
|
||||||
const [files, setFiles] = useState<string[]>([])
|
const [files, setFiles] = useState<string[]>([])
|
||||||
|
const [fileContent, setFileContent] = useState<string>('')
|
||||||
const [darkMode, setDarkMode] = useState(false)
|
const [darkMode, setDarkMode] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -34,6 +35,7 @@ function App() {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
await fetchFiles()
|
await fetchFiles()
|
||||||
setCurrentFile(name)
|
setCurrentFile(name)
|
||||||
|
setFileContent(content)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to create file:', error)
|
console.error('Failed to create file:', error)
|
||||||
@@ -43,8 +45,9 @@ function App() {
|
|||||||
const handleFileOpen = async (name: string) => {
|
const handleFileOpen = async (name: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/files/${name}`)
|
const response = await fetch(`/api/files/${name}`)
|
||||||
await response.json()
|
const data = await response.json()
|
||||||
setCurrentFile(name)
|
setCurrentFile(name)
|
||||||
|
setFileContent(data.content || '')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to open file:', error)
|
console.error('Failed to open file:', error)
|
||||||
}
|
}
|
||||||
@@ -78,6 +81,7 @@ function App() {
|
|||||||
|
|
||||||
if (currentFile === name) {
|
if (currentFile === name) {
|
||||||
setCurrentFile(null)
|
setCurrentFile(null)
|
||||||
|
setFileContent('')
|
||||||
}
|
}
|
||||||
await fetchFiles()
|
await fetchFiles()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -111,7 +115,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex-1 overflow-hidden flex flex-col">
|
<div className="flex-1 overflow-hidden flex flex-col">
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
initialContent=""
|
initialContent={fileContent}
|
||||||
onSave={handleFileSave}
|
onSave={handleFileSave}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user