Update edit history frontend
This commit is contained in:
parent
aa43ab7711
commit
4719dea2d4
7
app/src/frontend/pages/changes.css
Normal file
7
app/src/frontend/pages/changes.css
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.edit-history-link {
|
||||||
|
margin-top: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-history-latest-link {
|
||||||
|
float: right;
|
||||||
|
}
|
@ -1,31 +1,88 @@
|
|||||||
|
import { parse } from 'query-string';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { Link, RouteComponentProps } from 'react-router-dom';
|
||||||
|
|
||||||
|
import './changes.css';
|
||||||
|
|
||||||
import { apiGet } from '../apiHelpers';
|
import { apiGet } from '../apiHelpers';
|
||||||
import { BuildingEditSummary } from '../building/edit-history/building-edit-summary';
|
import { BuildingEditSummary } from '../building/edit-history/building-edit-summary';
|
||||||
|
import ErrorBox from '../components/error-box';
|
||||||
import InfoBox from '../components/info-box';
|
import InfoBox from '../components/info-box';
|
||||||
import { EditHistoryEntry } from '../models/edit-history-entry';
|
import { EditHistoryEntry } from '../models/edit-history-entry';
|
||||||
|
|
||||||
const ChangesPage = () => {
|
interface PagingInfo {
|
||||||
const [history, setHistory] = useState<EditHistoryEntry[]>(undefined);
|
id_for_older_query: string;
|
||||||
|
id_for_newer_query: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const recordsPerPage = 20;
|
||||||
|
|
||||||
|
const ChangesPage = (props: RouteComponentProps) => {
|
||||||
|
const { after_id, before_id } = parse(props.location.search);
|
||||||
|
|
||||||
|
const [history, setHistory] = useState<EditHistoryEntry[]>();
|
||||||
|
const [paging, setPaging] = useState<PagingInfo>();
|
||||||
|
const [error, setError] = useState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
const {history} = await apiGet(`/api/history`);
|
setHistory(null);
|
||||||
|
setPaging(null);
|
||||||
|
|
||||||
|
let url = `/api/history?count=${recordsPerPage}`;
|
||||||
|
if(after_id) {
|
||||||
|
url = `${url}&after_id=${after_id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (before_id) {
|
||||||
|
url = `${url}&before_id=${before_id}`;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const {history, paging, error} = await apiGet(url);
|
||||||
|
|
||||||
|
if(error) {
|
||||||
|
setError(error);
|
||||||
|
} else {
|
||||||
|
setHistory(history);
|
||||||
|
setPaging(paging);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError('Connection problem. Please try again later...');
|
||||||
|
}
|
||||||
|
|
||||||
setHistory(history);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, [props.location.search]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article>
|
<article>
|
||||||
<section className="main-col">
|
<section className="main-col">
|
||||||
<h1>Global edit history</h1>
|
<h1>Global edit history</h1>
|
||||||
|
|
||||||
|
{
|
||||||
|
paging?.id_for_newer_query &&
|
||||||
|
<Link className='edit-history-link' to={`?after_id=${paging.id_for_newer_query}`}>Show more recent changes</Link>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
(after_id || before_id) &&
|
||||||
|
<Link className='edit-history-latest-link' to='?'>Show latest changes</Link>
|
||||||
|
}
|
||||||
<ul className="edit-history-list">
|
<ul className="edit-history-list">
|
||||||
{(history == undefined || history.length == 0) ?
|
{
|
||||||
<InfoBox msg="No changes in the last week"></InfoBox> :
|
error &&
|
||||||
|
<ErrorBox msg={error}></ErrorBox>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
error == undefined && history == undefined &&
|
||||||
|
<InfoBox msg="Loading history..."></InfoBox>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
(history?.length === 0) &&
|
||||||
|
<InfoBox msg="No changes so far"></InfoBox>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
(history != undefined && history.length > 0) &&
|
||||||
history.map(entry => (
|
history.map(entry => (
|
||||||
<li key={`${entry.revision_id}`} className="edit-history-list-element">
|
<li key={`${entry.revision_id}`} className="edit-history-list-element">
|
||||||
<BuildingEditSummary
|
<BuildingEditSummary
|
||||||
@ -37,6 +94,10 @@ const ChangesPage = () => {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
|
{
|
||||||
|
paging?.id_for_older_query &&
|
||||||
|
<Link to={`?before_id=${paging.id_for_older_query}`}>Show older changes</Link>
|
||||||
|
}
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
|
@ -49,6 +49,11 @@ article .color-block {
|
|||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
}
|
}
|
||||||
|
@media(min-width: 768px) {
|
||||||
|
.main-col {
|
||||||
|
min-width: 48em;
|
||||||
|
}
|
||||||
|
}
|
||||||
hr {
|
hr {
|
||||||
display: block;
|
display: block;
|
||||||
height: 1px;
|
height: 1px;
|
||||||
|
Loading…
Reference in New Issue
Block a user