Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

731 update event page #732

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api/src/types/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type GetEventResponse = {
description: string | null;
fields: unknown;
status: 'OPEN' | 'CLOSED' | 'UPCOMING' | null;
eventDisplayRank: number | null;
};

export type GetEventsResponse = GetEventResponse[];
14 changes: 10 additions & 4 deletions packages/berlin/src/components/events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import { useNavigate } from 'react-router-dom';

// API
import { GetEventResponse } from 'api';
import { GetEventsResponse } from 'api';

// Components
import { Body } from '../typography/Body.styled';
import { Subtitle } from '../typography/Subtitle.styled';

type EventsProps = {
events: GetEventResponse[] | undefined;
events: GetEventsResponse | null | undefined;
errorMessage: string;
};

Expand All @@ -20,8 +20,14 @@ export default function Events({ events, errorMessage }: EventsProps) {
navigate(`/events/${eventId}/cycles`);
};

return events?.length ? (
events.map((event) => {
const sortedEvents = events?.sort((a, b) => {
const rankA = a.eventDisplayRank ?? Number.MAX_SAFE_INTEGER;
const rankB = b.eventDisplayRank ?? Number.MAX_SAFE_INTEGER;
return rankA - rankB;
});

return sortedEvents?.length ? (
sortedEvents.map((event) => {
return (
<article
key={event.id}
Expand Down
18 changes: 1 addition & 17 deletions packages/berlin/src/pages/Events.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// React and third-party libraries
import { useMemo, useState } from 'react';
import { useQuery } from '@tanstack/react-query';

// API
Expand All @@ -11,38 +10,23 @@ import useUser from '../hooks/useUser';
// Components
import { FlexColumn } from '../components/containers/FlexColumn.styled';
import { Title } from '../components/typography/Title.styled';
import * as Tabs from '../components/tabs';
import EventsCards from '../components/events';

function Events() {
const [activeTab, setActiveTab] = useState<string>('upcoming');
const { user } = useUser();
const { data: events } = useQuery({
queryKey: ['events'],
queryFn: () => fetchEvents({ serverUrl: import.meta.env.VITE_SERVER_URL }),
enabled: !!user?.id,
});

const openEvents = useMemo(() => events?.filter((event) => event.status === 'OPEN'), [events]);
const closedEvents = useMemo(
() => events?.filter((events) => events.status === 'CLOSED'),
[events],
);

const tabNames = ['upcoming', 'past'];
const tabs = {
upcoming: <EventsCards events={openEvents} errorMessage="No upcoming events..." />,
past: <EventsCards events={closedEvents} errorMessage="No past events..." />,
};

return (
<FlexColumn $gap="2rem">
<section className="flex w-full flex-col justify-between gap-2 md:flex-row md:items-center">
<Title>Events</Title>
<Tabs.TabsHeader className="tabs" tabNames={tabNames} onTabChange={setActiveTab} />
</section>
<section className="grid w-full gap-4 md:grid-cols-2">
<Tabs.TabsManager tabs={tabs} tab={activeTab} fallback={'Tab not found'} />
<EventsCards events={events} errorMessage="No events found..." />
</section>
</FlexColumn>
);
Expand Down
Loading