clean-up #15
@@ -16,6 +16,8 @@ interface Props {
|
|||||||
onClose: () => void
|
onClose: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HISTORY_CAP = 100
|
||||||
|
|
||||||
function pickRandom(items: DoomScrollItem[], excludeRecent: DoomScrollItem[]): DoomScrollItem {
|
function pickRandom(items: DoomScrollItem[], excludeRecent: DoomScrollItem[]): DoomScrollItem {
|
||||||
const excludeCount = Math.min(excludeRecent.length, items.length - 1)
|
const excludeCount = Math.min(excludeRecent.length, items.length - 1)
|
||||||
const recentUrls = new Set(excludeRecent.slice(-excludeCount).map((i) => i.url))
|
const recentUrls = new Set(excludeRecent.slice(-excludeCount).map((i) => i.url))
|
||||||
@@ -55,9 +57,9 @@ export default function DoomScrollView({ items, videoContext = 'mixed', onClose
|
|||||||
const next = pickRandom(items, history)
|
const next = pickRandom(items, history)
|
||||||
setHistory((h) => {
|
setHistory((h) => {
|
||||||
const updated = [...h, next]
|
const updated = [...h, next]
|
||||||
return updated.length > 100 ? updated.slice(-100) : updated
|
return updated.length > HISTORY_CAP ? updated.slice(-HISTORY_CAP) : updated
|
||||||
})
|
})
|
||||||
return idx + 1
|
return Math.min(idx + 1, HISTORY_CAP - 1)
|
||||||
})
|
})
|
||||||
}, [items, history])
|
}, [items, history])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user