diff --git a/src/routes/events/index.tsx b/src/routes/events/index.tsx index 2bc316f..33bb2b2 100644 --- a/src/routes/events/index.tsx +++ b/src/routes/events/index.tsx @@ -21,34 +21,45 @@ interface Event { export const Route = createFileRoute('/events/')({ beforeLoad: AuthGuard, loader: async () => { - const { data, error } = await supabase.from('events').select('*'); + const { data: events, error: eventsError } = await supabase.from('events').select('*'); + if (eventsError) throw eventsError; - if (error !== null) { - throw error; - } - return { events: data }; + const { data: eventTypesData, error: eventTypesError } = await supabase.from('event_type').select('*').order('type_id', { ascending: true }); + if (eventTypesError) throw eventTypesError; + console.log(eventTypesData); + return { events, eventTypes: eventTypesData }; }, component: EventIndex, }); function EventIndex() { - const { events } = Route.useLoaderData(); - const navigate = Route.useNavigate(); + const { events, eventTypes } = Route.useLoaderData() as { + events: Event[]; + eventTypes: { type_id: number; type_name: string }[]; + }; + const navigate = Route.useNavigate(); const [searchTerm, setSearchTerm] = useState(''); const [isFocused, setIsFocused] = useState(false); + const [selectedType, setSelectedType] = useState("All"); - const filteredEvents = events.filter( - (event) => - event.name && - event.name.toLowerCase().includes(searchTerm.toLowerCase()) - ); + const filteredEvents = events.filter((event) => { + const matchesSearch = event.name && event.name.toLowerCase().includes(searchTerm.toLowerCase()); + const matchesType = selectedType === "All" + ? true + : event.type === Number(selectedType); + return matchesSearch && matchesType; + }); + + const handleFilterSelect = (type: string) => { + setSelectedType(type); + }; return ( <>
-
+
setSearchTerm('')} - >清除 + > + 清除 + )}
+
+
+ + {eventTypes.map(({ type_id, type_name }) => ( + + ))} +
+
+

最新揪人

@@ -81,7 +116,6 @@ function EventIndex() { ))}
-

最新活動

@@ -125,6 +159,7 @@ function EventIndex() {
+
);