import React, {
FC,
useCallback, useEffect, useState,
} from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import { UserPicture } from '@growi/ui';
import { DevidedPagePath } from '@growi/core';
import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink';
import { useSWRxRecentlyUpdated } from '~/stores/page';
import loggerFactory from '~/utils/logger';
import LinkedPagePath from '~/models/linked-page-path';
import FootstampIcon from '../FootstampIcon';
import FormattedDistanceDate from '../FormattedDistanceDate';
const logger = loggerFactory('growi:History');
function PageItemLower({ page }) {
return (
{page.seenUsers.length}
{page.commentCount}
);
}
PageItemLower.propTypes = {
page: PropTypes.any,
};
function LargePageItem({ page }) {
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;
// when tag document is deleted from database directly tags includes null
const tagElements = tags.includes(null)
? <>>
: tags.map((tag) => {
return (
{tag.name}
);
});
return (
{ !dPagePath.isRoot &&
}
{locked}
{ tagElements }
);
}
LargePageItem.propTypes = {
page: PropTypes.any,
};
function SmallPageItem({ page }) {
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.propTypes = {
page: PropTypes.any,
};
const RecentChanges: FC = () => {
const { t } = useTranslation();
const { data: pages, mutate } = useSWRxRecentlyUpdated();
const [isRecentChangesSidebarSmall, setIsRecentChangesSidebarSmall] = useState(false);
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 || []).map(page => (isRecentChangesSidebarSmall
?
: ))}
>
);
};
export default RecentChanges;