|
@@ -10,10 +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 { useSWRxRecentlyUpdated, 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,13 +121,21 @@ SmallPageItem.propTypes = {
|
|
|
page: PropTypes.any,
|
|
page: PropTypes.any,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+function LoadingIndicator() {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="text-muted text-center">
|
|
|
|
|
+ <i className="fa fa-2x fa-spinner fa-pulse mr-1"></i>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
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 isReachingEnd = swr.data && swr.data[swr.data.length - 1]?.length < PER_PAGE;
|
|
|
|
|
+ const pages = swr.data?.flat()?.filter((item, index) => index === swr.data?.flat().findIndex(page => page._id === item._id));
|
|
|
|
|
|
|
|
const retrieveSizePreferenceFromLocalStorage = useCallback(() => {
|
|
const retrieveSizePreferenceFromLocalStorage = useCallback(() => {
|
|
|
if (window.localStorage.isRecentChangesSidebarSmall === 'true') {
|
|
if (window.localStorage.isRecentChangesSidebarSmall === 'true') {
|
|
@@ -148,7 +157,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,9 +176,18 @@ 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
|
|
|
|
|
+ swr={swr}
|
|
|
|
|
+ loadingIndicator={<LoadingIndicator />}
|
|
|
|
|
+ isReachingEnd={isReachingEnd}
|
|
|
|
|
+ >
|
|
|
|
|
+ {pages?.map(page => (
|
|
|
|
|
+ isRecentChangesSidebarSmall
|
|
|
|
|
+ ? <SmallPageItem key={page._id} page={page} />
|
|
|
|
|
+ : <LargePageItem key={page._id} page={page} />
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ </InfiniteScroll>
|
|
|
</ul>
|
|
</ul>
|
|
|
</div>
|
|
</div>
|
|
|
</>
|
|
</>
|