Merge branch 'dev'

This commit is contained in:
Milan Paunovic
2025-02-15 21:08:30 +01:00
7 changed files with 55 additions and 19 deletions

View File

@ -70,9 +70,9 @@ if (Platform.OS === 'ios') {
} }
if (__DEV__) { if (__DEV__) {
// functions().useEmulator("localhost", 5001); functions().useEmulator("localhost", 5001);
// firestore().useEmulator("localhost", 5471); firestore().useEmulator("localhost", 5471);
// auth().useEmulator("http://localhost:9099"); auth().useEmulator("http://localhost:9099");
} }
type TextStyleBase = type TextStyleBase =

View File

@ -174,7 +174,8 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
updateToDo({ updateToDo({
...todo, ...todo,
points: points, points: points,
assignees: selectedAssignees assignees: selectedAssignees,
currentAssignee: selectedAssignees[0],
}); });
} else { } else {
return; return;
@ -186,6 +187,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
done: false, done: false,
points: points, points: points,
assignees: selectedAssignees, assignees: selectedAssignees,
currentAssignee: selectedAssignees[0],
repeatDays: todo.repeatDays ?? [] repeatDays: todo.repeatDays ?? []
}); });
} else { } else {

View File

@ -231,6 +231,13 @@ const ToDoItem = (props: {
</View> </View>
<View row style={{ gap: 3 }}> <View row style={{ gap: 3 }}>
{selectedMembers?.map((member) => { {selectedMembers?.map((member) => {
let currentAssignee = props?.item?.currentAssignee;
let opacity = 1;
if (selectedMembers?.length > 1 && currentAssignee !== member?.uid) {
opacity = 0.4;
}
return member?.pfp ? ( return member?.pfp ? (
<ImageBackground <ImageBackground
key={member?.uid} key={member?.uid}
@ -242,6 +249,7 @@ const ToDoItem = (props: {
overflow: "hidden", overflow: "hidden",
borderWidth: 2, borderWidth: 2,
borderColor: member.eventColor || "transparent", borderColor: member.eventColor || "transparent",
opacity: opacity
}} }}
/> />
) : ( ) : (
@ -254,6 +262,7 @@ const ToDoItem = (props: {
borderWidth: 2, borderWidth: 2,
borderRadius: 100, borderRadius: 100,
borderColor: member.eventColor || "#ccc", borderColor: member.eventColor || "#ccc",
opacity: opacity
}} }}
> >
<View <View

View File

@ -11,6 +11,7 @@ export interface IToDo {
creatorId?: string; creatorId?: string;
familyId?: string; familyId?: string;
assignees?: string[]; // Optional list of assignees assignees?: string[]; // Optional list of assignees
currentAssignee?: string,
connectedTodoId?: string; connectedTodoId?: string;
} }

View File

@ -130,7 +130,7 @@ export const useCreateTodo = () => {
let assignee; let assignee;
if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) { 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 = { const nextTodo = {
@ -140,7 +140,8 @@ export const useCreateTodo = () => {
familyId: profileData?.familyId, familyId: profileData?.familyId,
creatorId: currentUser?.uid, creatorId: currentUser?.uid,
connectedTodoId: ruleDocRef.id, connectedTodoId: ruleDocRef.id,
assignees: assignee ? [assignee] : todoData.assignees assignees: todoData.assignees,
currentAssignee: assignee
} }
batch.set(newDocRef, nextTodo) batch.set(newDocRef, nextTodo)

View File

@ -1,14 +1,32 @@
import {useMutation} from "@tanstack/react-query"; import {useMutation} from "@tanstack/react-query";
import auth from "@react-native-firebase/auth"; import auth from "@react-native-firebase/auth";
import firestore from "@react-native-firebase/firestore";
import {ProfileType, useAuthContext} from "@/contexts/AuthContext"; import {ProfileType, useAuthContext} from "@/contexts/AuthContext";
import {useSetUserData} from "./useSetUserData"; import {useSetUserData} from "./useSetUserData";
import {uuidv4} from "@firebase/util"; import {uuidv4} from "@firebase/util";
import * as Localization from "expo-localization"; import * as Localization from "expo-localization";
export const useSignUp = () => { export const useSignUp = () => {
const {setRedirectOverride} = useAuthContext() const {setRedirectOverride} = useAuthContext();
const {mutateAsync: setUserData} = useSetUserData(); 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({ return useMutation({
mutationKey: ["signUp"], mutationKey: ["signUp"],
mutationFn: async ({ mutationFn: async ({
@ -24,7 +42,8 @@ export const useSignUp = () => {
lastName: string; lastName: string;
birthday: Date; birthday: Date;
}) => { }) => {
setRedirectOverride(true) setRedirectOverride(true);
const familyId = uuidv4();
await auth() await auth()
.createUserWithEmailAndPassword(email, password) .createUserWithEmailAndPassword(email, password)
@ -35,12 +54,14 @@ export const useSignUp = () => {
userType: ProfileType.PARENT, userType: ProfileType.PARENT,
firstName: firstName, firstName: firstName,
lastName: lastName, lastName: lastName,
familyId: uuidv4(), familyId: familyId,
timeZone: Localization.getCalendars()[0].timeZone, timeZone: Localization.getCalendars()[0].timeZone,
birthday: birthday birthday: birthday
}, },
customUser: res.user, customUser: res.user,
}); });
await createHouseholdIfNeeded(familyId, lastName);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }

View File

@ -59,14 +59,15 @@ export const useUpdateTodo = () => {
const newDate = nextDates[index]; const newDate = nextDates[index];
let assignee; let assignee;
if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) { 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) { if (newDate) {
const nextTodo = { const nextTodo = {
...todoData, ...todoData,
date: newDate, date: newDate,
assignees: assignee ? [assignee] : todoData.assignees assignees: todoData.assignees,
currentAssignee: assignee
} }
let docRef = todo.ref; let docRef = todo.ref;
batch.update(docRef, nextTodo) batch.update(docRef, nextTodo)
@ -83,7 +84,7 @@ export const useUpdateTodo = () => {
let assignee; let assignee;
if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) { 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 = { const nextTodo = {
@ -93,7 +94,8 @@ export const useUpdateTodo = () => {
familyId: profileData?.familyId, familyId: profileData?.familyId,
creatorId: currentUser?.uid, creatorId: currentUser?.uid,
connectedTodoId: todoData.connectedTodoId, connectedTodoId: todoData.connectedTodoId,
assignees: assignee ? [assignee] : todoData.assignees assignees: todoData.assignees,
currentAssignee: assignee
} }
batch.set(newDocRef, nextTodo) batch.set(newDocRef, nextTodo)