|
| 1 | +import { useContext } from 'react'; |
| 2 | +import { FiSearch } from 'react-icons/fi'; |
| 3 | +import EventSingle from './EventSingle'; |
| 4 | +import { EventsContext } from '../../context/EventsContext'; |
| 5 | +import EventsFilter from './EventsFilter'; |
| 6 | + |
| 7 | +const EventsGrid = () => { |
| 8 | + const { |
| 9 | + events, |
| 10 | + searchEvent, |
| 11 | + setSearchEvent, |
| 12 | + searchEventsByTitle, |
| 13 | + selectEvent, |
| 14 | + setSelectEvent, |
| 15 | + selectEventsByCategory, |
| 16 | + } = useContext(EventsContext); |
| 17 | + |
| 18 | + return ( |
| 19 | + <section className="py-5 sm:py-10 mt-5 sm:mt-10"> |
| 20 | + <div className="text-center"> |
| 21 | + <p className="font-general-medium text-2xl sm:text-4xl mb-1 text-ternary-dark dark:text-ternary-light"> |
| 22 | + Eventos |
| 23 | + </p> |
| 24 | + </div> |
| 25 | + |
| 26 | + <div className="mt-10 sm:mt-16"> |
| 27 | + <h3 |
| 28 | + className="font-general-regular |
| 29 | + text-center text-secondary-dark |
| 30 | + dark:text-ternary-light |
| 31 | + text-md |
| 32 | + sm:text-xl |
| 33 | + mb-3 |
| 34 | + " |
| 35 | + > |
| 36 | + Search events by title or filter by category |
| 37 | + </h3> |
| 38 | + <div |
| 39 | + className=" |
| 40 | + flex |
| 41 | + justify-between |
| 42 | + border-b border-primary-light |
| 43 | + dark:border-secondary-dark |
| 44 | + pb-3 |
| 45 | + gap-3 |
| 46 | + " |
| 47 | + > |
| 48 | + <div className="flex justify-between gap-2"> |
| 49 | + <span |
| 50 | + className=" |
| 51 | + hidden |
| 52 | + sm:block |
| 53 | + bg-primary-light |
| 54 | + dark:bg-ternary-dark |
| 55 | + p-2.5 |
| 56 | + shadow-sm |
| 57 | + rounded-xl |
| 58 | + cursor-pointer |
| 59 | + " |
| 60 | + > |
| 61 | + <FiSearch className="text-ternary-dark dark:text-ternary-light w-5 h-5"></FiSearch> |
| 62 | + </span> |
| 63 | + <input |
| 64 | + onChange={(e) => { |
| 65 | + setSearchEvent(e.target.value); |
| 66 | + }} |
| 67 | + className="font-general-medium |
| 68 | + pl-3 |
| 69 | + pr-1 |
| 70 | + sm:px-4 |
| 71 | + py-2 |
| 72 | + border |
| 73 | + border-gray-200 |
| 74 | + dark:border-secondary-dark |
| 75 | + rounded-lg |
| 76 | + text-sm |
| 77 | + sm:text-md |
| 78 | + bg-secondary-light |
| 79 | + dark:bg-ternary-dark |
| 80 | + text-primary-dark |
| 81 | + dark:text-ternary-light |
| 82 | + " |
| 83 | + id="name" |
| 84 | + name="name" |
| 85 | + type="search" |
| 86 | + required="" |
| 87 | + placeholder="Search Events" |
| 88 | + aria-label="Name" |
| 89 | + /> |
| 90 | + </div> |
| 91 | + |
| 92 | + <EventsFilter setSelectEvent={setSelectEvent} /> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + |
| 96 | + <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 mt-6 sm:gap-10"> |
| 97 | + {selectEvent |
| 98 | + ? selectEventsByCategory.map((event) => ( |
| 99 | + <EventSingle |
| 100 | + title={event.title} |
| 101 | + category={event.category} |
| 102 | + image={event.img} |
| 103 | + key={event.id} |
| 104 | + /> |
| 105 | + )) |
| 106 | + : searchEvent |
| 107 | + ? searchEventsByTitle.map((event) => ( |
| 108 | + <EventSingle |
| 109 | + title={event.title} |
| 110 | + category={event.category} |
| 111 | + image={event.img} |
| 112 | + key={event.id} |
| 113 | + /> |
| 114 | + )) |
| 115 | + : events.map((event) => ( |
| 116 | + <EventSingle |
| 117 | + title={event.title} |
| 118 | + category={event.category} |
| 119 | + image={event.img} |
| 120 | + key={event.id} |
| 121 | + /> |
| 122 | + ))} |
| 123 | + </div> |
| 124 | + </section> |
| 125 | + ); |
| 126 | +}; |
| 127 | + |
| 128 | +export default EventsGrid; |
0 commit comments