Files
llink/js/src/hooks/use-create-particle.ts
T
Arjun PatelandGitHub cc190ba85f feat: triage streams with open, close (#121)
* refactor: use interfaces for function params

* cleanup message retention code

* support open / closed streams

- Tabs for viewing separately
- Context menu to close / open streams
- Update stream particle status field

* ui tweak

* show stream state in stream-view

* ui tweaks

* cleanup message retention from orion api
2026-04-07 16:11:13 -07:00

49 lines
1.5 KiB
TypeScript

import { useMutation } from "@tanstack/react-query";
import { createParticle, createStreamParticle } from "@/lib/firestore-particles";
import type { ParticleType, ParticlePropertiesMap } from "@/api/types";
import { particlePath, ParticlePath, toFirestoreChildrenPath, toFirestoreDocPath } from "@/lib/particle-path";
interface CreateParticleParams<T extends ParticleType = ParticleType> {
// Path to which the new particle will be added as a child
path: ParticlePath;
type: T;
properties: ParticlePropertiesMap[T];
createdByHumanId: string;
}
export function useCreateParticle() {
return useMutation({
mutationFn: async (params: CreateParticleParams) => {
const collectionPath = toFirestoreChildrenPath(params.path);
return await createParticle(
collectionPath,
params.type,
params.properties,
params.createdByHumanId,
);
}
});
}
type CreateStreamParticleParams = {
networkId: string;
properties: ParticlePropertiesMap["stream"];
createdByHumanId: string;
visibleTo?: string[];
};
export function useCreateStreamParticle() {
return useMutation({
mutationFn: async (params: CreateStreamParticleParams) => {
const path = particlePath(params.networkId, []);
const networkCollectionPath = toFirestoreChildrenPath(path);
return await createStreamParticle(
networkCollectionPath,
params.properties,
params.createdByHumanId,
params.visibleTo,
);
}
});
}