* 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
49 lines
1.5 KiB
TypeScript
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,
|
|
);
|
|
}
|
|
});
|
|
}
|