feat: filter to ephemeral streams and particles
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
toFirestoreChildrenPath,
|
||||
} from "@/lib/particle-path";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { QueryFieldFilterConstraint } from "firebase/firestore";
|
||||
|
||||
interface UseLiveParticleResult {
|
||||
particle: Particle | null;
|
||||
@@ -62,6 +63,7 @@ export function useLiveParticleChildren(
|
||||
visibilityScopes?: string[],
|
||||
onAdded?: (child: Particle) => void,
|
||||
onRemoved?: (child: Particle, updatedChildren: Particle[]) => void,
|
||||
whereFilter?: QueryFieldFilterConstraint
|
||||
): UseLiveParticleChildrenResult {
|
||||
const [children, setChildren] = useState<Particle[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
@@ -89,9 +91,11 @@ export function useLiveParticleChildren(
|
||||
orderDirection,
|
||||
onAdded,
|
||||
onRemoved,
|
||||
whereFilter,
|
||||
);
|
||||
|
||||
return unsubscribe;
|
||||
// FIX: do we need to listen to more deps? Would that cause side effects that break behavior
|
||||
}, [collectionPath]);
|
||||
|
||||
return { children, isLoading, error };
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useCallback, useEffect, useEffectEvent, useMemo, useReducer, useRef } from "react";
|
||||
import { useCallback, useEffect, useEffectEvent, useMemo, useReducer, useRef, useState } from "react";
|
||||
import { useAuthStore } from "@/stores/auth-store";
|
||||
import type { Particle } from "@/api/types";
|
||||
import { useLiveParticleChildren } from "@/hooks/use-particle";
|
||||
import { toFirestoreDocPath, type ParticlePath } from "@/lib/particle-path";
|
||||
import { updateStreamPlaybackMarker } from "@/lib/firestore-particles";
|
||||
import { where, Timestamp } from "firebase/firestore";
|
||||
import { RECENCY_WINDOW_HOURS } from "@/lib/constants";
|
||||
|
||||
// --- Playback reducer (ID-based) ---
|
||||
|
||||
@@ -112,8 +114,15 @@ export function useStreamPlayback(
|
||||
});
|
||||
});
|
||||
|
||||
const [recencyCutoff] = useState(() => {
|
||||
const d = new Date();
|
||||
d.setHours(d.getHours() - RECENCY_WINDOW_HOURS);
|
||||
return Timestamp.fromDate(d);
|
||||
});
|
||||
|
||||
const { children } = useLiveParticleChildren(
|
||||
path, "created_at", "asc", undefined, onParticleAdded, onParticleRemoved,
|
||||
where("created_at", ">=", recencyCutoff),
|
||||
);
|
||||
|
||||
// Derive current index and particle from ID
|
||||
|
||||
Reference in New Issue
Block a user