Skip to content

Commit

Permalink
Some copy/paste related fixes:
Browse files Browse the repository at this point in the history
* In firestore compat `doc` function, client variant: if doc path is not provided (we wish a new server-assigned id), pass only the parent node (to prevent empty path crashes)
* In firestore compat `batch` function, bind `this` to returned `commit` methods (for both client and server variant)
  • Loading branch information
ikusteu committed Sep 10, 2023
1 parent c97ab23 commit dc0020a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/client/src/store/actions/copyPaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export const pasteSlotsWeek =
slots.forEach(({ id, date: oldDate, ...slotData }) => {
const luxonDate = fromISO(oldDate).plus({ weeks: jump });
const date = luxon2ISODate(luxonDate);
console.log("Slot coll ref", slotsCollRef);
const newSlotRef = doc(slotsCollRef);
batch.set(newSlotRef, { ...slotData, date });
});
Expand Down
14 changes: 8 additions & 6 deletions packages/client/src/utils/firestore/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ export const doc = (
FirestoreDocVariant.client({
// Even though 'doc' (aliased as 'clientDoc' here) works on both firestore and collection instanceerences,
// it doesn't work well on unions because of slightly different type overloads, hence the typecast.
instance: clientDoc(
instance as ClientFirestore,
pathSegments.join("/")
),
instance: docPath.length
? clientDoc(
instance as ClientCollectionReference,
docPath.length ? docPath : undefined
)
: clientDoc(instance as ClientCollectionReference),
}),
[FirestoreEnv.Server]: ({ instance }) =>
FirestoreDocVariant.server({
Expand Down Expand Up @@ -235,7 +237,7 @@ export const writeBatch = (db: FirestoreVariant) =>
}
return batch.set(doc.instance, data);
},
commit: batch.commit,
commit: batch.commit.bind(batch),
};
},
[FirestoreEnv.Server]: ({ instance }) => {
Expand All @@ -248,7 +250,7 @@ export const writeBatch = (db: FirestoreVariant) =>
}
return batch.set(doc.instance, data);
},
commit: batch.commit,
commit: batch.commit.bind(batch),
};
},
});
Expand Down

0 comments on commit dc0020a

Please sign in to comment.