file browser opens at home instead of restoring the last path

Navigation is now session-local state that always starts at home. The
unscoped browser still mirrors its folder into files/currentPath so the
Create Dashboard flow keeps defaulting a new dashboard's cwd to it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 23:46:15 +00:00
co-authored by Claude Opus 4.8
parent 82d0e9afd6
commit 5fd3d4faac
@@ -12,17 +12,27 @@ type DefaultSort = {
direction: 'asc' | 'desc'; direction: 'asc' | 'desc';
}; };
export const useFileBrowserApp = (basePath: string, rootOverride?: string, initialPath?: string, defaultSort?: DefaultSort) => { export const useFileBrowserApp = (
basePath: string,
rootOverride?: string,
initialPath?: string,
defaultSort?: DefaultSort,
) => {
const { user } = useAuth(); const { user } = useAuth();
const navigate = useNavigate(); const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams(); const [searchParams, setSearchParams] = useSearchParams();
const homeRoot = 'home'; const homeRoot = 'home';
const [globalPath, setGlobalPath] = useUserState<string>('files/currentPath', '/'); const [, setGlobalPath] = useUserState<string>('files/currentPath', '/');
const [localPath, setLocalPath] = useState(initialPath ?? basePath); const [currentPath, setLocalPath] = useState(initialPath ?? basePath);
const scoped = basePath !== '/'; const scoped = basePath !== '/';
const isolated = !!initialPath; const isolated = !!initialPath;
const currentPath = (scoped || isolated) ? localPath : globalPath; // Navigation is session-local — the browser always opens at home, never restoring the
const setCurrentPath = (scoped || isolated) ? setLocalPath : setGlobalPath; // last path. The main (unscoped) browser still mirrors its folder into files/currentPath
// so the Create Dashboard flow can default a new dashboard's cwd to it.
const setCurrentPath = (path: string) => {
setLocalPath(path);
if (!scoped && !isolated) setGlobalPath(path);
};
const [entries, setEntries] = useState<DirEntry[]>([]); const [entries, setEntries] = useState<DirEntry[]>([]);
const [rootDir, setRootDir] = useState(''); const [rootDir, setRootDir] = useState('');
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
@@ -661,37 +671,55 @@ export const useFileBrowserApp = (basePath: string, rootOverride?: string, initi
user, user,
// Navigation // Navigation
homeRoot, homeRoot,
currentPath, setCurrentPath, currentPath,
setCurrentPath,
// Directory listing // Directory listing
visibleEntries, loading, refresh, visibleEntries,
loading,
refresh,
// View // View
viewMode, setViewMode, defaultSort, viewMode,
showHidden, setShowHidden, hiddenForced, setViewMode,
defaultSort,
showHidden,
setShowHidden,
hiddenForced,
// Selection // Selection
selected, setSelected, selected,
setSelected,
clipboard, clipboard,
renamingName, setRenamingName, renamingName,
setRenamingName,
// Search // Search
searchQuery, setSearchQuery, searchQuery,
searchResults, searching, setSearchQuery,
searchResults,
searching,
searchInputRef, searchInputRef,
// Upload // Upload
uploadProgress, uploadProgress,
// Clone // Clone
showCloneInput, setShowCloneInput, showCloneInput,
cloneUrl, setCloneUrl, setShowCloneInput,
cloneUrl,
setCloneUrl,
cloning, cloning,
// Drag & drop // Drag & drop
dragging, dragging,
// Task runner // Task runner
runningTask, setRunningTask, runningTask,
setRunningTask,
getMatchingTasks, getMatchingTasks,
// Video download // Video download
showVideoDownload, setShowVideoDownload, showVideoDownload,
videoUrl, setVideoUrl, setShowVideoDownload,
audioOnly, setAudioOnly, videoUrl,
setVideoUrl,
audioOnly,
setAudioOnly,
// Dictate // Dictate
showDictate, setShowDictate, showDictate,
setShowDictate,
// Refs // Refs
fileScrollRef, fileScrollRef,
// Handlers // Handlers
@@ -737,4 +765,3 @@ export type UseFileBrowserAppType = ReturnType<typeof useFileBrowserApp>;
// ── Types ── // ── Types ──
type ClipboardState = { paths: string[]; mode: 'copy' | 'cut' } | null; type ClipboardState = { paths: string[]; mode: 'copy' | 'cut' } | null;