Lets a removal made by mistake be undone before the item leaves the list, by timing the fade-out of items leaving a list.
Returns the class a fading card takes in phase, for DumpCard's
className, or undefined for a card that isn't fading.
Returns the fading state of a list's items and the calls that drive it.
onFaded is called with an item whose fade ran to its end, for the list to
drop it; a cancelled fade doesn't call it. The timers are cleared on
unmount.
Returned by useFading to useUpvotedList and usePlaylist. The
list keeps showing an item while it is in fading.
-
cancelAll: () => void
Called when the list is replaced, as by another user's upvotes.
-
cancelFading: (id: string) => void
Called when the removal is undone, so that the item stays.
- fading: Record<string, FadeState>
-
startFading: (id: string) => void
Does nothing when
idis already fading.
Held by useFading for each fading item, and mapped to a CSS class by
fadeClassName. cooldown lasts 2 seconds, and dismissing lasts
the 350ms of the CSS collapse.
Usage
import * as mod from "src/hooks/feed/useFading.ts";