mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 14:04:50 +00:00
fix(webui): address code review feedback for updateLocalCache
This commit is contained in:
@@ -40,11 +40,21 @@ export function useFileSystemDnd({
|
|||||||
queryKey: queryKeyPrefix,
|
queryKey: queryKeyPrefix,
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const [queryKey, oldData] of queries) {
|
const isSearchSort = (val: unknown): val is SearchSort => {
|
||||||
if (!oldData) continue
|
if (typeof val !== 'object' || val === null) return false
|
||||||
|
const obj = val as Record<string, unknown>
|
||||||
|
return (
|
||||||
|
'field' in obj &&
|
||||||
|
'order' in obj &&
|
||||||
|
typeof obj.field === 'string' &&
|
||||||
|
(obj.order === 'asc' || obj.order === 'desc')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const sort = queryKey[5] as SearchSort | undefined
|
for (const [queryKey, oldData] of queries) {
|
||||||
const isDesc = sort?.order === 'desc'
|
if (!oldData || !Array.isArray(oldData.pages)) continue
|
||||||
|
|
||||||
|
const sort = queryKey.find(isSearchSort)
|
||||||
|
|
||||||
const allItems = oldData.pages.flatMap((page) => page.data ?? [])
|
const allItems = oldData.pages.flatMap((page) => page.data ?? [])
|
||||||
|
|
||||||
@@ -55,13 +65,19 @@ export function useFileSystemDnd({
|
|||||||
|
|
||||||
allItems[itemIndex] = { ...allItems[itemIndex], ...updatedItem }
|
allItems[itemIndex] = { ...allItems[itemIndex], ...updatedItem }
|
||||||
|
|
||||||
allItems.sort((a, b) => {
|
if (sort?.field === 'custom') {
|
||||||
const indexA = a.sortIndex ?? ''
|
const isDesc = sort.order === 'desc'
|
||||||
const indexB = b.sortIndex ?? ''
|
allItems.sort((a, b) => {
|
||||||
if (indexA === indexB) return 0
|
const indexA = a.sortIndex ?? ''
|
||||||
const comp = indexA.localeCompare(indexB)
|
const indexB = b.sortIndex ?? ''
|
||||||
return isDesc ? -comp : comp
|
if (indexA === indexB) return 0
|
||||||
})
|
if (isDesc) {
|
||||||
|
return indexA < indexB ? 1 : -1
|
||||||
|
} else {
|
||||||
|
return indexA < indexB ? -1 : 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
let pointer = 0
|
let pointer = 0
|
||||||
const newPages = oldData.pages.map((page) => {
|
const newPages = oldData.pages.map((page) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user