Skip to content

Commit

Permalink
date filter toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
raspberri05 committed Feb 26, 2025
1 parent a384e17 commit 7728066
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions client/src/components/molecules/btn-date-filter/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { Tabs, TabsList, TabsTrigger } from "../../../components/ui/tabs";
export type EventCardProps = {
tab1: string;
tab2: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fcn: any;
};

export const BtnDateFilter: React.FC<EventCardProps> = ({ tab1, tab2 }) => {
export const BtnDateFilter: React.FC<EventCardProps> = ({ tab1, tab2, fcn }) => {
return (
<Tabs className="w-[35%] md:w-[20%] text-center">
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="account" className="text-xs">
<TabsTrigger value="account" className="text-xs" onClick={() => fcn("upcoming")}>
{tab1}
</TabsTrigger>
<TabsTrigger value="password" className="text-xs">
<TabsTrigger value="password" className="text-xs" onClick={() => fcn("past")}>
{tab2}
</TabsTrigger>
</TabsList>
Expand Down
7 changes: 4 additions & 3 deletions client/src/pages/events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Event {

const CalendarPage = () => {
const [events, setEvents] = useState<Event[]>([]);
const [dateFilter, setDateFilter] = useState("all");

function formatDate(date: string) {
const dateObj = new Date(date);
Expand All @@ -34,7 +35,7 @@ const CalendarPage = () => {
return `${formattedHour}:${minutes} ${ampm}`;
}
useEffect(() => {
fetch("http://localhost/api/v1/events", {
fetch(`http://localhost/api/v1/events?timeframe=${dateFilter}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -45,7 +46,7 @@ const CalendarPage = () => {
console.log(data);
setEvents(data.foundEvents);
});
}, []);
}, [dateFilter]);
return (
<>
<div className="about text-text my-10 px-[15%]">
Expand All @@ -60,7 +61,7 @@ const CalendarPage = () => {
These events are accessible to all those who are interested,
irrespective of their major or prior experience.
</p>
<BtnDateFilter tab1="Upcoming" tab2="Past" />
<BtnDateFilter tab1="Future" tab2="Past" fcn={setDateFilter} />
</div>

<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 mt-8">
Expand Down

0 comments on commit 7728066

Please sign in to comment.