Changing Archive Sync to Update and Alternatives to History.

This commit is contained in:
Roland 2022-11-14 15:42:57 -07:00
parent a17eb6559e
commit 11bd59cec0
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
7 changed files with 51 additions and 53 deletions

View file

@ -411,7 +411,7 @@ export async function getArchive(archiveId) {
const response = await apiGet(`${ARCHIVES_API}/${archiveId}`);
if (response.status === 200) {
const data = await response.json();
return [data['file'], data['alternatives']];
return [data['file'], data['history']];
} else {
toast({
type: 'error', title: 'Archive Error', description: 'Unable to get Archive. See server logs.', time: 5000,

View file

@ -41,10 +41,10 @@ import {Button, CardIcon, Header, Loader, Placeholder, Segment, Table} from "./T
function ArchivePage() {
const [deleteOpen, setDeleteOpen] = useState(false);
const [syncOpen, setSyncOpen] = useState(false);
const [updateOpen, setUpdateOpen] = useState(false);
const navigate = useNavigate();
const {archiveId} = useParams();
const {archiveFile, alternatives} = useArchive(archiveId);
const {archiveFile, history} = useArchive(archiveId);
let title;
if (archiveFile && archiveFile.archive) {
@ -85,19 +85,19 @@ function ArchivePage() {
await deleteArchives([archive.id]);
navigate(-1);
}
const localSyncArchive = async () => {
setSyncOpen(false);
const localUpdateArchive = async () => {
setUpdateOpen(false);
await postDownload(archive.url, 'archive');
}
const syncButton = (<>
<Button color='yellow' onClick={() => setSyncOpen(true)} content='Sync'/>
const updateButton = (<>
<Button color='yellow' onClick={() => setUpdateOpen(true)} content='Update'/>
<Confirm
open={syncOpen}
open={updateOpen}
content='Download the latest version of this URL?'
confirmButton='Sync'
onCancel={() => setSyncOpen(false)}
onConfirm={localSyncArchive}
confirmButton='Update'
onCancel={() => setUpdateOpen(false)}
onConfirm={localUpdateArchive}
/>
</>);
const deleteButton = (<>
@ -111,11 +111,11 @@ function ArchivePage() {
/>
</>);
let alternativesList = <Loader active/>;
if (!isEmpty(alternatives)) {
alternativesList = <FileCards files={alternatives}/>;
} else if (isEmpty(alternatives)) {
alternativesList = <p>No alternatives available</p>;
let historyList = <Loader active/>;
if (!isEmpty(history)) {
historyList = <FileCards files={history}/>;
} else if (isEmpty(history)) {
historyList = <p>No history available</p>;
}
const domain = archive.domain ? archive.domain.domain : null;
@ -153,16 +153,16 @@ function ArchivePage() {
{singlefileButton}
{readabilityLink}
{syncButton}
{updateButton}
{deleteButton}
</Segment>
<Segment>
<HelpHeader
headerContent='Alternatives'
popupContent='Alternative archives are archives that have the same URL.'
headerContent='History'
popupContent='Other archives of this URL created at different times.'
/>
{alternativesList}
{historyList}
</Segment>
</>
)

View file

@ -81,13 +81,13 @@ export const useDomains = () => {
export const useArchive = (archiveId) => {
const [archiveFile, setArchiveFile] = useState(null);
const [alternatives, setAlternatives] = useState(null);
const [history, setHistory] = useState(null);
const fetchArchive = async () => {
try {
const [file, alt] = await getArchive(archiveId);
const [file, history] = await getArchive(archiveId);
setArchiveFile(file);
setAlternatives(alt);
setHistory(history);
} catch (e) {
console.error(e);
setArchiveFile(undefined);
@ -98,7 +98,7 @@ export const useArchive = (archiveId) => {
fetchArchive();
}, [archiveId]);
return {archiveFile, alternatives};
return {archiveFile, history};
}
export const useQuery = () => {