Skip to content

Commit

Permalink
fix(AllPages): fix stuck i18n (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunory authored Oct 4, 2023
1 parent 2abc163 commit f7879b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/components/AllPagesPanel/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {MenuItem} from '../types';

export const ALL_PAGES_ID = 'all-pages' as const;

export const ALL_PAGES_MENU_ITEM: MenuItem = {
id: ALL_PAGES_ID,
title: i18n('menu-item.all-pages.title'),
tooltipText: i18n('menu-item.all-pages.title'),
icon: Ellipsis,
};
export function getAllPagesMenuItem(): MenuItem {
return {
id: ALL_PAGES_ID,
title: i18n('menu-item.all-pages.title'),
tooltipText: i18n('menu-item.all-pages.title'),
icon: Ellipsis,
};
}
2 changes: 1 addition & 1 deletion src/components/AllPagesPanel/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {AllPagesPanel} from './AllPagesPanel';
export {ALL_PAGES_MENU_ITEM, ALL_PAGES_ID} from './constants';
export {getAllPagesMenuItem, ALL_PAGES_ID} from './constants';
export {useVisibleMenuItems} from './useVisibleMenuItems';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {AsideHeaderInnerContextType} from './AsideHeaderContext';
import {AsideHeaderProps, InnerPanels} from './types';
import {MenuItem} from '../types';
import {ALL_PAGES_MENU_ITEM, AllPagesPanel} from '../AllPagesPanel';
import {getAllPagesMenuItem, AllPagesPanel} from '../AllPagesPanel';

const EMPTY_MENU_ITEMS: MenuItem[] = [];

Expand All @@ -11,6 +11,9 @@ export const useAsideHeaderInnerContextValue = (
): AsideHeaderInnerContextType => {
const {size, onClosePanel, menuItems, panelItems, onMenuItemsChanged} = props;
const [innerVisiblePanel, setInnerVisiblePanel] = useState<InnerPanels | undefined>();
const ALL_PAGES_MENU_ITEM = React.useMemo(() => {
return getAllPagesMenuItem();
}, []);

const allPagesIsAvailable =
Boolean(onMenuItemsChanged) && (!menuItems || menuItems?.length > 0);
Expand Down Expand Up @@ -42,7 +45,7 @@ export const useAsideHeaderInnerContextValue = (
}
item.onItemClick?.(item, collapsed, event);
},
[innerOnClosePanel],
[innerOnClosePanel, ALL_PAGES_MENU_ITEM],
);

const innerMenuItems = useMemo(
Expand All @@ -56,7 +59,7 @@ export const useAsideHeaderInnerContextValue = (
},
]
: menuItems || EMPTY_MENU_ITEMS,
[allPagesIsAvailable, menuItems, innerVisiblePanel],
[allPagesIsAvailable, menuItems, innerVisiblePanel, ALL_PAGES_MENU_ITEM],
);

const innerPanelItems = useMemo(() => {
Expand Down

0 comments on commit f7879b3

Please sign in to comment.