feat: jump to my newly created particle once created

This commit is contained in:
talksik
2026-03-24 10:27:50 -07:00
parent 1fb31a0d04
commit 6f033e2a73
3 changed files with 25 additions and 2 deletions
+10
View File
@@ -86,6 +86,7 @@ interface UseStreamPlaybackResult {
next: () => void;
prev: () => void;
goTo: (index: number) => void;
goToParticle: (particleId: string) => void;
pause: () => void;
resume: () => void;
}
@@ -212,6 +213,14 @@ export function useStreamPlayback(
[children],
);
// NOTE: if particle doesn't exist in children, this will lead to a brief moment where currentParticle is null
const goToParticle = useCallback(
(particleId: string) => {
// Dispatch directly by ID — if the particle isn't in children yet
// (e.g. just created), it will resolve once the live query delivers it.
dispatch({ type: "SET_PARTICLE", particleId });
}, []);
const pause = useCallback(() => dispatch({ type: "PAUSE" }), []);
const resume = useCallback(() => dispatch({ type: "RESUME" }), []);
@@ -225,6 +234,7 @@ export function useStreamPlayback(
next,
prev,
goTo,
goToParticle,
pause,
resume,
};