diff --git a/app/_layout.tsx b/app/_layout.tsx index 7fcd0b8..3562c5c 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -70,9 +70,9 @@ if (Platform.OS === 'ios') { } if (__DEV__) { - // functions().useEmulator("localhost", 5001); - // firestore().useEmulator("localhost", 5471); - // auth().useEmulator("http://localhost:9099"); + functions().useEmulator("localhost", 5001); + firestore().useEmulator("localhost", 5471); + auth().useEmulator("http://localhost:9099"); } type TextStyleBase = diff --git a/components/pages/todos/AddChoreDialog.tsx b/components/pages/todos/AddChoreDialog.tsx index 431c9a3..c3020c0 100644 --- a/components/pages/todos/AddChoreDialog.tsx +++ b/components/pages/todos/AddChoreDialog.tsx @@ -174,7 +174,8 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { updateToDo({ ...todo, points: points, - assignees: selectedAssignees + assignees: selectedAssignees, + currentAssignee: selectedAssignees[0], }); } else { return; @@ -186,6 +187,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { done: false, points: points, assignees: selectedAssignees, + currentAssignee: selectedAssignees[0], repeatDays: todo.repeatDays ?? [] }); } else { diff --git a/components/pages/todos/ToDoItem.tsx b/components/pages/todos/ToDoItem.tsx index c978bad..9bc3704 100644 --- a/components/pages/todos/ToDoItem.tsx +++ b/components/pages/todos/ToDoItem.tsx @@ -231,6 +231,13 @@ const ToDoItem = (props: { {selectedMembers?.map((member) => { + + let currentAssignee = props?.item?.currentAssignee; + let opacity = 1; + if (selectedMembers?.length > 1 && currentAssignee !== member?.uid) { + opacity = 0.4; + } + return member?.pfp ? ( ) : ( @@ -254,6 +262,7 @@ const ToDoItem = (props: { borderWidth: 2, borderRadius: 100, borderColor: member.eventColor || "#ccc", + opacity: opacity }} > { let assignee; if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) { - assignee = todoData.assignees[index % todoData.assignees.length]; + assignee = todoData.assignees[(index + 1) % todoData.assignees.length]; } const nextTodo = { @@ -140,7 +140,8 @@ export const useCreateTodo = () => { familyId: profileData?.familyId, creatorId: currentUser?.uid, connectedTodoId: ruleDocRef.id, - assignees: assignee ? [assignee] : todoData.assignees + assignees: todoData.assignees, + currentAssignee: assignee } batch.set(newDocRef, nextTodo) diff --git a/hooks/firebase/useSignUp.ts b/hooks/firebase/useSignUp.ts index 13f55c4..aab0f94 100644 --- a/hooks/firebase/useSignUp.ts +++ b/hooks/firebase/useSignUp.ts @@ -1,30 +1,49 @@ import {useMutation} from "@tanstack/react-query"; import auth from "@react-native-firebase/auth"; +import firestore from "@react-native-firebase/firestore"; import {ProfileType, useAuthContext} from "@/contexts/AuthContext"; import {useSetUserData} from "./useSetUserData"; import {uuidv4} from "@firebase/util"; import * as Localization from "expo-localization"; export const useSignUp = () => { - const {setRedirectOverride} = useAuthContext() + const {setRedirectOverride} = useAuthContext(); const {mutateAsync: setUserData} = useSetUserData(); + const createHouseholdIfNeeded = async (familyId: string, lastName: string) => { + try { + const householdRef = firestore().collection("Households"); + const snapshot = await householdRef.where("familyId", "==", familyId).get(); + + if (snapshot.empty) { + await householdRef.add({ + familyId, + name: lastName + }); + } + } catch (error) { + console.error("Error creating household:", error); + throw error; + } + }; + return useMutation({ mutationKey: ["signUp"], mutationFn: async ({ - email, - password, - firstName, - lastName, - birthday - }: { + email, + password, + firstName, + lastName, + birthday + }: { email: string; password: string; firstName: string; lastName: string; birthday: Date; }) => { - setRedirectOverride(true) + setRedirectOverride(true); + const familyId = uuidv4(); await auth() .createUserWithEmailAndPassword(email, password) @@ -35,12 +54,14 @@ export const useSignUp = () => { userType: ProfileType.PARENT, firstName: firstName, lastName: lastName, - familyId: uuidv4(), + familyId: familyId, timeZone: Localization.getCalendars()[0].timeZone, birthday: birthday }, customUser: res.user, }); + + await createHouseholdIfNeeded(familyId, lastName); } catch (error) { console.error(error); } diff --git a/hooks/firebase/useUpdateTodo.ts b/hooks/firebase/useUpdateTodo.ts index ed5ea3c..c01992f 100644 --- a/hooks/firebase/useUpdateTodo.ts +++ b/hooks/firebase/useUpdateTodo.ts @@ -59,14 +59,15 @@ export const useUpdateTodo = () => { const newDate = nextDates[index]; let assignee; if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) { - assignee = todoData.assignees[index % todoData.assignees.length]; + assignee = todoData.assignees[(index + 1) % todoData.assignees.length]; } if (newDate) { const nextTodo = { ...todoData, date: newDate, - assignees: assignee ? [assignee] : todoData.assignees + assignees: todoData.assignees, + currentAssignee: assignee } let docRef = todo.ref; batch.update(docRef, nextTodo) @@ -83,7 +84,7 @@ export const useUpdateTodo = () => { let assignee; if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) { - assignee = todoData.assignees[index % todoData.assignees.length]; + assignee = todoData.assignees[(index + 1) % todoData.assignees.length]; } const nextTodo = { @@ -93,7 +94,8 @@ export const useUpdateTodo = () => { familyId: profileData?.familyId, creatorId: currentUser?.uid, connectedTodoId: todoData.connectedTodoId, - assignees: assignee ? [assignee] : todoData.assignees + assignees: todoData.assignees, + currentAssignee: assignee } batch.set(newDocRef, nextTodo)