Skip to content

Commit

Permalink
fix: Populate with the default list
Browse files Browse the repository at this point in the history
If the account has been created but there aren't any logs, add the default list to ensure it's there.
  • Loading branch information
mmcknett committed May 18, 2024
1 parent 7b7e727 commit 5d3d186
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hooks/use-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deleteField, doc, DocumentReference, setDoc, Timestamp, updateDoc, arra
import { useDocumentData } from "react-firebase-hooks/firestore";

import { checkedUid, IFirebaseContext } from "../data/FirebaseContext";
import { IAccountData, ILog, ILogDraft } from "../data/data-types";
import { DEFAULT_LIST, IAccountData, ILog, ILogDraft } from "../data/data-types";
import { ACCOUNTS_COLLECTION, checkedAccountPath } from "../data/paths";
import { getLogsCollection } from "../data/collections";

Expand Down Expand Up @@ -49,6 +49,11 @@ async function healListCacheIfNeeded(fBaseContext: IFirebaseContext, accountDocR
const uniqueLists = new Set<string>(allLogDocrefs.docs.map(doc => doc.data().list));
const lists = Array.from(uniqueLists).sort();

if (lists.length == 0) {
// There aren't any logs, so add the default list.
lists.push(DEFAULT_LIST);
}

const accountPath = accountDocRef.path;
try {
// Use updateDoc so that this fails if we haven't created the account yet.
Expand Down

0 comments on commit 5d3d186

Please sign in to comment.