|
@@ -1,20 +1,23 @@
|
|
|
-import React from 'react';
|
|
|
|
|
|
|
+import React, {
|
|
|
|
|
+ useCallback, useEffect, useState,
|
|
|
|
|
+} from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
-import { withTranslation } from 'react-i18next';
|
|
|
|
|
|
|
+import { useTranslation, withTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
import { UserPicture } from '@growi/ui';
|
|
import { UserPicture } from '@growi/ui';
|
|
|
import { DevidedPagePath } from '@growi/core';
|
|
import { DevidedPagePath } from '@growi/core';
|
|
|
|
|
+
|
|
|
import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink';
|
|
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 loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
import LinkedPagePath from '~/models/linked-page-path';
|
|
import LinkedPagePath from '~/models/linked-page-path';
|
|
|
|
|
|
|
|
import FootstampIcon from '../FootstampIcon';
|
|
import FootstampIcon from '../FootstampIcon';
|
|
|
|
|
|
|
|
-import { withUnstatedContainers } from '../UnstatedUtils';
|
|
|
|
|
-import AppContainer from '~/client/services/AppContainer';
|
|
|
|
|
-import { toastError } from '~/client/util/apiNotification';
|
|
|
|
|
|
|
|
|
|
import FormattedDistanceDate from '../FormattedDistanceDate';
|
|
import FormattedDistanceDate from '../FormattedDistanceDate';
|
|
|
|
|
|
|
@@ -119,17 +122,82 @@ function SmallPageItem({ page }) {
|
|
|
SmallPageItem.propTypes = {
|
|
SmallPageItem.propTypes = {
|
|
|
page: PropTypes.any,
|
|
page: PropTypes.any,
|
|
|
};
|
|
};
|
|
|
-class RecentChanges extends React.Component {
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+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 (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <div className="grw-sidebar-content-header p-3 d-flex">
|
|
|
|
|
+ <h3 className="mb-0 text-nowrap">{t('Recent Changes')}</h3>
|
|
|
|
|
+ <button type="button" className="btn btn-sm ml-auto grw-btn-reload" onClick={() => mutate()}>
|
|
|
|
|
+ <i className="icon icon-reload"></i>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <div className="d-flex align-items-center">
|
|
|
|
|
+ <div className="grw-recent-changes-resize-button custom-control custom-switch ml-1">
|
|
|
|
|
+ <input
|
|
|
|
|
+ id="recentChangesResize"
|
|
|
|
|
+ className="custom-control-input"
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ checked={isRecentChangesSidebarSmall}
|
|
|
|
|
+ onChange={changeSizeHandler}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="custom-control-label" htmlFor="recentChangesResize">
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="grw-sidebar-content-body grw-recent-changes p-3">
|
|
|
|
|
+ <ul className="list-group list-group-flush">
|
|
|
|
|
+ {(pages || []).map(page => (isRecentChangesSidebarSmall
|
|
|
|
|
+ ? <SmallPageItem key={page._id} page={page} />
|
|
|
|
|
+ : <LargePageItem key={page._id} page={page} />))}
|
|
|
|
|
+ </ul>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </>
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// export default RecentChanges;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class DeprecatedRecentChanges extends React.Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
static propTypes = {
|
|
|
t: PropTypes.func.isRequired, // i18next
|
|
t: PropTypes.func.isRequired, // i18next
|
|
|
- appContainer: PropTypes.instanceOf(AppContainer).isRequired,
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
this.state = {
|
|
this.state = {
|
|
|
isRecentChangesSidebarSmall: false,
|
|
isRecentChangesSidebarSmall: false,
|
|
|
|
|
+ recentlyUpdatedPages: [],
|
|
|
};
|
|
};
|
|
|
this.reloadData = this.reloadData.bind(this);
|
|
this.reloadData = this.reloadData.bind(this);
|
|
|
}
|
|
}
|
|
@@ -143,10 +211,9 @@ class RecentChanges extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async reloadData() {
|
|
async reloadData() {
|
|
|
- const { appContainer } = this.props;
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
- await appContainer.retrieveRecentlyUpdated();
|
|
|
|
|
|
|
+ const { data } = await apiv3Get('/pages/recent');
|
|
|
|
|
+ this.setState({ recentlyUpdatedPages: data.pages });
|
|
|
}
|
|
}
|
|
|
catch (error) {
|
|
catch (error) {
|
|
|
logger.error('failed to save', error);
|
|
logger.error('failed to save', error);
|
|
@@ -171,32 +238,30 @@ class RecentChanges extends React.Component {
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const { t } = this.props;
|
|
const { t } = this.props;
|
|
|
- const { recentlyUpdatedPages } = this.props.appContainer.state;
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<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>
|
|
|
|
|
- <button type="button" className="btn btn-sm ml-auto grw-btn-reload" onClick={this.reloadData}>
|
|
|
|
|
|
|
+ <h3 className="mb-0">{t('Recent Changes')}</h3>
|
|
|
|
|
+ {/* <h3 className="mb-0">{t('Recent Created')}</h3> */} {/* TODO: impl switching */}
|
|
|
|
|
+ <button type="button" className="btn btn-sm ml-auto grw-btn-reload-rc" onClick={this.reloadData}>
|
|
|
<i className="icon icon-reload"></i>
|
|
<i className="icon icon-reload"></i>
|
|
|
</button>
|
|
</button>
|
|
|
- <div className="d-flex align-items-center">
|
|
|
|
|
- <div className="grw-recent-changes-resize-button custom-control custom-switch ml-1">
|
|
|
|
|
- <input
|
|
|
|
|
- id="recentChangesResize"
|
|
|
|
|
- className="custom-control-input"
|
|
|
|
|
- type="checkbox"
|
|
|
|
|
- checked={this.state.isRecentChangesSidebarSmall}
|
|
|
|
|
- onChange={this.changeSizeHandler}
|
|
|
|
|
- />
|
|
|
|
|
- <label className="custom-control-label" htmlFor="recentChangesResize">
|
|
|
|
|
- </label>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <div className="grw-recent-changes-resize-button custom-control custom-switch ml-2">
|
|
|
|
|
+ <input
|
|
|
|
|
+ id="recentChangesResize"
|
|
|
|
|
+ className="custom-control-input"
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ checked={this.state.isRecentChangesSidebarSmall}
|
|
|
|
|
+ onChange={this.changeSizeHandler}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="custom-control-label" htmlFor="recentChangesResize">
|
|
|
|
|
+ </label>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div className="grw-sidebar-content-body grw-recent-changes p-3">
|
|
<div className="grw-sidebar-content-body grw-recent-changes p-3">
|
|
|
<ul className="list-group list-group-flush">
|
|
<ul className="list-group list-group-flush">
|
|
|
- {recentlyUpdatedPages.map(page => (this.state.isRecentChangesSidebarSmall
|
|
|
|
|
|
|
+ {this.state.recentlyUpdatedPages.map(page => (this.state.isRecentChangesSidebarSmall
|
|
|
? <SmallPageItem key={page._id} page={page} />
|
|
? <SmallPageItem key={page._id} page={page} />
|
|
|
: <LargePageItem key={page._id} page={page} />))}
|
|
: <LargePageItem key={page._id} page={page} />))}
|
|
|
</ul>
|
|
</ul>
|
|
@@ -207,10 +272,5 @@ class RecentChanges extends React.Component {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * Wrapper component for using unstated
|
|
|
|
|
- */
|
|
|
|
|
-const RecentChangesWrapper = withUnstatedContainers(RecentChanges, [AppContainer]);
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-export default withTranslation()(RecentChangesWrapper);
|
|
|
|
|
|
|
+export default withTranslation()(DeprecatedRecentChanges);
|