import React, { memo, useCallback, useEffect, useState, } from 'react'; import { DevidedPagePath, isPopulated } from '@growi/core'; import { UserPicture, FootstampIcon } from '@growi/ui'; import { useTranslation } from 'next-i18next'; import Link from 'next/link'; import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink'; import { IPageHasId } from '~/interfaces/page'; import LinkedPagePath from '~/models/linked-page-path'; import { useSWRInifinitexRecentlyUpdated } from '~/stores/page-listing'; import loggerFactory from '~/utils/logger'; import FormattedDistanceDate from '../FormattedDistanceDate'; import InfiniteScroll from './InfiniteScroll'; import TagLabelsStyles from '../Page/TagLabels.module.scss'; import styles from './RecentChanges.module.scss'; const logger = loggerFactory('growi:History'); type PageItemProps = { page: IPageHasId, } const PageItemLower = memo(({ page }: PageItemProps): JSX.Element => { return (
{page.seenUsers.length}
{page.commentCount}
); }); PageItemLower.displayName = 'PageItemLower'; const LargePageItem = memo(({ page }: PageItemProps): JSX.Element => { const dPagePath = new DevidedPagePath(page.path, false, true); const linkedPagePathFormer = new LinkedPagePath(dPagePath.former); const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter); const FormerLink = () => (
); let locked; if (page.grant !== 1) { locked = ; } const tags = page.tags; const tagElements = tags.map((tag) => { if (!isPopulated(tag)) { return <>; } return ( {tag.name} ); }); return (
  • { !dPagePath.isRoot && }
    {locked}
    { tagElements }
  • ); }); LargePageItem.displayName = 'LargePageItem'; const SmallPageItem = memo(({ page }: PageItemProps): JSX.Element => { const dPagePath = new DevidedPagePath(page.path, false, true); const linkedPagePathFormer = new LinkedPagePath(dPagePath.former); const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter); const FormerLink = () => (
    ); let locked; if (page.grant !== 1) { locked = ; } return (
  • { !dPagePath.isRoot && }
    {locked}
  • ); }); SmallPageItem.displayName = 'SmallPageItem'; const RecentChanges = (): JSX.Element => { const PER_PAGE = 20; const { t } = useTranslation(); const swr = useSWRInifinitexRecentlyUpdated(); const [isRecentChangesSidebarSmall, setIsRecentChangesSidebarSmall] = useState(false); const isEmpty = swr.data?.[0].length === 0; const isReachingEnd = isEmpty || (swr.data && swr.data[swr.data.length - 1]?.length < PER_PAGE); const retrieveSizePreferenceFromLocalStorage = useCallback(() => { if (window.localStorage.isRecentChangesSidebarSmall === 'true') { setIsRecentChangesSidebarSmall(true); } }, []); const changeSizeHandler = useCallback((e) => { setIsRecentChangesSidebarSmall(e.target.checked); window.localStorage.setItem('isRecentChangesSidebarSmall', e.target.checked); }, []); // componentDidMount useEffect(() => { retrieveSizePreferenceFromLocalStorage(); }, [retrieveSizePreferenceFromLocalStorage]); return (

    {t('Recent Changes')}

      {pages => pages.map(page => ( isRecentChangesSidebarSmall ? : )) }
    ); }; export default RecentChanges;