mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
Preventing double-search when order is changed on page switch.
This commit is contained in:
parent
5e206fd9a2
commit
f33dc31111
6 changed files with 15 additions and 24 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue