infra: add linting and formatting for js projects (#230)
* wip * wip * wip * format * wip(mobile): lint and format * cleanup * nits * nits * idiomatic react * nit * format all root files
This commit was merged in pull request #230.
This commit is contained in:
@@ -21,15 +21,15 @@ import {
|
||||
type SnapshotOptions,
|
||||
type Unsubscribe,
|
||||
type QueryFieldFilterConstraint,
|
||||
} from "firebase/firestore";
|
||||
import { firestoreDb } from "@/firebase";
|
||||
import { isContainerType, ParticleSchema } from "@/api/types";
|
||||
} from 'firebase/firestore';
|
||||
import { firestoreDb } from '@/firebase';
|
||||
import { isContainerType, ParticleSchema } from '@/api/types';
|
||||
import type {
|
||||
Particle,
|
||||
ParticleType,
|
||||
ParticlePropertiesMap,
|
||||
Reactions,
|
||||
} from "@/api/types";
|
||||
} from '@/api/types';
|
||||
|
||||
// --- Converter ---
|
||||
|
||||
@@ -37,7 +37,7 @@ const particleConverter: FirestoreDataConverter<Particle> = {
|
||||
toFirestore(particle: Particle): DocumentData {
|
||||
const { id: _id, created_at, updated_at, ...rest } = particle;
|
||||
const deletedAt =
|
||||
"deleted_at" in particle ? particle.deleted_at : undefined;
|
||||
'deleted_at' in particle ? particle.deleted_at : undefined;
|
||||
return {
|
||||
...rest,
|
||||
created_at: Timestamp.fromDate(created_at),
|
||||
@@ -50,12 +50,12 @@ const particleConverter: FirestoreDataConverter<Particle> = {
|
||||
options?: SnapshotOptions,
|
||||
): Particle {
|
||||
const raw = snap.data(options);
|
||||
if (typeof raw.type !== "string") {
|
||||
if (typeof raw.type !== 'string') {
|
||||
throw new Error(`Invalid particle type: ${raw.type}`);
|
||||
}
|
||||
const type = raw.type as ParticleType;
|
||||
switch (type) {
|
||||
case "stream":
|
||||
case 'stream':
|
||||
return ParticleSchema.parse({
|
||||
id: snap.id,
|
||||
type: raw.type,
|
||||
@@ -81,7 +81,7 @@ const particleConverter: FirestoreDataConverter<Particle> = {
|
||||
raw.huddle_active_participants ?? undefined,
|
||||
status: raw.status ?? undefined,
|
||||
});
|
||||
case "folder":
|
||||
case 'folder':
|
||||
return ParticleSchema.parse({
|
||||
id: snap.id,
|
||||
type: raw.type,
|
||||
@@ -93,15 +93,15 @@ const particleConverter: FirestoreDataConverter<Particle> = {
|
||||
: undefined,
|
||||
visible_to: raw.visible_to,
|
||||
});
|
||||
case "media":
|
||||
case "file":
|
||||
case "text":
|
||||
case "quest":
|
||||
case "paper": {
|
||||
case 'media':
|
||||
case 'file':
|
||||
case 'text':
|
||||
case 'quest':
|
||||
case 'paper': {
|
||||
// Firestore stores timestamps as `Timestamp`; zod expects `Date`. Text
|
||||
// particles carry `properties.edited_at`, so coerce it if present.
|
||||
const properties =
|
||||
type === "text" && raw.properties?.edited_at
|
||||
type === 'text' && raw.properties?.edited_at
|
||||
? {
|
||||
...raw.properties,
|
||||
edited_at: (raw.properties.edited_at as Timestamp).toDate(),
|
||||
@@ -165,17 +165,17 @@ export async function getParticle(docPath: string): Promise<Particle | null> {
|
||||
|
||||
export interface GetParticleChildrenOptions {
|
||||
orderByField: string;
|
||||
orderDirection: "asc" | "desc";
|
||||
orderDirection: 'asc' | 'desc';
|
||||
}
|
||||
|
||||
export async function getParticleChildren(
|
||||
collectionPath: string,
|
||||
{
|
||||
orderByField = "created_at",
|
||||
orderDirection = "asc",
|
||||
orderByField = 'created_at',
|
||||
orderDirection = 'asc',
|
||||
}: GetParticleChildrenOptions = {
|
||||
orderByField: "created_at",
|
||||
orderDirection: "asc",
|
||||
orderByField: 'created_at',
|
||||
orderDirection: 'asc',
|
||||
},
|
||||
): Promise<Particle[]> {
|
||||
const q = query(
|
||||
@@ -191,7 +191,7 @@ export interface SubscribeToParticleChildrenOptions {
|
||||
onError: (error: Error) => void;
|
||||
visibilityScopes?: string[];
|
||||
orderByField?: string;
|
||||
orderDirection?: "asc" | "desc";
|
||||
orderDirection?: 'asc' | 'desc';
|
||||
onAdded?: (child: Particle) => void;
|
||||
onRemoved?: (child: Particle, updatedChildren: Particle[]) => void;
|
||||
whereFilter?: QueryFieldFilterConstraint;
|
||||
@@ -205,8 +205,8 @@ export function subscribeToParticleChildren(
|
||||
onData,
|
||||
onError,
|
||||
visibilityScopes = [],
|
||||
orderByField = "created_at",
|
||||
orderDirection = "desc",
|
||||
orderByField = 'created_at',
|
||||
orderDirection = 'desc',
|
||||
onAdded,
|
||||
onRemoved,
|
||||
whereFilter,
|
||||
@@ -218,7 +218,7 @@ export function subscribeToParticleChildren(
|
||||
orderBy(orderByField, orderDirection),
|
||||
);
|
||||
if (visibilityScopes.length > 0) {
|
||||
q = query(q, where("visible_to", "array-contains-any", visibilityScopes));
|
||||
q = query(q, where('visible_to', 'array-contains-any', visibilityScopes));
|
||||
}
|
||||
if (whereFilter) {
|
||||
q = query(q, whereFilter);
|
||||
@@ -234,8 +234,8 @@ export function subscribeToParticleChildren(
|
||||
|
||||
if (onAdded || onRemoved) {
|
||||
for (const change of snap.docChanges()) {
|
||||
if (change.type === "added" && onAdded) onAdded(change.doc.data());
|
||||
if (change.type === "removed" && onRemoved)
|
||||
if (change.type === 'added' && onAdded) onAdded(change.doc.data());
|
||||
if (change.type === 'removed' && onRemoved)
|
||||
onRemoved(change.doc.data(), updatedChildren);
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,7 @@ export function subscribeToLatestChild(
|
||||
): Unsubscribe {
|
||||
const q = query(
|
||||
typedCollection(collectionPath),
|
||||
orderBy("created_at", "desc"),
|
||||
orderBy('created_at', 'desc'),
|
||||
limit(1),
|
||||
);
|
||||
return onSnapshot(
|
||||
@@ -279,7 +279,7 @@ export async function createParticle<T extends ParticleType>(
|
||||
}
|
||||
|
||||
const particle: Particle = ParticleSchema.parse({
|
||||
id: "", // ignored by toFirestore, but needed to satisfy the type
|
||||
id: '', // ignored by toFirestore, but needed to satisfy the type
|
||||
type,
|
||||
properties,
|
||||
created_at: new Date(),
|
||||
@@ -292,22 +292,22 @@ export async function createParticle<T extends ParticleType>(
|
||||
|
||||
export async function createStreamParticle(
|
||||
collectionPath: string,
|
||||
properties: ParticlePropertiesMap["stream"],
|
||||
properties: ParticlePropertiesMap['stream'],
|
||||
createdByHumanId: string,
|
||||
visibleTo?: string[],
|
||||
): Promise<string> {
|
||||
if (!visibleTo || visibleTo.length === 0) {
|
||||
throw new Error("visibleTo is required for streams and cannot be empty");
|
||||
throw new Error('visibleTo is required for streams and cannot be empty');
|
||||
}
|
||||
|
||||
const particle: Particle = ParticleSchema.parse({
|
||||
id: "",
|
||||
type: "stream",
|
||||
id: '',
|
||||
type: 'stream',
|
||||
properties,
|
||||
created_at: new Date(),
|
||||
created_by_human_id: createdByHumanId,
|
||||
visible_to: visibleTo,
|
||||
status: "open",
|
||||
status: 'open',
|
||||
});
|
||||
const ref = await addDoc(typedCollection(collectionPath), particle);
|
||||
return ref.id;
|
||||
@@ -340,8 +340,8 @@ export async function editTextParticleContent(
|
||||
): Promise<void> {
|
||||
const particleRef = typedDoc(docPath);
|
||||
await updateDoc(particleRef, {
|
||||
"properties.content": content,
|
||||
"properties.edited_at": serverTimestamp(),
|
||||
'properties.content': content,
|
||||
'properties.edited_at': serverTimestamp(),
|
||||
updated_at: serverTimestamp(),
|
||||
});
|
||||
}
|
||||
@@ -383,7 +383,7 @@ export async function updateParticle(
|
||||
|
||||
export async function updateStreamStatus(
|
||||
docPath: string,
|
||||
status: "open" | "closed",
|
||||
status: 'open' | 'closed',
|
||||
): Promise<void> {
|
||||
const particleRef = typedDoc(docPath);
|
||||
await updateDoc(particleRef, { status, updated_at: serverTimestamp() });
|
||||
@@ -426,7 +426,7 @@ export async function updateStreamPlaybackMarker(
|
||||
const RESERVED_REACTION_CHARS = /[~*/[\]]/g;
|
||||
|
||||
export function sanitizeReactionText(text: string): string {
|
||||
return text.replace(RESERVED_REACTION_CHARS, "");
|
||||
return text.replace(RESERVED_REACTION_CHARS, '');
|
||||
}
|
||||
|
||||
export async function toggleParticleReaction(
|
||||
@@ -441,9 +441,9 @@ export async function toggleParticleReaction(
|
||||
const alreadyReacted = currentReactions?.[key]?.includes(humanId) ?? false;
|
||||
await updateDoc(
|
||||
particleRef,
|
||||
new FieldPath("reactions", key),
|
||||
new FieldPath('reactions', key),
|
||||
alreadyReacted ? arrayRemove(humanId) : arrayUnion(humanId),
|
||||
"updated_at",
|
||||
'updated_at',
|
||||
serverTimestamp(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user