Skip to content

Commit 83c1450

Browse files
authored
Feature: Adding, removing and viewing favorite doctors. (#125)
**What does this PR do?** This PR enhances the existing user interface by integrating backend functionality to manage favorite doctors. Users can now add doctors to their favorites list, remove them, and view their list of favorites directly within the application. **Description of Task to be completed** - [x] Favorite a doctor - [x] View list of favorite doctors - [x] Remove a doctor from favorites - [x] Refresh the favorite status icon How should this be manually tested? After logging in, to view a list of favorite doctors, you tap on the heart icon beside the notifications icon. To favorite a doctor, you can do so on the doctor's information screen. You can unfavorite him/her on this screen too. Screenshots ![image](https://github.com/atlp-rwanda/commanders-rn-medica/assets/54446750/45c235fc-09e7-4f42-ba56-1ed9a7ed2aea) ![image](https://github.com/atlp-rwanda/commanders-rn-medica/assets/54446750/d489ea11-c21e-4530-bc6c-9e90b9c57662) ![image](https://github.com/atlp-rwanda/commanders-rn-medica/assets/54446750/5d492e7f-73cb-43fb-b876-7e2bc7f63ced) ![image](https://github.com/atlp-rwanda/commanders-rn-medica/assets/54446750/b6823ef1-ffea-4768-8bff-25730efc6da6)
2 parents 023b682 + f40a948 commit 83c1450

File tree

10 files changed

+467
-302
lines changed

10 files changed

+467
-302
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log*
1919
# VS Code
2020
.history/
2121
.vscode/launch.json
22+
.vscode
2223

2324
# macOS
2425
.DS_Store

app/(tabs)/index.tsx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RootState } from "@/redux/store/store";
2-
import { Link, router } from "expo-router";
2+
import { Link, router, useNavigation } from "expo-router";
33
import { useEffect, useState } from "react";
44
import {
55
ActivityIndicator,
@@ -32,6 +32,7 @@ import {
3232
const roleFilters = ["All", "General", "Dentist", "Nutritionist", "Pediatric"];
3333

3434
const Home = () => {
35+
const navigation = useNavigation();
3536
const dispatch = useDispatch();
3637
const [doctors, setDoctors] = useState<Doctor[]>([]);
3738
const [filteredDoctors, setFilteredDoctors] = useState<Doctor[]>([]);
@@ -40,28 +41,51 @@ const Home = () => {
4041

4142
const { loading, user } = useSelector(
4243
(state: RootState) => state.getProfileReducer
43-
);
44+
);
4445
const fetchDoctors = async () => {
45-
try {
46+
try {
47+
const { data } = await supabase.auth.getUser();
48+
const user_id = data.user?.id;
49+
console.log("Userid: " + user_id);
4650
let { data: doctorsData, error } = await supabase
4751
.from("doctor")
4852
.select("*");
4953

50-
if (error) {
51-
console.error("Error fetching data:", error);
52-
} else {
53-
setDoctors(doctorsData || []);
54-
setFilteredDoctors(doctorsData || []);
55-
}
54+
const { data: favoriteData, error: favoriteError } = await supabase
55+
.from('favorites')
56+
.select('doctor_id')
57+
.eq('user_id', user_id);
58+
59+
if (favoriteError) {
60+
console.error('Error fetching favorites:', favoriteError);
61+
return [];
62+
}
63+
64+
// console.log("Favorites:----->", favoriteData);
65+
66+
const favoriteDoctorIds = favoriteData.map(favorite => favorite.doctor_id);
67+
68+
const doctorsWithLikedStatus = doctorsData?.map(doctor => ({
69+
...doctor,
70+
liked: favoriteDoctorIds.includes(doctor.id)
71+
}));
72+
setDoctors(doctorsWithLikedStatus || []);
73+
setFilteredDoctors(doctorsWithLikedStatus || []);
5674
} catch (error) {
5775
console.error("Error:", error);
5876
}
5977
};
6078

6179
useEffect(() => {
80+
const unsubscribeFocus = navigation.addListener('focus', () => {
81+
fetchDoctors();
82+
});
6283
fetchDoctors();
6384
dispatch(getProfile() as unknown as UnknownAction);
64-
}, []);
85+
return () => {
86+
unsubscribeFocus();
87+
};
88+
}, [navigation,roleFilters]);
6589

6690
const greeting = () => {
6791
const date = new Date();
@@ -184,7 +208,14 @@ const Home = () => {
184208
className="w-[86px] items-center justify-between me-3 mb-6 h-24"
185209
>
186210
<TouchableOpacity
187-
activeOpacity={0.8}
211+
activeOpacity={0.8}
212+
onPress={()=>{
213+
router.push({
214+
pathname: "/Doctors/topDoctors",
215+
params: {
216+
category: item.name
217+
},
218+
});}}
188219
className="bg-[#246BFD14] p-2.5 items-center justify-center rounded-full mb-3 w-[60px] h-[60px]"
189220
>
190221
<SvgXml
@@ -276,6 +307,7 @@ const Home = () => {
276307
pathname: "/doctor-appointments/",
277308
params: {
278309
doctorId: item.id,
310+
liked: item.liked?'true':'false'
279311
},
280312
});
281313
}}

0 commit comments

Comments
 (0)