Skip to content

Commit

Permalink
Add TrafficJamsCounter and A11yTransportCounters
Browse files Browse the repository at this point in the history
  • Loading branch information
sashachabin committed Jul 4, 2023
1 parent 7e512cb commit 5d1a8c0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
38 changes: 29 additions & 9 deletions client/api/main-page/main-page.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
import { Unit } from 'transport-common/types/masstrans';
import { fetchApi } from 'api/utils/fetch';

export const MainPageApi = {
getCards: () => {
return fetchApi(
getCards: async () => {
return await fetchApi(
'https://transport-cms.ekaterinburg.io/api/cards/?populate=backgroundImage',
{ dataField: 'data' },
);
},

getMarqueeItems: () => {
return fetchApi('https://transport-cms.ekaterinburg.io/api/marquees', {
dataField: 'data',
});
getTrafficJamsCounter: async () => {
return await fetchApi(
'https://ekb-probki.vercel.app/api',
{ dataField: 'score' },
);
},

getNotifications: () => {
return fetchApi('https://transport-cms.ekaterinburg.io/api/notifications', {
getA11yTransportCounters: async () => {
const countA11yUnits = async (type) => {
const units = <Unit[]>await fetchApi(
`https://transport.ekaterinburg.city/api/masstrans/${type}`,
{ dataField: 'data' }
);
return units
.filter(({ accessibility }) => accessibility)
.length;
}

return {
buses: await countA11yUnits('bus'),
trolls: await countA11yUnits('troll'),
trams: await countA11yUnits('tram')
}
},

getMarqueeItems: async () => {
return await fetchApi('https://transport-cms.ekaterinburg.io/api/marquees', {
dataField: 'data',
});
},
}
};
6 changes: 6 additions & 0 deletions client/api/main-page/main-page.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export interface Card {
};
}

export interface AccessibilityTransportCounters {
buses: number,
trolls: number,
trams: number
}

interface Thumbnail {
ext: string;
url: string;
Expand Down
13 changes: 4 additions & 9 deletions client/components/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,17 @@ import { Marquee } from './Marquee/Marquee';

const cn = classNames.bind(styles);

export function MainPage({ cards, marqueeItems, notifications }: MainPageTypes) {
export function MainPage({ cards, trafficJams, a11yTransportCounters, marqueeItems }: MainPageTypes) {
// TODO Output data to dynamic cards
console.log({ trafficJams, a11yTransportCounters });

return (
<div className={cn(styles.MainPage)}>
<div className={cn(styles.MainPageInner)}>
<div className={cn(styles.MainPageLogo)}>
<Logo />
<h1 className={cn(styles.MainPageTitle)}>Транспорт Екатеринбурга</h1>
</div>
{/* {notifications.map(({ id, attributes }) => (
<Notification
text={attributes.text}
title={attributes.title}
image={attributes.image}
key={id}
/>
))} */}

<div className={styles.MainPageCardGrid}>
{cards
Expand Down
9 changes: 8 additions & 1 deletion client/components/MainPage/MainPage.types.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { Card, Marquee, Notification } from 'api/main-page/main-page.types';
import type {
Card,
AccessibilityTransportCounters,
Marquee,
Notification
} from 'api/main-page/main-page.types';

export type MainPageTypes = {
cards: Card[];
trafficJams: number;
a11yTransportCounters: AccessibilityTransportCounters,
notifications: Notification[];
marqueeItems: Marquee[];
};
9 changes: 5 additions & 4 deletions client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export default function Home(props) {
export async function getStaticProps() {
return {
props: {
cards: (await MainPageApi.getCards()) || [],
marqueeItems: (await MainPageApi.getMarqueeItems()) || [],
notifications: (await MainPageApi.getNotifications()) || [],
cards: await MainPageApi.getCards() || [],
trafficJams: await MainPageApi.getTrafficJamsCounter() || null,
a11yTransportCounters: await MainPageApi.getA11yTransportCounters() || {},
marqueeItems: await MainPageApi.getMarqueeItems() || [],
},
revalidate: 15,
revalidate: 60,
};
}

1 comment on commit 5d1a8c0

@ekbdev
Copy link

@ekbdev ekbdev commented on 5d1a8c0 Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for transport ready!

✅ Preview
https://transport-ope5s5yn8-ekbdev.vercel.app
https://ekbdev-transport-feature-main-page-data.vercel.app

Built with commit 5d1a8c0.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.