Skip to content

Commit

Permalink
feat: create new events page (#1014)
Browse files Browse the repository at this point in the history
* feat: create new events page

* chore: add params for pagination
  • Loading branch information
shelegdmitriy authored Mar 1, 2024
1 parent 3a03290 commit ac96a26
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/data/bos-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type NetworkComponents = {
widgetMetadata: string;
widgetMetadataEditor: string;
wrapper: string;
eventsPage: string;
};

export const componentsByNetworkId = ((): Record<NetworkId, NetworkComponents | undefined> => {
Expand Down Expand Up @@ -127,6 +128,7 @@ export const componentsByNetworkId = ((): Record<NetworkId, NetworkComponents |
widgetMetadata: 'eugenethedream/widget/WidgetMetadata',
widgetMetadataEditor: `${testnetTLA}/widget/WidgetMetadataEditor`,
wrapper: `${testnetTLA}/widget/GatewayWrapper`,
eventsPage: `${testnetTLA}/widget/Events.Index`,
},

mainnet: {
Expand Down Expand Up @@ -188,6 +190,7 @@ export const componentsByNetworkId = ((): Record<NetworkId, NetworkComponents |
widgetMetadata: 'mob.near/widget/WidgetMetadata',
widgetMetadataEditor: 'near/widget/WidgetMetadataEditor',
wrapper: 'near/widget/GatewayWrapper',
eventsPage: 'near/widget/Events.Index',
},
};
})();
1 change: 0 additions & 1 deletion src/pages/[...arbitrary].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const finiteRoutes: Record<string, string> = {
defi: 'https://pages.near.org/defi',
'educate-old': 'https://pages.near.org/educate-old',
education: 'https://pages.near.org/education',
events: 'https://pages.near.org/events',
examples: 'https://pages.near.org/examples',
lisbon: 'https://pages.near.org/lisbon',
meetings: 'https://pages.near.org/meetings',
Expand Down
26 changes: 26 additions & 0 deletions src/pages/events.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ComponentWrapperPage } from '@/components/near-org/ComponentWrapperPage';
import { useBosComponents } from '@/hooks/useBosComponents';
import { useDefaultLayout } from '@/hooks/useLayout';
import type { NextPageWithLayout } from '@/utils/types';

import { fetchEventsList } from '@/utils/events';

const EventsPage: NextPageWithLayout = () => {
const components = useBosComponents();
return (
<ComponentWrapperPage
src={components.eventsPage}
meta={{
title: 'NEAR | Events',
description: 'Join NEAR for one of our upcoming in-person, virtual, or hybrid events.',
}}
componentProps={{
fetchEventsList,
}}
/>
);
};

EventsPage.getLayout = useDefaultLayout;

export default EventsPage;
2 changes: 2 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const notificationsGatewayUrl = process.env.NEXT_PUBLIC_NOTIFICATIONS_GAT
export const notificationsLocalStorageKey = 'push-notifications-v0';
export const localStorageAccountIdKey = 'near-social-vm:v01::accountId:';
export const isLocalEnvironment = process.env.NEXT_PUBLIC_LOCAL_ENVIRONMENT === 'true';
export const eventsApiUrl = process.env.NEXT_PUBLIC_EVENTS_API_URL;
export const eventsApiKey = process.env.NEXT_PUBLIC_EVENTS_API_KEY;

export const commitModalBypassAuthorIds = (process.env.NEXT_PUBLIC_COMMIT_MODAL_BYPASS_AUTHOR_IDS ?? '')
.split(',')
Expand Down
37 changes: 37 additions & 0 deletions src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { eventsApiUrl, eventsApiKey } from './config';

type EventData = {
api_id: string;
event: {
api_id: string;
name: string;
start_at: string;
cover_url: string;
url: string;
};
};

type EventsListData = {
entries: EventData[];
hasMore: boolean;
};

export const fetchEventsList = async (limit: number, offset: number): Promise<EventsListData> => {
const queryLimit = `pagination_limit=${limit ?? 10}`;
const queryOffset = offset ? `pagination_offset=${offset}` : '';
const queryParams = `${queryLimit}${queryOffset ? `&${queryOffset}` : ''}`;
const res = await fetch(`${eventsApiUrl}/calendar/list-events?${queryParams}`, {
method: 'GET',
headers: {
accept: 'application/json',
'x-luma-api-key': eventsApiKey as string,
},
});

if (!res.ok) {
throw new Error('Failed to fetch data');
}

const data = (await res.json()) as { entries: EventData[]; has_more: boolean };
return { entries: data.entries, hasMore: data.has_more };
};

0 comments on commit ac96a26

Please sign in to comment.