fix(files): auto-refresh the tree on window focus and via a dispatchable event

The tree caches loaded directories per refresh tick, so content edited
outside DSH (another editor, a sync plugin pulling from a remote) stayed
stale until the manual refresh click.

- bump the tick when the window regains focus, so switching back to DSH
  shows the on-disk state
- also bump on a bubbling 'dsh-sidebar:refresh-files' window event, so
  external plugins (e.g. dsh-better-overleaf after a pull/push) can
  refresh the tree programmatically without reaching into internals
This commit is contained in:
Hoemr
2026-08-30 17:55:37 +08:00
parent 3aab7ca3a5
commit f23e40facf
+15
View File
@@ -72,6 +72,21 @@ export function TreePanel(props: {
const [results, setResults] = useState<{ matches: string[]; truncated: boolean } | null>(null)
const [error, setError] = useState<string | null>(null)
const [refreshTick, setRefreshTick] = useState(0)
// The tree caches loaded directories per refresh tick, so content changed
// outside DSH (another editor, a sync tool) stays stale until the manual
// refresh click. Re-focusing the window bumps the tick automatically, and
// integrations can force a refresh by dispatching a bubbling
// `dsh-sidebar:refresh-files` event on `window`.
useEffect(() => {
const bump = (): void => { setRefreshTick(tick => tick + 1) }
window.addEventListener('focus', bump)
window.addEventListener('dsh-sidebar:refresh-files', bump)
return () => {
window.removeEventListener('focus', bump)
window.removeEventListener('dsh-sidebar:refresh-files', bump)
}
}, [])
/** One-line upload status under the search row ('' hides the hint). */
const [uploadStatus, setUploadStatus] = useState('')
/** Whether the status line is a failure/cancel (error color, stays visible). */