Preventing double-search when order is changed on page switch.

This commit is contained in:
Roland 2023-04-12 16:09:09 -06:00
parent 5e206fd9a2
commit f33dc31111
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
6 changed files with 15 additions and 24 deletions

View file

@ -354,16 +354,6 @@ function Archives() {
const [deleteOpen, setDeleteOpen] = useState(false);
useTitle('Archives');
const {searchParams} = useQuery();
let searchOrder = '-date';
if (searchParams.get('order')) {
// Use whatever order the user specified.
searchOrder = searchParams.get('order');
} else if (searchParams.get('q')) {
// User used a search_str
searchOrder = defaultSearchOrder;
}
const {
archives,

View file

@ -976,13 +976,13 @@ export function SortButton({sorts = []}) {
console.error('No sorts have been defined!');
}
// Use the order in the URL query, fallback to the first in the orders array.
const defaultDesc = sort ? sort.startsWith('-') : true;
const defaultSort = sort ? sort.replaceAll(/^-/g, '') : sorts[0]['value'];
const [localSort, setLocalSort] = useState(defaultSort);
const [localSort, setLocalSort] = useState(sort ? sort.replaceAll(/^-/g, '') : null);
const [desc, setDesc] = useState(sort ? sort.startsWith('-') : true);
const [open, setOpen] = useState(false);
const [desc, setDesc] = useState(defaultDesc);
// Remove the - from the front of the query sort, it will be added when toggling direction.
const sortKey = localSort ? localSort.replaceAll(/^-/g, '') : sorts[0]['value'];
const selectedSort = sorts.find(i => i['value'] === sortKey);
useEffect(() => {
if (localSort) {
@ -999,6 +999,10 @@ export function SortButton({sorts = []}) {
const toggleDesc = () => {
setDesc(!desc);
if (!localSort) {
// No sort in URL, use the first.
setLocalSort(sorts[0]['value']);
}
setOpen(false);
}
@ -1009,10 +1013,6 @@ export function SortButton({sorts = []}) {
})
}
// Remove the - from the front of the query sort.
const sortKey = localSort.replaceAll(/^-/g, '');
const selectedSort = sorts.find(i => i['value'] === sortKey);
return <>
<Modal closeIcon
open={open}

View file

@ -502,7 +502,7 @@ export function FilesRefreshProgress() {
if (refreshing) {
// Default is Counting / Step 1. Move progress bar toward the middle to avoid clipping out of the screen.
let params = {value: Math.floor(counted_files / 5), total: counted_files, progress: 'ratio'};
let params = {value: Math.floor(counted_files / 2), total: counted_files, progress: 'ratio'};
let label = 'Refresh: Counting';
if (discovery) {

View file

@ -760,6 +760,6 @@ export const useSearchView = () => {
}
export const useSearchOrder = () => {
const [order, setOrder] = useOneQuery('order');
return {sort: order, setSort: setOrder}
const [sort, setSort] = useOneQuery('order');
return {sort, setSort}
}

View file

@ -860,6 +860,7 @@ def get_refresh_progress():
FROM file_group
''')
results = dict(curs.fetchone())
# TODO counts are wrong if we are not refreshing all files.
status = dict(
counted_files=REFRESH.get('counted_files', 0),

View file

@ -397,7 +397,7 @@ async def get_tags_request(_: Request):
@openapi.definition(
summary='Create or update a Tag',
)
async def post_new_tag(_: Request, body: schema.TagRequest, tag_id: int = None):
async def post_tag(_: Request, body: schema.TagRequest, tag_id: int = None):
tags.upsert_tag(body.name, body.color, tag_id)
if tag_id:
return response.empty(HTTPStatus.OK)