Skip to content

Commit

Permalink
add useMemo for profile and notification
Browse files Browse the repository at this point in the history
  • Loading branch information
in-mai-space committed Dec 4, 2024
1 parent a40094f commit 58bc9b2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frontend/app/(app)/(tabs)/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export default function Explore() {
};

return (
<SafeAreaView className="h-screen w-screen">
<SafeAreaView className="h-screen w-screen bg-white">
{selectedCategory === 'Map' && renderMapPage()}
<View className="w-full px-[5%] z-10">
<View className="mb-2 bg-[#FFFFFF] rounded-full">
Expand Down
8 changes: 6 additions & 2 deletions frontend/app/(app)/(tabs)/notification.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFocusEffect } from 'expo-router';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { FlatList, SafeAreaView, SectionList, Text, View } from 'react-native';
import { useAuthStore } from '../../../auth/authStore';
import NotificationEntry from '../../../components/notification/notification';
Expand All @@ -17,12 +17,16 @@ const Notification = () => {
data,
isLoading,
error,
refetch,
refetch: originalRefetch,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
} = useUserNotification(mongoDBId || '');

const refetch = useCallback(() => {
originalRefetch();
}, [originalRefetch]);

useFocusEffect(
useCallback(() => {
refetch();
Expand Down
20 changes: 18 additions & 2 deletions frontend/app/(app)/user/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import React from 'react';
import { useLocalSearchParams } from 'expo-router';
import { router, Stack, useLocalSearchParams } from 'expo-router';
import User from './components/user-profile';
import Arrow from '../../../components/arrow';

const Profile = () => {
const { id } = useLocalSearchParams<{ id: string }>();
return <User id={id} />;

return (
<>
<Stack.Screen
options={{
headerTitle: '',
headerTransparent: true,
headerShown: true,
headerLeft: () => (
<Arrow direction="left" onPress={() => router.back()} />
),
}}
/>
<User id={id} />
</>
);
};

export default Profile;
14 changes: 7 additions & 7 deletions frontend/app/(app)/user/components/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import {
Dimensions,
FlatList,
Expand Down Expand Up @@ -66,15 +66,15 @@ const Menu = ({ id }: { id: string }) => {
refetch: refetchSpecies,
} = useUserSpecies(id);

const memoizedRefetch = useMemo(() => {
return category === 'Dives' ? refetchDivelog : refetchSpecies;
}, [category, refetchDivelog, refetchSpecies]);

useFocusEffect(
useCallback(() => {
console.log(`Refetching ${category} data`);
if (category === 'Dives') {
refetchDivelog();
} else if (category === 'Species') {
refetchSpecies();
}
}, [refetchDivelog, refetchSpecies, category]),
memoizedRefetch();
}, [memoizedRefetch, category]),
);

const diveLogData = diveLogPages?.pages.flatMap((page) => page) ?? [];
Expand Down
11 changes: 0 additions & 11 deletions frontend/app/(app)/user/components/user-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ const User = ({ id }: { id: string }) => {
colors={['#549ac7', '#ffffff', '#ffffff', '#ffffff']}
style={{ flex: 1 }}
>
<Stack.Screen
options={{
headerTitle: '',
headerTransparent: true,
headerShown: true,
headerLeft: () =>
!isViewingOwnProfile ? (
<Arrow direction="left" onPress={() => router.back()} />
) : null,
}}
/>
<SafeAreaView
edges={['top', 'left', 'right']}
className="flex flex-1 mt-[10%]"
Expand Down

0 comments on commit 58bc9b2

Please sign in to comment.