Stop a folder wipe from restoring the pre-wipe library catalog.
The in-memory catalog could outlive the write, so delete-all came back as thousands of empty tiles and a stale badge. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,14 +7,58 @@ export function newestOutput(jobs, seen, folderId) {
|
||||
return jobs.filter(j=>j.request.folderId===folderId).flatMap(j=>j.outputs || []).filter(a=>!seen.has(a.id)).sort((a,b)=>(a.studio2?.savedAt || 0)-(b.studio2?.savedAt || 0)).at(-1) || null
|
||||
}
|
||||
export function reconcileSelection(selected, assets) {
|
||||
if (!selected?.id) return assets.at(-1) || null
|
||||
return assets.find(a => a.id === selected.id) || selected
|
||||
const list = assets || []
|
||||
if (!selected?.id) return list.at(-1) || null
|
||||
return list.find(a => a.id === selected.id) || list.at(-1) || null
|
||||
}
|
||||
export function activeJobs(jobs) { return jobs.filter(j=>['waking','enhancing','submitting','rendering','saving'].includes(j.state)) }
|
||||
export function previewHidden(asset, revealed, xaigen) {
|
||||
if (!xaigen || !asset?.id) return false
|
||||
return !revealed?.has?.(asset.id)
|
||||
}
|
||||
/** A reported imageCount of 0 is an empty folder. Do not replace it with a local list length. */
|
||||
export function folderImageCount(folder, localStillCount = 0) {
|
||||
if (folder && typeof folder.imageCount === 'number' && Number.isFinite(folder.imageCount)) return folder.imageCount
|
||||
return Number(localStillCount) || 0
|
||||
}
|
||||
|
||||
/** Replace library rows from a wipe response. Rows already in the wiped folder stay gone. */
|
||||
export function libraryAfterWipe(previous, response, folderId) {
|
||||
const suppressed = new Set(previous?.suppressedIds || [])
|
||||
const target = String(folderId || '')
|
||||
for (const list of [previous?.stills, previous?.clips, previous?.tracks, response?.stills, response?.clips, response?.tracks]) {
|
||||
for (const item of list || []) {
|
||||
if (item?.id && String(item.folderId || '') === target) suppressed.add(item.id)
|
||||
}
|
||||
}
|
||||
const take = (list) => (Array.isArray(list) ? list : []).filter(item => item?.id && !suppressed.has(item.id))
|
||||
return {
|
||||
folders: Array.isArray(response?.folders) ? response.folders : (previous?.folders || []),
|
||||
stills: take(response?.stills),
|
||||
clips: take(response?.clips),
|
||||
tracks: take(response?.tracks),
|
||||
suppressedIds: [...suppressed]
|
||||
}
|
||||
}
|
||||
|
||||
/** Later pages and a stale full list must not put a suppressed id back. */
|
||||
export function mergeLibraryRows(prev, next, suppressedIds) {
|
||||
const drop = new Set(suppressedIds || [])
|
||||
const map = new Map()
|
||||
for (const item of prev || []) {
|
||||
if (item?.id && !drop.has(item.id)) map.set(item.id, item)
|
||||
}
|
||||
for (const item of next || []) {
|
||||
if (item?.id && !drop.has(item.id)) map.set(item.id, item)
|
||||
}
|
||||
return [...map.values()]
|
||||
}
|
||||
|
||||
export function replaceLibraryRows(next, suppressedIds) {
|
||||
const drop = new Set(suppressedIds || [])
|
||||
return (next || []).filter(item => item?.id && !drop.has(item.id))
|
||||
}
|
||||
|
||||
export function selectResult(state, asset) { return {...state,selected:asset} }
|
||||
export function assetLabel(asset) {
|
||||
if (!asset) return 'None'
|
||||
|
||||
Reference in New Issue
Block a user