From 3f08bce9eaafdbe3d57930e6f5dccefc7b559591 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 2 Feb 2022 14:02:51 -0700 Subject: [PATCH] Removing consolidated hook because values were not being passed up. --- app/src/api.js | 35 ++++++++++++-- app/src/components/Admin.js | 6 +-- app/src/components/Archive.js | 16 +++---- app/src/components/Common.js | 21 ++++----- app/src/components/Files.js | 4 +- app/src/components/Inventory.js | 4 +- app/src/components/Nav.js | 24 +++++----- app/src/components/Videos.js | 8 ++-- app/src/hooks/customHooks.js | 82 ++++++++++++++------------------- modules/files/lib.py | 2 + modules/files/models.py | 2 +- 11 files changed, 106 insertions(+), 98 deletions(-) diff --git a/app/src/api.js b/app/src/api.js index e410a8e2..0cf521b2 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -1,4 +1,4 @@ -import {API_URI, ARCHIVES_API, DEFAULT_LIMIT, OTP_API, VIDEOS_API} from "./components/Common"; +import {API_URI, ARCHIVES_API, DEFAULT_LIMIT, OTP_API, secondsToDateTime, VIDEOS_API} from "./components/Common"; import {toast} from 'react-semantic-toasts'; function timeoutPromise(ms, promise) { @@ -303,8 +303,8 @@ export async function deleteArchive(archive_id) { export async function searchArchives(offset, limit, domain = null, searchStr = null) { // Build a search query to retrieve a list of videos from the API - offset = offset || 0; - limit = limit || DEFAULT_LIMIT; + offset = parseInt(offset || 0); + limit = parseInt(limit || DEFAULT_LIMIT); let body = {offset, limit}; if (domain) { body['domain'] = domain; @@ -372,10 +372,33 @@ export async function getDownloaders() { return await response.json(); } +const replaceFileDatetimes = (files) => { + for (let i = 0; i < files.length; i++) { + let file = files[i]['modified']; + if (file['modified']) { + files[i]['modified'] = secondsToDateTime(file['modified']); + } + } + return files; +} + export async function filesSearch(offset, limit, searchStr) { const body = {search_str: searchStr, offset: parseInt(offset), limit: parseInt(limit)}; const response = await apiPost(`${API_URI}/files/search`, body); - return await response.json(); + + if (response.status === 200) { + let data = await response.json(); + let [files, total] = [data['files'], data['totals']['files']]; + files = replaceFileDatetimes(files); + return [files, total]; + } else { + toast({ + type: 'error', + title: 'Unable to search files', + description: 'Cannot search files. See server logs.', + time: 5000, + }); + } } export async function refreshFiles() { @@ -385,7 +408,9 @@ export async function refreshFiles() { export async function getFiles(directories) { let body = {directories: directories || []}; let response = await apiPost(`${API_URI}/files`, body); - return await response.json(); + let {files} = await response.json(); + files = replaceFileDatetimes(files); + return files; } export async function deleteFile(file) { diff --git a/app/src/components/Admin.js b/app/src/components/Admin.js index 22687488..811c10f2 100644 --- a/app/src/components/Admin.js +++ b/app/src/components/Admin.js @@ -443,9 +443,9 @@ class Downloads extends React.Component { export default function Admin(props) { const links = [ - {text: 'Downloads', to: '/admin', exact: true}, - {text: 'Settings', to: '/admin/settings'}, - {text: 'WROL Mode', to: '/admin/wrol'}, + {text: 'Downloads', to: '/admin', exact: true, key: 'admin'}, + {text: 'Settings', to: '/admin/settings', key: 'settings'}, + {text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'}, ]; return ( diff --git a/app/src/components/Archive.js b/app/src/components/Archive.js index 6e0bd981..c36de3fb 100644 --- a/app/src/components/Archive.js +++ b/app/src/components/Archive.js @@ -4,7 +4,8 @@ import { CardGroupCentered, ClearButton, ExternalLink, - PageContainer, Paginator, + PageContainer, + Paginator, SearchInput, TabLinks, textEllipsis, @@ -202,9 +203,8 @@ export function ArchivesList({archives, searchStr, syncArchive, localDeleteArchi } export function Archives() { - const {archivesData, setPage, totalPages, searchStr, activePage, setSearchStr, domain, setDomain, search} = - useArchives(); - const {archives} = archivesData; + const {archives, setPage, totalPages, searchStr, activePage, setSearchStr, domain, setDomain, search} = + useArchives(20); const syncArchive = async (url) => { await postDownload(url, 'archive'); @@ -237,7 +237,7 @@ export function Archives() { setDomain={setDomain} />
- +
) @@ -319,9 +319,9 @@ function Domains() { export function ArchiveRoute(props) { const links = [ - {text: 'Archives', to: '/archive', exact: true}, - {text: 'Domains', to: '/archive/domains'}, - {text: 'Manage', to: '/archive/manage'}, + {text: 'Archives', to: '/archive', exact: true, key: 'archive'}, + {text: 'Domains', to: '/archive/domains', key: 'domains'}, + {text: 'Manage', to: '/archive/manage', key: 'manage'}, ]; return diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 6683d7ee..cd6f2e8a 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -5,7 +5,6 @@ import Button from "semantic-ui-react/dist/commonjs/elements/Button"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import Message from "semantic-ui-react/dist/commonjs/collections/Message"; import {getConfig} from "../api"; -import {useSearchParams} from "../hooks/customHooks"; export const API_URI = `http://${window.location.host}/api`; export const VIDEOS_API = `${API_URI}/videos`; @@ -55,26 +54,21 @@ export default class OldPaginator extends React.Component { } } -export function Paginator(props) { - let {activePage, setPage} = useSearchParams(props.defaultLimit || 20); - - const handlePaginationChange = (e, {activePage}) => { - setPage(activePage); +export function Paginator({activePage, onPageChange, totalPages, showFirstAndLast}) { + const handlePageChange = (e, {activePage}) => { + onPageChange(activePage); } return ( ) } @@ -607,6 +601,7 @@ export function TabLinks({links}) { className={'item'} exact={link.exact || false} style={{padding: '1em'}} + key={link.key} > {link.text} diff --git a/app/src/components/Files.js b/app/src/components/Files.js index 5fb86270..e40f5949 100644 --- a/app/src/components/Files.js +++ b/app/src/components/Files.js @@ -15,7 +15,7 @@ const icons = { PDF: , }; -export function Files(props) { +export function Files() { const {searchFiles, setPage, totalPages, activePage, searchStr, setSearchStr} = useSearchFiles(50); const {browseFiles, setOpenFolders, fetchFiles} = useBrowseFiles(); @@ -127,7 +127,7 @@ export function Files(props) { } -function ManageFiles(props) { +function ManageFiles() { return (<>