mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
Redoing Paginator with custom hook. Keeping Old Paginator for Videos until it is updated with hooks.
This commit is contained in:
parent
643c86e9a4
commit
79f2359e83
5 changed files with 54 additions and 34 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import React, {useState} from "react";
|
||||
import {Card, Confirm, Container, Icon, Image, Placeholder} from "semantic-ui-react";
|
||||
import Paginator, {
|
||||
import {
|
||||
CardGroupCentered,
|
||||
ClearButton,
|
||||
ExternalLink,
|
||||
PageContainer,
|
||||
PageContainer, Paginator,
|
||||
SearchInput,
|
||||
TabLinks,
|
||||
textEllipsis,
|
||||
|
|
@ -237,11 +237,7 @@ export function Archives() {
|
|||
setDomain={setDomain}
|
||||
/>
|
||||
<div style={{marginTop: '3em', textAlign: 'center'}}>
|
||||
<Paginator
|
||||
activePage={activePage}
|
||||
changePage={setPage}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
<Paginator totalPages={totalPages}/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ 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`;
|
||||
|
|
@ -12,7 +13,7 @@ export const ARCHIVES_API = `${API_URI}/archive`;
|
|||
export const OTP_API = `${API_URI}/otp`;
|
||||
export const DEFAULT_LIMIT = 20;
|
||||
|
||||
export default class Paginator extends React.Component {
|
||||
export default class OldPaginator extends React.Component {
|
||||
state = {
|
||||
boundaryRange: 1,
|
||||
siblingRange: 2,
|
||||
|
|
@ -54,6 +55,30 @@ export default class Paginator extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export function Paginator(props) {
|
||||
let {activePage, setPage} = useSearchParams(props.defaultLimit || 20);
|
||||
|
||||
const handlePaginationChange = (e, {activePage}) => {
|
||||
setPage(activePage);
|
||||
}
|
||||
|
||||
return (
|
||||
<Pagination
|
||||
activePage={activePage}
|
||||
boundaryRange={1}
|
||||
onPageChange={handlePaginationChange}
|
||||
size='mini'
|
||||
siblingRange={2}
|
||||
totalPages={props.totalPages}
|
||||
ellipsisItem={true}
|
||||
firstItem={null}
|
||||
lastItem={null}
|
||||
prevItem={true}
|
||||
nextItem={true}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function secondsToDuration(video) {
|
||||
let duration = video.duration;
|
||||
let hours = Math.floor(duration / 3600);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import FileBrowser from 'react-keyed-file-browser';
|
|||
import {Button, Confirm, Header, Icon, Modal} from "semantic-ui-react";
|
||||
import 'react-keyed-file-browser/dist/react-keyed-file-browser.css';
|
||||
import {deleteFile, refreshFiles} from "../api";
|
||||
import Paginator, {humanFileSize, PageContainer, SearchInput, TabLinks} from "./Common";
|
||||
import {Paginator, humanFileSize, PageContainer, SearchInput, TabLinks} from "./Common";
|
||||
import {useBrowseFiles, useSearchFiles} from "../hooks/customHooks";
|
||||
import {Route} from "react-router-dom";
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ const icons = {
|
|||
};
|
||||
|
||||
export function Files(props) {
|
||||
const {searchFiles, setPage, limit, totalPages, activePage, searchStr, setSearchStr} = useSearchFiles(50);
|
||||
const {searchFiles, setPage, totalPages, activePage, searchStr, setSearchStr} = useSearchFiles(50);
|
||||
const {browseFiles, setOpenFolders, fetchFiles} = useBrowseFiles();
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = React.useState(false);
|
||||
|
|
@ -119,7 +119,6 @@ export function Files(props) {
|
|||
/>);
|
||||
}
|
||||
|
||||
console.log('Files', limit);
|
||||
return <>
|
||||
<SearchInput initValue={searchStr} onSubmit={setSearchStr}/>
|
||||
{selectedModal}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import {Link, Route} from "react-router-dom";
|
||||
import Paginator, {
|
||||
import OldPaginator, {
|
||||
changePageHistory,
|
||||
DEFAULT_LIMIT,
|
||||
defaultSearchOrder,
|
||||
|
|
@ -401,7 +401,7 @@ class Videos extends React.Component {
|
|||
if (totalPages) {
|
||||
pagination = (
|
||||
<div style={{marginTop: '3em', textAlign: 'center'}}>
|
||||
<Paginator
|
||||
<OldPaginator
|
||||
activePage={activePage}
|
||||
changePage={this.changePage}
|
||||
totalPages={totalPages}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,23 @@ export const useSearchParam = (key, defaultValue = null) => {
|
|||
return [value, setValue];
|
||||
}
|
||||
|
||||
export const useSearchParams = ({defaultLimit = 20}) => {
|
||||
let [limit, setLimit] = useSearchParam('l', defaultLimit);
|
||||
let [offset, setOffset] = useSearchParam('o');
|
||||
let [searchStr, setSearchStr] = useSearchParam('q');
|
||||
|
||||
let [activePage, setActivePage] = useState(1);
|
||||
|
||||
const setPage = (i) => {
|
||||
i = parseInt(i);
|
||||
let l = parseInt(limit);
|
||||
setOffset((l * i) - l);
|
||||
setActivePage(i);
|
||||
}
|
||||
|
||||
return {limit, setLimit, offset, setOffset, searchStr, setSearchStr, activePage, setPage};
|
||||
}
|
||||
|
||||
export const useSearch = () => {
|
||||
let [searchStr, setSearchStr] = useSearchParam('q');
|
||||
|
||||
|
|
@ -73,17 +90,8 @@ export const useArchives = (defaultLimit = 20) => {
|
|||
const [totalPages, setTotalPages] = useState(0);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
|
||||
let [offset, setOffset] = useSearchParam('o');
|
||||
let [limit, setLimit] = useSearchParam('l', defaultLimit);
|
||||
let {limit, setLimit, offset, setOffset, searchStr, setSearchStr, setPage} = useSearchParams(defaultLimit);
|
||||
let [domain, setDomain] = useSearchParam('domain');
|
||||
let [searchStr, setSearchStr] = useSearchParam('q');
|
||||
|
||||
const setPage = (i) => {
|
||||
i = parseInt(i);
|
||||
let l = parseInt(limit);
|
||||
setOffset((l * i) - l);
|
||||
setActivePage(i);
|
||||
}
|
||||
|
||||
const search = async (term) => {
|
||||
setArchives({archives: null, total: 0});
|
||||
|
|
@ -132,19 +140,11 @@ export const useVersion = () => {
|
|||
}
|
||||
|
||||
export const useSearchFiles = ({defaultLimit = 50}) => {
|
||||
let {limit, setLimit, offset, setOffset, searchStr, setSearchStr, activePage, setPage} =
|
||||
useSearchParams(defaultLimit);
|
||||
|
||||
const [searchFiles, setSearchFiles] = useState([]);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
const [offset, setOffset] = useSearchParam('o');
|
||||
const [limit, setLimit] = useSearchParam('l', defaultLimit);
|
||||
const [searchStr, setSearchStr] = useSearchParam('q');
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
|
||||
const setPage = (i) => {
|
||||
i = parseInt(i);
|
||||
let l = parseInt(limit);
|
||||
setOffset((l * i) - l);
|
||||
setActivePage(i);
|
||||
}
|
||||
|
||||
const localSearchFiles = async () => {
|
||||
setSearchFiles([]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue