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" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ThemeSwitcher } from './components/ThemeSwitcher'
|
||||
function App() {
|
||||
const [currentFile, setCurrentFile] = useState<string | null>(null)
|
||||
const [files, setFiles] = useState<string[]>([])
|
||||
const [fileContent, setFileContent] = useState<string>('')
|
||||
const [darkMode, setDarkMode] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -34,6 +35,7 @@ function App() {
|
||||
if (response.ok) {
|
||||
await fetchFiles()
|
||||
setCurrentFile(name)
|
||||
setFileContent(content)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to create file:', error)
|
||||
@@ -43,8 +45,9 @@ function App() {
|
||||
const handleFileOpen = async (name: string) => {
|
||||
try {
|
||||
const response = await fetch(`/api/files/${name}`)
|
||||
await response.json()
|
||||
const data = await response.json()
|
||||
setCurrentFile(name)
|
||||
setFileContent(data.content || '')
|
||||
} catch (error) {
|
||||
console.error('Failed to open file:', error)
|
||||
}
|
||||
@@ -78,6 +81,7 @@ function App() {
|
||||
|
||||
if (currentFile === name) {
|
||||
setCurrentFile(null)
|
||||
setFileContent('')
|
||||
}
|
||||
await fetchFiles()
|
||||
} catch (error) {
|
||||
@@ -111,7 +115,7 @@ function App() {
|
||||
</div>
|
||||
<div className="flex-1 overflow-hidden flex flex-col">
|
||||
<MarkdownEditor
|
||||
initialContent=""
|
||||
initialContent={fileContent}
|
||||
onSave={handleFileSave}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user