From 4719dea2d46edded36013fb5d0b7f6654706f601 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Mon, 3 Feb 2020 12:40:36 +0000 Subject: [PATCH] Update edit history frontend --- app/src/frontend/pages/changes.css | 7 +++ app/src/frontend/pages/changes.tsx | 75 +++++++++++++++++++++++++++--- app/src/frontend/styles/layout.css | 5 ++ 3 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 app/src/frontend/pages/changes.css diff --git a/app/src/frontend/pages/changes.css b/app/src/frontend/pages/changes.css new file mode 100644 index 00000000..9ee45613 --- /dev/null +++ b/app/src/frontend/pages/changes.css @@ -0,0 +1,7 @@ +.edit-history-link { + margin-top: 4em; +} + +.edit-history-latest-link { + float: right; +} \ No newline at end of file diff --git a/app/src/frontend/pages/changes.tsx b/app/src/frontend/pages/changes.tsx index 6f0d7cc5..01af54d5 100644 --- a/app/src/frontend/pages/changes.tsx +++ b/app/src/frontend/pages/changes.tsx @@ -1,31 +1,88 @@ +import { parse } from 'query-string'; import React, { useEffect, useState } from 'react'; +import { Link, RouteComponentProps } from 'react-router-dom'; + +import './changes.css'; import { apiGet } from '../apiHelpers'; import { BuildingEditSummary } from '../building/edit-history/building-edit-summary'; +import ErrorBox from '../components/error-box'; import InfoBox from '../components/info-box'; import { EditHistoryEntry } from '../models/edit-history-entry'; -const ChangesPage = () => { - const [history, setHistory] = useState(undefined); +interface PagingInfo { + 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(); + const [paging, setPaging] = useState(); + const [error, setError] = useState(); useEffect(() => { 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(); - }, []); + }, [props.location.search]); return (

Global edit history

+ { + paging?.id_for_newer_query && + Show more recent changes + } + { + (after_id || before_id) && + Show latest changes + }
    - {(history == undefined || history.length == 0) ? - : + { + error && + + } + { + error == undefined && history == undefined && + + } + { + (history?.length === 0) && + + } + { + (history != undefined && history.length > 0) && history.map(entry => (
  • { )) }
+ { + paging?.id_for_older_query && + Show older changes + }
); diff --git a/app/src/frontend/styles/layout.css b/app/src/frontend/styles/layout.css index bf7951ba..f1624c6b 100644 --- a/app/src/frontend/styles/layout.css +++ b/app/src/frontend/styles/layout.css @@ -49,6 +49,11 @@ article .color-block { padding-left: 1em; padding-right: 1em; } +@media(min-width: 768px) { + .main-col { + min-width: 48em; + } +} hr { display: block; height: 1px;