diff --git a/components/pages/(tablet_pages)/chores/TabletChoresPage.tsx b/components/pages/(tablet_pages)/chores/TabletChoresPage.tsx index 657c3a2..d85b2f1 100644 --- a/components/pages/(tablet_pages)/chores/TabletChoresPage.tsx +++ b/components/pages/(tablet_pages)/chores/TabletChoresPage.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from "react"; +import React, {useEffect, useMemo} from "react"; import {Text, View} from "react-native-ui-lib"; import * as ScreenOrientation from "expo-screen-orientation"; import TabletContainer from "../tablet_components/TabletContainer"; @@ -7,10 +7,29 @@ import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers"; import { ImageBackground, StyleSheet } from "react-native"; import { colorMap } from "@/constants/colorMap"; import { ScrollView } from "react-native-gesture-handler"; -import { ProfileType } from "@/contexts/AuthContext"; +import { ProfileType, useAuthContext } from "@/contexts/AuthContext"; const TabletChoresPage = () => { const {data: users} = useGetFamilyMembers(); + const { user: currentUser } = useAuthContext(); + + const sortedUsers = useMemo(() => { + return users + ?.filter(member => member.userType !== ProfileType.FAMILY_DEVICE) + .sort((a, b) => { + if (a.uid === currentUser?.uid) return -1; + if (b.uid === currentUser?.uid) return 1; + + const typePriority = { + [ProfileType.PARENT]: 0, + [ProfileType.CHILD]: 1, + [ProfileType.CAREGIVER]: 2 + }; + + return typePriority[a.userType] - typePriority[b.userType]; + }); + }, [users, currentUser]); + // Function to lock the screen orientation to landscape const lockScreenOrientation = async () => { await ScreenOrientation.lockAsync( @@ -27,11 +46,16 @@ const TabletChoresPage = () => { }; }, []); + const capitalizeFirstLetter = (str: string) => { + if (!str) return ""; + return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); + }; + return ( - {users + {sortedUsers ?.filter((member) => member.userType !== ProfileType.FAMILY_DEVICE) .map((user, index) => ( @@ -66,7 +90,7 @@ const TabletChoresPage = () => { {user.firstName} - ({user.userType}) + ({capitalizeFirstLetter(user.userType)}) diff --git a/components/pages/(tablet_pages)/tablet_components/UsersList.tsx b/components/pages/(tablet_pages)/tablet_components/UsersList.tsx index 4b3f71f..bf81cb1 100644 --- a/components/pages/(tablet_pages)/tablet_components/UsersList.tsx +++ b/components/pages/(tablet_pages)/tablet_components/UsersList.tsx @@ -1,11 +1,13 @@ import { View, Text } from "react-native-ui-lib"; -import React, { useEffect } from "react"; +import React, { useEffect, useMemo } from "react"; import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers"; import { ImageBackground, StyleSheet } from "react-native"; import { colorMap } from "@/constants/colorMap"; -import { ProfileType } from "@/contexts/AuthContext"; +import { ProfileType, useAuthContext } from "@/contexts/AuthContext"; +import { ScrollView } from "react-native-gesture-handler"; const UsersList = () => { + const { user: currentUser } = useAuthContext(); const { data: familyMembers, refetch: refetchFamilyMembers } = useGetFamilyMembers(); @@ -13,17 +15,34 @@ const UsersList = () => { refetchFamilyMembers(); }, []); + const sortedMembers = useMemo(() => { + return familyMembers + ?.filter((member) => member.userType !== ProfileType.FAMILY_DEVICE) + .sort((a, b) => { + // Current user first + if (a.uid === currentUser?.uid) return -1; + if (b.uid === currentUser?.uid) return 1; + + // Then sort by user type priority + const typePriority = { + [ProfileType.PARENT]: 0, + [ProfileType.CHILD]: 1, + [ProfileType.CAREGIVER]: 2, + }; + + return typePriority[a.userType] - typePriority[b.userType]; + }); + }, [familyMembers, currentUser]); + const capitalizeFirstLetter = (str: string) => { if (!str) return ""; return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); }; return ( - - {familyMembers - ?.filter((member) => member.userType !== ProfileType.FAMILY_DEVICE) - .map((member, index) => ( - <> + + {sortedMembers?.map((member, index) => ( + {member.pfp ? ( { style={styles.pfp} center backgroundColor={member.eventColor || colorMap.teal} - children={ - - {member.firstName.at(0)} - {member.lastName.at(0)} - - } - /> + > + + {member.firstName.at(0)} + {member.lastName.at(0)} + + )} {member.firstName} {capitalizeFirstLetter(member.userType)} - + ))} ); diff --git a/components/pages/brain_dump/DumpList.tsx b/components/pages/brain_dump/DumpList.tsx index 6f2f435..f1c4dbd 100644 --- a/components/pages/brain_dump/DumpList.tsx +++ b/components/pages/brain_dump/DumpList.tsx @@ -3,11 +3,11 @@ import React from "react"; import { useBrainDumpContext } from "@/contexts/DumpContext"; import { FlatList } from "react-native"; import BrainDumpItem from "./DumpItem"; - +import { StyleSheet } from "react-native"; const DumpList = (props: { searchText: string }) => { const { brainDumps } = useBrainDumpContext(); - const filteredBrainDumps = + const sortedDumps = props.searchText.trim() === "" ? brainDumps : brainDumps.filter( @@ -18,18 +18,21 @@ const DumpList = (props: { searchText: string }) => { .includes(props.searchText.toLowerCase()) ); - return ( - - item.title} - renderItem={({ item }) => ( - - )} - /> - - ); -}; - + return ( + + {brainDumps?.length ? item.title} + renderItem={({ item }) => ( + + )} + /> : You have no notes} + + ); + }; + + const styles = StyleSheet.create({ + alert: {fontFamily: "PlusJakartaSans_300Light", fontSize: 20} + }) export default DumpList; diff --git a/components/pages/grocery/GroceryList.tsx b/components/pages/grocery/GroceryList.tsx index 0fe5186..730377b 100644 --- a/components/pages/grocery/GroceryList.tsx +++ b/components/pages/grocery/GroceryList.tsx @@ -122,16 +122,14 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => { {/* Pending Approval Section */} + {setPendingVisible(!pendingVisible)}}> Pending Approval {pendingVisible && ( { - setPendingVisible(false); - }} + name="down" + size={17} + style={styles.dropIcon} + color="#9f9f9f" /> )} {!pendingVisible && ( @@ -140,11 +138,9 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => { size={15} style={styles.dropIcon} color="#9f9f9f" - onPress={() => { - setPendingVisible(true); - }} - /> - )} + /> + )} + void}) => { {/* Approved Section */} + {setApprovedVisible(!approvedVisible)}}> Shopping List {approvedVisible && ( void}) => { size={17} style={styles.dropIcon} color="#9f9f9f" - onPress={() => { - setApprovedVisible(false); - }} /> )} {!approvedVisible && ( @@ -201,11 +195,9 @@ const GroceryList = ({onInputFocus}: {onInputFocus: (y: number) => void}) => { size={15} style={styles.dropIcon} color="#9f9f9f" - onPress={() => { - setApprovedVisible(true); - }} /> )} + } /> ) : ( - + {getInitials(member.firstName, member.lastName)} diff --git a/contexts/DumpContext.tsx b/contexts/DumpContext.tsx index 83278a6..6e0cb9b 100644 --- a/contexts/DumpContext.tsx +++ b/contexts/DumpContext.tsx @@ -26,7 +26,7 @@ const BrainDumpContext = createContext( export const BrainDumpProvider: React.FC<{ children: React.ReactNode }> = ({ children, }) => { - const { data: brainDumps } = useGetNotes(); + const { data: brainDumps, refetch } = useGetNotes(); const { mutate: deleteNote } = useDeleteNote(); const { mutateAsync: createBrainDump } = useCreateNote(); const { mutateAsync: updateNoteMutate } = useUpdateNote(); diff --git a/hooks/firebase/useCreateNote.ts b/hooks/firebase/useCreateNote.ts index 417e959..c2de84d 100644 --- a/hooks/firebase/useCreateNote.ts +++ b/hooks/firebase/useCreateNote.ts @@ -5,7 +5,7 @@ import { IFeedback } from "@/contexts/FeedbackContext"; import { IBrainDump } from "@/contexts/DumpContext"; export const useCreateNote = () => { - const { user: currentUser, profileData } = useAuthContext(); + const { user: currentUser } = useAuthContext(); const queryClients = useQueryClient(); return useMutation({ diff --git a/hooks/firebase/useGetNotes.ts b/hooks/firebase/useGetNotes.ts index 62b590a..5aabe65 100644 --- a/hooks/firebase/useGetNotes.ts +++ b/hooks/firebase/useGetNotes.ts @@ -13,6 +13,7 @@ export const useGetNotes = () => { const snapshot = await firestore() .collection("BrainDumps") .where("creatorId", "==", currentUser?.uid) + .orderBy("updatedAt", "desc") .get(); return snapshot.docs.map((doc) => ({