|
7 | 7 | ImageBackground,
|
8 | 8 | ScrollView,
|
9 | 9 | FlatList,
|
| 10 | + Pressable |
10 | 11 | } from "react-native";
|
11 | 12 | import React, { useContext, useEffect, useState } from "react";
|
12 | 13 | import { useFonts as useFontsExpo } from "expo-font";
|
@@ -56,6 +57,8 @@ export default function Index() {
|
56 | 57 | const { authType, imageUrl: otherAuthImageUrl } = useAuth();
|
57 | 58 | const [showpopUp, setShowPopup] = useState(false);
|
58 | 59 | const [selectedDoctor, setSelectedDoctor] = useState();
|
| 60 | + const [selectedSpecilization, setSelectedSpecilization] = useState<string>("All") |
| 61 | + const [specialization,setSpecialization]=useState<string[]>([]) |
59 | 62 |
|
60 | 63 | const [fontsLoaded] = useFontsExpo({
|
61 | 64 | "Urbanist-regular": require("@/assets/fonts/Urbanist-Regular.ttf"),
|
@@ -95,7 +98,10 @@ export default function Index() {
|
95 | 98 | }
|
96 | 99 | setIsLoading(true);
|
97 | 100 | setDoctors(data);
|
| 101 | + const uniqueSpecialization = Array.from(new Set(data.map((doctor: Doctor) => doctor.specialization))) |
| 102 | + setSpecialization(["All",...uniqueSpecialization]) |
98 | 103 | }
|
| 104 | + |
99 | 105 | fetchData();
|
100 | 106 | }, [doctors]);
|
101 | 107 |
|
@@ -131,17 +137,21 @@ export default function Index() {
|
131 | 137 | setShowPopup(true)
|
132 | 138 | }
|
133 | 139 |
|
| 140 | + const handleSpecializationChange = (specialization: string) => { |
| 141 | + setSelectedSpecilization(specialization) |
| 142 | + setSearchTerm('') |
| 143 | + |
| 144 | + } |
| 145 | + const filteredDoctors = doctors.filter(doctor => { |
| 146 | + const matchSearchTerm = searchTerm.length > 0 ? doctor.last_name.toLowerCase().includes(searchTerm.toLowerCase())||doctor.first_name.toLowerCase().includes(searchTerm.toLowerCase()) : true |
| 147 | + const matchSpecialization = selectedSpecilization === 'All' || doctor.specialization === selectedSpecilization |
| 148 | + return matchSearchTerm&&matchSpecialization |
134 | 149 |
|
| 150 | + }) |
135 | 151 | if (!fontsLoaded) {
|
136 | 152 | return null;
|
137 | 153 | }
|
138 |
| - const filteredDoctors = |
139 |
| - searchTerm.length > 0 |
140 |
| - ? doctors.filter((doctor) => |
141 |
| - doctor.last_name.toLowerCase().includes(searchTerm) |
142 |
| - ) |
143 |
| - : doctors; |
144 |
| - |
| 154 | + |
145 | 155 | return (
|
146 | 156 | <View
|
147 | 157 | style={{
|
@@ -461,98 +471,18 @@ export default function Index() {
|
461 | 471 | }}
|
462 | 472 | >
|
463 | 473 | <ScrollView horizontal showsHorizontalScrollIndicator={false}>
|
464 |
| - <View |
465 |
| - style={{ |
466 |
| - backgroundColor: "#246BFD", |
467 |
| - padding: 5, |
468 |
| - paddingHorizontal: 10, |
469 |
| - borderRadius: 20, |
470 |
| - justifyContent: "center", |
471 |
| - width: 65, |
472 |
| - height: 34, |
473 |
| - alignItems: "center", |
474 |
| - }} |
475 |
| - > |
476 |
| - <Text style={{ fontFamily: "Urbanist-regular", color: "white" }}> |
477 |
| - All |
478 |
| - </Text> |
479 |
| - </View> |
480 |
| - <View |
481 |
| - style={{ |
482 |
| - backgroundColor: theme === "dark" ? "#181A20" : "#ffffff", |
483 |
| - marginLeft: 10, |
484 |
| - padding: 5, |
485 |
| - paddingHorizontal: 10, |
486 |
| - borderColor: "#246BFD", |
487 |
| - borderWidth: 2, |
488 |
| - borderRadius: 20, |
489 |
| - height: 34, |
490 |
| - alignItems: "center", |
491 |
| - }} |
492 |
| - > |
493 |
| - <Text |
494 |
| - style={{ fontFamily: "Urbanist-regular", color: "#246BFD" }} |
495 |
| - > |
496 |
| - General |
497 |
| - </Text> |
498 |
| - </View> |
499 |
| - <View |
500 |
| - style={{ |
501 |
| - backgroundColor: theme === "dark" ? "#181A20" : "#ffffff", |
502 |
| - marginLeft: 10, |
503 |
| - padding: 5, |
504 |
| - paddingHorizontal: 10, |
505 |
| - borderColor: "#246BFD", |
506 |
| - borderWidth: 2, |
507 |
| - borderRadius: 20, |
508 |
| - height: 34, |
509 |
| - alignItems: "center", |
510 |
| - }} |
511 |
| - > |
512 |
| - <Text |
513 |
| - style={{ fontFamily: "Urbanist-regular", color: "#246BFD" }} |
514 |
| - > |
515 |
| - Dentist |
516 |
| - </Text> |
517 |
| - </View> |
518 |
| - <View |
519 |
| - style={{ |
520 |
| - backgroundColor: theme === "dark" ? "#181A20" : "#ffffff", |
521 |
| - marginLeft: 10, |
522 |
| - padding: 5, |
523 |
| - paddingHorizontal: 10, |
524 |
| - borderColor: "#246BFD", |
525 |
| - borderWidth: 2, |
526 |
| - borderRadius: 20, |
527 |
| - height: 34, |
528 |
| - alignItems: "center", |
529 |
| - }} |
530 |
| - > |
531 |
| - <Text |
532 |
| - style={{ fontFamily: "Urbanist-regular", color: "#246BFD" }} |
533 |
| - > |
534 |
| - Nutritionist |
535 |
| - </Text> |
536 |
| - </View> |
537 |
| - <View |
538 |
| - style={{ |
539 |
| - backgroundColor: theme === "dark" ? "#181A20" : "#ffffff", |
540 |
| - marginLeft: 10, |
541 |
| - padding: 5, |
542 |
| - paddingHorizontal: 10, |
543 |
| - borderColor: "#246BFD", |
544 |
| - borderWidth: 2, |
545 |
| - borderRadius: 20, |
546 |
| - height: 34, |
547 |
| - alignItems: "center", |
548 |
| - }} |
549 |
| - > |
550 |
| - <Text |
551 |
| - style={{ fontFamily: "Urbanist-regular", color: "#246BFD" }} |
552 |
| - > |
553 |
| - Neurologist |
554 |
| - </Text> |
555 |
| - </View> |
| 474 | + {specialization.map((specialization, index) => |
| 475 | + <Pressable key={index} onPress={()=>handleSpecializationChange(specialization)} style={[styles.categoryBtn, |
| 476 | + selectedSpecilization === specialization ? styles.firstCategoryBtn : {}, |
| 477 | + ]}> |
| 478 | + |
| 479 | + <Text style={[ |
| 480 | + styles.categoryBtnText, |
| 481 | + selectedSpecilization === specialization ? styles.firstCategoryBtnText : {}, |
| 482 | + ]}>{specialization}</Text> |
| 483 | + |
| 484 | + </Pressable> |
| 485 | + )} |
556 | 486 | </ScrollView>
|
557 | 487 | </View>
|
558 | 488 |
|
@@ -761,4 +691,35 @@ const styles = StyleSheet.create({
|
761 | 691 | marginLeft: "5%",
|
762 | 692 | marginTop: "6%",
|
763 | 693 | },
|
| 694 | + categoryBtnView: { |
| 695 | + display: "flex", |
| 696 | + flexDirection: "row", |
| 697 | + alignItems: "center", |
| 698 | + marginBottom: "5%", |
| 699 | + backgroundColor: "white", |
| 700 | + }, |
| 701 | + categoryBtn: { |
| 702 | + borderWidth: 2, |
| 703 | + borderColor: "#246BFD", |
| 704 | + height: 40, |
| 705 | + paddingHorizontal: 20, |
| 706 | + paddingVertical: 7, |
| 707 | + borderRadius: 20, |
| 708 | + display: "flex", |
| 709 | + flexDirection: "row", |
| 710 | + justifyContent: "center", |
| 711 | + alignItems: "center", |
| 712 | + marginRight: 8, |
| 713 | + marginLeft: 10, |
| 714 | + }, |
| 715 | + firstCategoryBtn: { |
| 716 | + backgroundColor: "#246BFD", |
| 717 | + }, |
| 718 | + firstCategoryBtnText: { |
| 719 | + color: "white", |
| 720 | + }, |
| 721 | + categoryBtnText: { |
| 722 | + color: "#246BFD", |
| 723 | + fontSize: 16, |
| 724 | + }, |
764 | 725 | });
|
0 commit comments