Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tabs restore on page mount #105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/App/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import type {AppProps, PageData} from './index';
import type {Settings} from '../../utils';

import React, {useCallback, useMemo} from 'react';
import React, {useCallback, useEffect, useMemo} from 'react';
import {PageConstructor, PageConstructorProvider} from '@gravity-ui/page-constructor';
import {DocBasePageData, getPageByType, getPageType} from '@diplodoc/components';
import {useDiplodocTabs} from '@diplodoc/tabs-extension/react';

Check failure on line 8 in src/components/App/Page.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'@diplodoc/tabs-extension' should be listed in the project's dependencies. Run 'npm i -S @diplodoc/tabs-extension' to add it

import {Layout} from '../Layout';
import {ConstructorPage} from '../ConstructorPage';
Expand All @@ -21,6 +22,17 @@
const type = getPageType(data);
const Page = getPageByType(type);

const tabs = useDiplodocTabs();
tabs.configure({saveTabsToLocalStorage: true, saveTabsToQueryStateMode: 'page'});

useEffect(() => {
tabs.onPageChanged();
tabs.restoreTabs({
...tabs.getTabsFromLocalStorage(),
...tabs.getTabsFromSearchQuery,
});
}, [tabs]);

return (
<Layout headerHeight={pageProps.headerHeight}>
<Layout.Content>
Expand Down
Loading