Fix: add browser history state for document editor to support mouse back button
All checks were successful
Automated Container Build / build-and-push (push) Successful in 37s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 37s
This commit is contained in:
parent
c9c36cce30
commit
2e463a3104
1 changed files with 11 additions and 5 deletions
|
|
@ -195,6 +195,7 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
|||
|
||||
useEffect(() => {
|
||||
const handlePopState = (e: PopStateEvent) => {
|
||||
setEditingFile(null);
|
||||
if (e.state && e.state.path) setCurrentPath(e.state.path);
|
||||
else setCurrentPath(new URLSearchParams(window.location.search).get('path') || '.');
|
||||
setPreviewFile(null);
|
||||
|
|
@ -208,6 +209,11 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
|||
const [viewMode, setViewMode] = useState<ViewMode>('grid');
|
||||
const [appMode, setAppMode] = useState<'drive' | 'docs' | 'slides' | 'sheets'>('drive');
|
||||
const [editingFile, setEditingFile] = useState<FileItem | null>(null);
|
||||
|
||||
const openEditor = useCallback((file: FileItem) => {
|
||||
setEditingFile(file);
|
||||
window.history.pushState({ editing: true, path: currentPath }, '', window.location.search || window.location.href);
|
||||
}, [currentPath]);
|
||||
const [activeSection, setActiveSection] = useState<SidebarSection>('files');
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [searchResults, setSearchResults] = useState<FileItem[] | null>(null);
|
||||
|
|
@ -531,13 +537,13 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
|||
navigateToFolder(file);
|
||||
} else if (file.name.endsWith('.docx')) {
|
||||
setAppMode('docs');
|
||||
setEditingFile(file);
|
||||
openEditor(file);
|
||||
} else if (file.name.endsWith('.pptx')) {
|
||||
setAppMode('slides');
|
||||
setEditingFile(file);
|
||||
openEditor(file);
|
||||
} else if (file.name.endsWith('.xlsx') || file.name.endsWith('.xls')) {
|
||||
setAppMode('sheets');
|
||||
setEditingFile(file);
|
||||
openEditor(file);
|
||||
} else {
|
||||
setPreviewFile(file);
|
||||
}
|
||||
|
|
@ -1929,9 +1935,9 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
|||
) : (appMode === 'docs' || appMode === 'slides' || appMode === 'sheets') && activeSection === 'files' ? (
|
||||
<OfficeHome
|
||||
type={appMode}
|
||||
onFileSelect={(file) => setEditingFile(file)}
|
||||
onFileSelect={(file) => openEditor(file)}
|
||||
onCreateBlank={(file) => {
|
||||
setEditingFile(file);
|
||||
openEditor(file);
|
||||
loadFiles();
|
||||
}}
|
||||
onPinChange={() => setPinnedRefreshCounter(c => c + 1)}
|
||||
|
|
|
|||
Reference in a new issue