fix: open editor immediately when clicking suggested property slots
Previously, clicking a suggested property slot (Status, Date, URL) would add an empty property to frontmatter but fail to open the editor. This was due to a race condition where: 1. handleSuggestedAdd() called onAddProperty() which is async 2. The useEffect tried to detect when the property appeared in frontmatter 3. But frontmatter updates asynchronously after onAddProperty resolves 4. By the time frontmatter is updated, the useEffect had already run The fix is to directly set the editing key immediately when clicking a suggested slot, rather than relying on the useEffect to detect the property being added. This is more reliable because we know we're adding the property - we don't need to wait for it to appear in frontmatter.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
---
|
||||
type: Project
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
|
||||
|
||||
4
demo-vault-v2/untitled-note-1775496473.md
Normal file
4
demo-vault-v2/untitled-note-1775496473.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
5
demo-vault-v2/untitled-note-1775496825.md
Normal file
5
demo-vault-v2/untitled-note-1775496825.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
My Custom H1 Heading
|
||||
7
demo-vault-v2/untitled-note-1775497099.md
Normal file
7
demo-vault-v2/untitled-note-1775497099.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
[[2024-03|March 2024]]
|
||||
|
||||
[[2024-03|March 2024]]
|
||||
4
demo-vault-v2/untitled-note-1775541952.md
Normal file
4
demo-vault-v2/untitled-note-1775541952.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542285.md
Normal file
4
demo-vault-v2/untitled-note-1775542285.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542291.md
Normal file
4
demo-vault-v2/untitled-note-1775542291.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542296.md
Normal file
4
demo-vault-v2/untitled-note-1775542296.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542431.md
Normal file
4
demo-vault-v2/untitled-note-1775542431.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542439.md
Normal file
4
demo-vault-v2/untitled-note-1775542439.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542446.md
Normal file
4
demo-vault-v2/untitled-note-1775542446.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542459.md
Normal file
4
demo-vault-v2/untitled-note-1775542459.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542467.md
Normal file
4
demo-vault-v2/untitled-note-1775542467.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542474.md
Normal file
4
demo-vault-v2/untitled-note-1775542474.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542676.md
Normal file
4
demo-vault-v2/untitled-note-1775542676.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542684.md
Normal file
4
demo-vault-v2/untitled-note-1775542684.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542692.md
Normal file
4
demo-vault-v2/untitled-note-1775542692.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542700.md
Normal file
4
demo-vault-v2/untitled-note-1775542700.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542708.md
Normal file
4
demo-vault-v2/untitled-note-1775542708.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
7
demo-vault-v2/untitled-note-1775542716-renamed.md
Normal file
7
demo-vault-v2/untitled-note-1775542716-renamed.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
type: Project
|
||||
status: Active
|
||||
---
|
||||
|
||||
|
||||
Appended by raw editor test
|
||||
4
demo-vault-v2/untitled-note-1775542923.md
Normal file
4
demo-vault-v2/untitled-note-1775542923.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542931.md
Normal file
4
demo-vault-v2/untitled-note-1775542931.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542938.md
Normal file
4
demo-vault-v2/untitled-note-1775542938.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542951.md
Normal file
4
demo-vault-v2/untitled-note-1775542951.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542959.md
Normal file
4
demo-vault-v2/untitled-note-1775542959.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
4
demo-vault-v2/untitled-note-1775542967.md
Normal file
4
demo-vault-v2/untitled-note-1775542967.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
7
demo-vault-v2/untitled-note-1775542981.md
Normal file
7
demo-vault-v2/untitled-note-1775542981.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
type: Note
|
||||
status: Active
|
||||
---
|
||||
[[2024-03|March 2024]]
|
||||
|
||||
[[2024-03|March 2024]]
|
||||
15
demo-vault-v2/untitled-project-1775497094.md
Normal file
15
demo-vault-v2/untitled-project-1775497094.md
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
type: Project
|
||||
status: Active
|
||||
---
|
||||
|
||||
## Objective
|
||||
|
||||
|
||||
|
||||
## Key Results
|
||||
|
||||
|
||||
|
||||
## Notes
|
||||
|
||||
15
demo-vault-v2/untitled-project-1775542975.md
Normal file
15
demo-vault-v2/untitled-project-1775542975.md
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
type: Project
|
||||
status: Active
|
||||
---
|
||||
|
||||
## Objective
|
||||
|
||||
|
||||
|
||||
## Key Results
|
||||
|
||||
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMemo, useCallback, useRef, useEffect } from 'react'
|
||||
import { useMemo, useCallback } from 'react'
|
||||
import type { VaultEntry } from '../types'
|
||||
import type { FrontmatterValue } from './Inspector'
|
||||
import type { ParsedFrontmatter } from '../utils/frontmatter'
|
||||
@@ -113,20 +113,12 @@ export function DynamicPropertiesPanel({
|
||||
? SUGGESTED_PROPERTIES.filter(p => !existingKeys.has(p.toLowerCase()))
|
||||
: []
|
||||
|
||||
const pendingEditKeyRef = useRef<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (pendingEditKeyRef.current && propertyEntries.some(([k]) => k === pendingEditKeyRef.current)) {
|
||||
setEditingKey(pendingEditKeyRef.current)
|
||||
pendingEditKeyRef.current = null
|
||||
}
|
||||
}, [propertyEntries, setEditingKey])
|
||||
|
||||
const handleSuggestedAdd = useCallback((key: string) => {
|
||||
if (!onAddProperty) return
|
||||
pendingEditKeyRef.current = key
|
||||
// Open the editor immediately - no need to wait for frontmatter to update
|
||||
setEditingKey(key)
|
||||
onAddProperty(key, '')
|
||||
}, [onAddProperty])
|
||||
}, [onAddProperty, setEditingKey])
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
|
||||
Reference in New Issue
Block a user