|
|
@@ -1,81 +1,18 @@
|
|
|
-import { FC, memo, useCallback } from 'react';
|
|
|
+import { memo } from 'react';
|
|
|
|
|
|
-import { SidebarContentsType, SidebarMode } from '~/interfaces/ui';
|
|
|
-import { useCollapsedContentsOpened, useCurrentSidebarContents, useSidebarMode } from '~/stores/ui';
|
|
|
+import dynamic from 'next/dynamic';
|
|
|
|
|
|
-import styles from './PrimaryItems.module.scss';
|
|
|
-
|
|
|
-/**
|
|
|
- * @returns String for className to switch the indicator is active or not
|
|
|
- */
|
|
|
-const useIndicator = (sidebarMode: SidebarMode, isSelected: boolean): string => {
|
|
|
- const { data: isCollapsedContentsOpened } = useCollapsedContentsOpened();
|
|
|
-
|
|
|
- if (sidebarMode === SidebarMode.COLLAPSED && !isCollapsedContentsOpened) {
|
|
|
- return '';
|
|
|
- }
|
|
|
-
|
|
|
- return isSelected ? 'active' : '';
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-type PrimaryItemProps = {
|
|
|
- contents: SidebarContentsType,
|
|
|
- label: string,
|
|
|
- iconName: string,
|
|
|
- sidebarMode: SidebarMode,
|
|
|
- onHover?: (contents: SidebarContentsType) => void,
|
|
|
-}
|
|
|
-
|
|
|
-const PrimaryItem: FC<PrimaryItemProps> = (props: PrimaryItemProps) => {
|
|
|
- const {
|
|
|
- contents, label, iconName, sidebarMode,
|
|
|
- onHover,
|
|
|
- } = props;
|
|
|
-
|
|
|
- const { data: currentContents, mutateAndSave: mutateContents } = useCurrentSidebarContents();
|
|
|
+import { SidebarContentsType } from '~/interfaces/ui';
|
|
|
+import { useSidebarMode } from '~/stores/ui';
|
|
|
|
|
|
- const indicatorClass = useIndicator(sidebarMode, contents === currentContents);
|
|
|
+import { PrimaryItem } from './PrimaryItem';
|
|
|
|
|
|
- const selectThisItem = useCallback(() => {
|
|
|
- mutateContents(contents, false);
|
|
|
- }, [contents, mutateContents]);
|
|
|
-
|
|
|
- const itemClickedHandler = useCallback(() => {
|
|
|
- // do nothing ONLY WHEN the collapse mode
|
|
|
- if (sidebarMode === SidebarMode.COLLAPSED) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- selectThisItem();
|
|
|
- }, [selectThisItem, sidebarMode]);
|
|
|
-
|
|
|
- const mouseEnteredHandler = useCallback(() => {
|
|
|
- // ignore other than collapsed mode
|
|
|
- if (sidebarMode !== SidebarMode.COLLAPSED) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- selectThisItem();
|
|
|
- onHover?.(contents);
|
|
|
- }, [contents, onHover, selectThisItem, sidebarMode]);
|
|
|
-
|
|
|
-
|
|
|
- const labelForTestId = label.toLowerCase().replace(' ', '-');
|
|
|
-
|
|
|
- return (
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- data-testid={`grw-sidebar-nav-primary-${labelForTestId}`}
|
|
|
- className={`btn btn-primary ${indicatorClass}`}
|
|
|
- onClick={itemClickedHandler}
|
|
|
- onMouseEnter={mouseEnteredHandler}
|
|
|
- >
|
|
|
- <span className="material-symbols-outlined">{iconName}</span>
|
|
|
- </button>
|
|
|
- );
|
|
|
-};
|
|
|
+import styles from './PrimaryItems.module.scss';
|
|
|
|
|
|
+// Do not SSR Socket.io to make it work
|
|
|
+const PrimaryItemForNotification = dynamic(
|
|
|
+ () => import('../InAppNotification/PrimaryItemForNotification').then(mod => mod.PrimaryItemForNotification), { ssr: false },
|
|
|
+);
|
|
|
|
|
|
type Props = {
|
|
|
onItemHover?: (contents: SidebarContentsType) => void,
|
|
|
@@ -97,13 +34,7 @@ export const PrimaryItems = memo((props: Props) => {
|
|
|
<PrimaryItem sidebarMode={sidebarMode} contents={SidebarContentsType.RECENT} label="Recent Changes" iconName="update" onHover={onItemHover} />
|
|
|
<PrimaryItem sidebarMode={sidebarMode} contents={SidebarContentsType.BOOKMARKS} label="Bookmarks" iconName="bookmarks" onHover={onItemHover} />
|
|
|
<PrimaryItem sidebarMode={sidebarMode} contents={SidebarContentsType.TAG} label="Tags" iconName="local_offer" onHover={onItemHover} />
|
|
|
- <PrimaryItem
|
|
|
- sidebarMode={sidebarMode}
|
|
|
- contents={SidebarContentsType.NOTIFICATION}
|
|
|
- label="In-App Notification"
|
|
|
- iconName="notifications"
|
|
|
- onHover={onItemHover}
|
|
|
- />
|
|
|
+ <PrimaryItemForNotification sidebarMode={sidebarMode} onHover={onItemHover} />
|
|
|
</div>
|
|
|
);
|
|
|
});
|