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(() => {
|
useEffect(() => {
|
||||||
const handlePopState = (e: PopStateEvent) => {
|
const handlePopState = (e: PopStateEvent) => {
|
||||||
|
setEditingFile(null);
|
||||||
if (e.state && e.state.path) setCurrentPath(e.state.path);
|
if (e.state && e.state.path) setCurrentPath(e.state.path);
|
||||||
else setCurrentPath(new URLSearchParams(window.location.search).get('path') || '.');
|
else setCurrentPath(new URLSearchParams(window.location.search).get('path') || '.');
|
||||||
setPreviewFile(null);
|
setPreviewFile(null);
|
||||||
|
|
@ -208,6 +209,11 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
||||||
const [viewMode, setViewMode] = useState<ViewMode>('grid');
|
const [viewMode, setViewMode] = useState<ViewMode>('grid');
|
||||||
const [appMode, setAppMode] = useState<'drive' | 'docs' | 'slides' | 'sheets'>('drive');
|
const [appMode, setAppMode] = useState<'drive' | 'docs' | 'slides' | 'sheets'>('drive');
|
||||||
const [editingFile, setEditingFile] = useState<FileItem | null>(null);
|
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 [activeSection, setActiveSection] = useState<SidebarSection>('files');
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
const [searchResults, setSearchResults] = useState<FileItem[] | null>(null);
|
const [searchResults, setSearchResults] = useState<FileItem[] | null>(null);
|
||||||
|
|
@ -531,13 +537,13 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
||||||
navigateToFolder(file);
|
navigateToFolder(file);
|
||||||
} else if (file.name.endsWith('.docx')) {
|
} else if (file.name.endsWith('.docx')) {
|
||||||
setAppMode('docs');
|
setAppMode('docs');
|
||||||
setEditingFile(file);
|
openEditor(file);
|
||||||
} else if (file.name.endsWith('.pptx')) {
|
} else if (file.name.endsWith('.pptx')) {
|
||||||
setAppMode('slides');
|
setAppMode('slides');
|
||||||
setEditingFile(file);
|
openEditor(file);
|
||||||
} else if (file.name.endsWith('.xlsx') || file.name.endsWith('.xls')) {
|
} else if (file.name.endsWith('.xlsx') || file.name.endsWith('.xls')) {
|
||||||
setAppMode('sheets');
|
setAppMode('sheets');
|
||||||
setEditingFile(file);
|
openEditor(file);
|
||||||
} else {
|
} else {
|
||||||
setPreviewFile(file);
|
setPreviewFile(file);
|
||||||
}
|
}
|
||||||
|
|
@ -1929,9 +1935,9 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
|
||||||
) : (appMode === 'docs' || appMode === 'slides' || appMode === 'sheets') && activeSection === 'files' ? (
|
) : (appMode === 'docs' || appMode === 'slides' || appMode === 'sheets') && activeSection === 'files' ? (
|
||||||
<OfficeHome
|
<OfficeHome
|
||||||
type={appMode}
|
type={appMode}
|
||||||
onFileSelect={(file) => setEditingFile(file)}
|
onFileSelect={(file) => openEditor(file)}
|
||||||
onCreateBlank={(file) => {
|
onCreateBlank={(file) => {
|
||||||
setEditingFile(file);
|
openEditor(file);
|
||||||
loadFiles();
|
loadFiles();
|
||||||
}}
|
}}
|
||||||
onPinChange={() => setPinnedRefreshCounter(c => c + 1)}
|
onPinChange={() => setPinnedRefreshCounter(c => c + 1)}
|
||||||
|
|
|
||||||
Reference in a new issue