mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
fix: auto open page if is in page before last close
This commit is contained in:
parent
e26cd2d09f
commit
497bec3c0d
3 changed files with 22 additions and 2 deletions
|
|
@ -13,8 +13,9 @@ import { usePreferenceObservable } from '@services/preferences/hooks';
|
|||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import FindInPage from '../../components/FindInPage';
|
||||
import { SideBar } from '../../components/Sidebar';
|
||||
import { WikiBackground } from '../WikiBackground';
|
||||
import { Guide } from '../Guide';
|
||||
import { WikiBackground } from '../WikiBackground';
|
||||
import { useInitialPage } from './useInitialPage';
|
||||
|
||||
const Workflow = lazy(() => import('../Workflow'));
|
||||
|
||||
|
|
@ -63,6 +64,7 @@ const ContentRoot = styled.div`
|
|||
|
||||
export default function Main(): JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
useInitialPage();
|
||||
const preferences = usePreferenceObservable();
|
||||
if (preferences === undefined) return <div>{t('Loading')}</div>;
|
||||
const { sidebar } = preferences;
|
||||
|
|
|
|||
18
src/pages/Main/useInitialPage.ts
Normal file
18
src/pages/Main/useInitialPage.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { usePromiseValue } from '@/helpers/useServiceValue';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useLocation } from 'wouter';
|
||||
|
||||
export function useInitialPage() {
|
||||
const [, setLocation] = useLocation();
|
||||
// when first open the TidGi and no workspace is active (so no BrowserView will be on top of the React), goto the active pages route
|
||||
const initialActivePage = usePromiseValue(async () => await window.service.pages.getActivePage());
|
||||
// only do this once, and not triggering unnecessary rerender by using ref.
|
||||
const [alreadyInitialized, alreadyInitializedSetter] = useState(false);
|
||||
useEffect(() => {
|
||||
if (initialActivePage !== undefined && !alreadyInitialized) {
|
||||
setLocation(`/${WindowNames.main}/${initialActivePage.type}/${initialActivePage.id}/`);
|
||||
alreadyInitializedSetter(true);
|
||||
}
|
||||
}, [setLocation, initialActivePage, alreadyInitialized, alreadyInitializedSetter]);
|
||||
}
|
||||
|
|
@ -54,8 +54,8 @@ export class Pages implements IPagesService {
|
|||
public async setActivePage(id: string | PageType, oldActivePageID: string | PageType | undefined): Promise<void> {
|
||||
logger.info(`openPage: ${id}`);
|
||||
await Promise.all([
|
||||
this.update(id, { active: true }),
|
||||
oldActivePageID !== id && this.clearActivePage(oldActivePageID),
|
||||
this.update(id, { active: true }),
|
||||
// if not switch to wiki page, e.g. switch from workspace to workflow page, clear active workspace and close its browser view
|
||||
id !== PageType.wiki && this.workspaceViewService.clearActiveWorkspaceView(),
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue