mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-05 04:12:53 +02:00
feat(theme-classic): store selected tab in query string. (#8225)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com> Closes https://github.com/facebook/docusaurus/issues/7008
This commit is contained in:
parent
eb710af1b8
commit
5c09dbfc3d
6 changed files with 329 additions and 111 deletions
|
@ -19,6 +19,8 @@ import {ReactContextError} from '../utils/reactUtils';
|
|||
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
||||
|
||||
type ContextValue = {
|
||||
/** A boolean that tells if choices have already been restored from storage */
|
||||
readonly ready: boolean;
|
||||
/** A map from `groupId` to the `value` of the saved choice. */
|
||||
readonly tabGroupChoices: {readonly [groupId: string]: string};
|
||||
/** Set the new choice value of a group. */
|
||||
|
@ -28,6 +30,7 @@ type ContextValue = {
|
|||
const Context = React.createContext<ContextValue | undefined>(undefined);
|
||||
|
||||
function useContextValue(): ContextValue {
|
||||
const [ready, setReady] = useState(false);
|
||||
const [tabGroupChoices, setChoices] = useState<{
|
||||
readonly [groupId: string]: string;
|
||||
}>({});
|
||||
|
@ -51,6 +54,7 @@ function useContextValue(): ContextValue {
|
|||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
setReady(true);
|
||||
}, []);
|
||||
|
||||
const setTabGroupChoices = useCallback(
|
||||
|
@ -62,8 +66,8 @@ function useContextValue(): ContextValue {
|
|||
);
|
||||
|
||||
return useMemo(
|
||||
() => ({tabGroupChoices, setTabGroupChoices}),
|
||||
[tabGroupChoices, setTabGroupChoices],
|
||||
() => ({ready, tabGroupChoices, setTabGroupChoices}),
|
||||
[ready, tabGroupChoices, setTabGroupChoices],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue