mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
refactor: optimize sorting logic in DocumentsSidebar by utilizing refs for current sort state, enhancing performance and clarity
This commit is contained in:
parent
889af57d3f
commit
376f120502
1 changed files with 16 additions and 7 deletions
|
|
@ -270,15 +270,24 @@ export function DocumentsSidebar({ open, onOpenChange }: DocumentsSidebarProps)
|
|||
[deleteDocumentMutation, isSearchMode, t]
|
||||
);
|
||||
|
||||
const sortKeyRef = useRef(sortKey);
|
||||
const sortDescRef = useRef(sortDesc);
|
||||
sortKeyRef.current = sortKey;
|
||||
sortDescRef.current = sortDesc;
|
||||
|
||||
const handleSortChange = useCallback((key: SortKey) => {
|
||||
setSortKey((currentKey) => {
|
||||
if (currentKey === key) {
|
||||
setSortDesc((v) => !v);
|
||||
return currentKey;
|
||||
}
|
||||
const currentKey = sortKeyRef.current;
|
||||
const currentDesc = sortDescRef.current;
|
||||
|
||||
if (currentKey === key && currentDesc) {
|
||||
setSortKey("created_at");
|
||||
setSortDesc(true);
|
||||
} else if (currentKey === key) {
|
||||
setSortDesc(true);
|
||||
} else {
|
||||
setSortKey(key);
|
||||
setSortDesc(false);
|
||||
return key;
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue