import React, { useCallback, useEffect, useState, } from 'react'; import PropTypes from 'prop-types'; import { useTranslation, withTranslation } from 'react-i18next'; import { UserPicture, FootstampIcon } from '@growi/ui'; import { DevidedPagePath } from '@growi/core'; import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink'; import { apiv3Get } from '~/client/util/apiv3-client'; import { toastError } from '~/client/util/apiNotification'; import { useSWRxRecentlyUpdated } from '~/stores/page'; import loggerFactory from '~/utils/logger'; import LinkedPagePath from '~/models/linked-page-path'; 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; const tagElements = 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 = () => { const { t } = useTranslation(); const { data: pages, error, mutate } = useSWRxRecentlyUpdated(); if (error != null) { toastError(error, 'Error occurred in updating History'); } 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; class DeprecatedRecentChanges extends React.Component { static propTypes = { t: PropTypes.func.isRequired, // i18next }; constructor(props) { super(props); this.state = { isRecentChangesSidebarSmall: false, recentlyUpdatedPages: [], }; this.reloadData = this.reloadData.bind(this); } componentWillMount() { this.retrieveSizePreferenceFromLocalStorage(); } async componentDidMount() { this.reloadData(); } async reloadData() { try { const { data } = await apiv3Get('/pages/recent'); this.setState({ recentlyUpdatedPages: data.pages }); } catch (error) { logger.error('failed to save', error); toastError(error, 'Error occurred in updating History'); } } retrieveSizePreferenceFromLocalStorage() { if (window.localStorage.isRecentChangesSidebarSmall === 'true') { this.setState({ isRecentChangesSidebarSmall: true, }); } } changeSizeHandler = (e) => { this.setState({ isRecentChangesSidebarSmall: e.target.checked, }); window.localStorage.setItem('isRecentChangesSidebarSmall', e.target.checked); } render() { const { t } = this.props; return ( <>

    {t('Recent Changes')}

    {/*

    {t('Recent Created')}

    */} {/* TODO: impl switching */}
      {this.state.recentlyUpdatedPages.map(page => (this.state.isRecentChangesSidebarSmall ? : ))}
    ); } } export default withTranslation()(DeprecatedRecentChanges);