feat: show latest particle preview in stream list

This commit is contained in:
talksik
2026-03-18 18:00:12 -07:00
parent 1a695f9873
commit 6d84fbe20c
3 changed files with 108 additions and 10 deletions
+20
View File
@@ -7,6 +7,7 @@ import {
updateDoc,
query,
orderBy,
limit,
serverTimestamp,
Timestamp,
type DocumentData,
@@ -97,6 +98,25 @@ export function subscribeToParticleChildren(
);
}
export function subscribeToLatestChild(
collectionPath: string,
onData: (child: Particle | null) => void,
onError: (error: Error) => void,
): Unsubscribe {
const q = query(
typedCollection(collectionPath),
orderBy("created_at", "desc"),
limit(1),
);
return onSnapshot(
q,
(snap) => {
onData(snap.empty ? null : snap.docs[0].data());
},
onError,
);
}
// This creates a new particle document with the given properties and returns its ID.
export async function createParticle<T extends ParticleType>(
collectionPath: string,