|
@@ -10,11 +10,11 @@ import { UserPicture, FootstampIcon } from '@growi/ui';
|
|
|
import { DevidedPagePath } from '@growi/core';
|
|
import { DevidedPagePath } from '@growi/core';
|
|
|
|
|
|
|
|
import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink';
|
|
import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink';
|
|
|
-import { useSWRxRecentlyUpdated } from '~/stores/page';
|
|
|
|
|
|
|
+import { useSWRInifinitexRecentlyUpdated } from '~/stores/page';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
import LinkedPagePath from '~/models/linked-page-path';
|
|
import LinkedPagePath from '~/models/linked-page-path';
|
|
|
-
|
|
|
|
|
|
|
+import InfiniteScroll from './InfiniteScroll';
|
|
|
|
|
|
|
|
import FormattedDistanceDate from '../FormattedDistanceDate';
|
|
import FormattedDistanceDate from '../FormattedDistanceDate';
|
|
|
|
|
|
|
@@ -120,14 +120,13 @@ SmallPageItem.propTypes = {
|
|
|
page: PropTypes.any,
|
|
page: PropTypes.any,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-
|
|
|
|
|
const RecentChanges = (): JSX.Element => {
|
|
const RecentChanges = (): JSX.Element => {
|
|
|
-
|
|
|
|
|
|
|
+ const PER_PAGE = 20;
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
- const { data: pages, mutate } = useSWRxRecentlyUpdated();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const swr = useSWRInifinitexRecentlyUpdated();
|
|
|
const [isRecentChangesSidebarSmall, setIsRecentChangesSidebarSmall] = useState(false);
|
|
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(() => {
|
|
const retrieveSizePreferenceFromLocalStorage = useCallback(() => {
|
|
|
if (window.localStorage.isRecentChangesSidebarSmall === 'true') {
|
|
if (window.localStorage.isRecentChangesSidebarSmall === 'true') {
|
|
|
setIsRecentChangesSidebarSmall(true);
|
|
setIsRecentChangesSidebarSmall(true);
|
|
@@ -148,7 +147,7 @@ const RecentChanges = (): JSX.Element => {
|
|
|
<>
|
|
<>
|
|
|
<div className="grw-sidebar-content-header p-3 d-flex">
|
|
<div className="grw-sidebar-content-header p-3 d-flex">
|
|
|
<h3 className="mb-0 text-nowrap">{t('Recent Changes')}</h3>
|
|
<h3 className="mb-0 text-nowrap">{t('Recent Changes')}</h3>
|
|
|
- <button type="button" className="btn btn-sm ml-auto grw-btn-reload" onClick={() => mutate()}>
|
|
|
|
|
|
|
+ <button type="button" className="btn btn-sm ml-auto grw-btn-reload" onClick={() => swr.mutate()}>
|
|
|
<i className="icon icon-reload"></i>
|
|
<i className="icon icon-reload"></i>
|
|
|
</button>
|
|
</button>
|
|
|
<div className="d-flex align-items-center">
|
|
<div className="d-flex align-items-center">
|
|
@@ -167,14 +166,21 @@ const RecentChanges = (): JSX.Element => {
|
|
|
</div>
|
|
</div>
|
|
|
<div className="grw-recent-changes p-3">
|
|
<div className="grw-recent-changes p-3">
|
|
|
<ul className="list-group list-group-flush">
|
|
<ul className="list-group list-group-flush">
|
|
|
- {(pages || []).map(page => (isRecentChangesSidebarSmall
|
|
|
|
|
- ? <SmallPageItem key={page._id} page={page} />
|
|
|
|
|
- : <LargePageItem key={page._id} page={page} />))}
|
|
|
|
|
|
|
+ <InfiniteScroll
|
|
|
|
|
+ swrInifiniteResponse={swr}
|
|
|
|
|
+ isReachingEnd={isReachingEnd}
|
|
|
|
|
+ >
|
|
|
|
|
+ {pages => pages.map(page => (
|
|
|
|
|
+ isRecentChangesSidebarSmall
|
|
|
|
|
+ ? <SmallPageItem key={page._id} page={page} />
|
|
|
|
|
+ : <LargePageItem key={page._id} page={page} />
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ </InfiniteScroll>
|
|
|
</ul>
|
|
</ul>
|
|
|
</div>
|
|
</div>
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
export default RecentChanges;
|
|
export default RecentChanges;
|