Skip to content

Commit

Permalink
Add country key indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri authored and samshara committed Jan 12, 2024
1 parent 697c3f6 commit 25563bf
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 45 deletions.
6 changes: 0 additions & 6 deletions src/components/domain/CountryPageEmptyMessage/i18n.json

This file was deleted.

30 changes: 0 additions & 30 deletions src/components/domain/CountryPageEmptyMessage/index.tsx

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/views/CountryProfile/styles.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.country-profile {
display: flex;
flex-direction: column;
padding: var(--go-ui-spacing-2xl) 0;
gap: var(--go-ui-spacing-2xl);
padding: var(--go-ui-spacing-2xl) 0;
}
9 changes: 8 additions & 1 deletion src/views/CountryProfileOverview/i18n.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"namespace": "countryProfileOverview",
"strings": {
"pageTitle": "Country Profile Overview"
"countryIndicatorsTitle": "Country Key Indicators",
"countryIndicatorsPopulationLabel": "Population",
"countryIndicatorsUrbanPopulationLabel": "Urban Pop",
"countryIndicatorsGDPLabel": "GDP",
"countryIndicatorsPovertyLabel": "Poverty (%POP)",
"countryIndicatorsLifeExpectancyLabel": "Life Expectancy",
"countryIndicatorsLiteracyLabel": "Literacy",
"countryIndicatorsCapitaLabel": "GNI/Capita"
}
}
77 changes: 73 additions & 4 deletions src/views/CountryProfileOverview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,85 @@
import CountryPageEmptyMessage from '#components/domain/CountryPageEmptyMessage';
import { useOutletContext } from 'react-router-dom';
import { isDefined, isNotDefined } from '@togglecorp/fujs';

import BlockLoading from '#components/BlockLoading';
import Container from '#components/Container';
import TextOutput from '#components/TextOutput';
import useTranslation from '#hooks/useTranslation';
import { type CountryOutletContext } from '#utils/outletContext';
import { useRequest } from '#utils/restRequest';

import i18n from './i18n.json';
import styles from './styles.module.css';

// eslint-disable-next-line import/prefer-default-export
export function Component() {
const strings = useTranslation(i18n);

const { countryId } = useOutletContext<CountryOutletContext>();

const {
pending: indicatorPending,
response: indicatorResponse,
} = useRequest({
url: '/api/v2/country/{id}/databank/',
skip: isNotDefined(countryId),
pathVariables: isDefined(countryId) ? {
id: Number(countryId),
} : undefined,
});

return (
<CountryPageEmptyMessage
title={strings.pageTitle}
/>
<Container
className={styles.countryIndicators}
childrenContainerClassName={styles.indicatorContent}
heading={strings.countryIndicatorsTitle}
headingLevel={4}
withHeaderBorder
>
{indicatorPending && <BlockLoading className={styles.loading} />}
<TextOutput
label={strings.countryIndicatorsPopulationLabel}
value={indicatorResponse?.population}
valueType="number"
strongValue
/>
<TextOutput
label={strings.countryIndicatorsUrbanPopulationLabel}
value={`${indicatorResponse?.urban_population} %`}
valueType="text"
strongValue
/>
<TextOutput
label={strings.countryIndicatorsGDPLabel}
value={indicatorResponse?.gdp}
valueType="number"
strongValue
/>
<TextOutput
label={strings.countryIndicatorsCapitaLabel}
value={indicatorResponse?.gnipc}
valueType="number"
strongValue
/>
<TextOutput
label={strings.countryIndicatorsPovertyLabel}
value={`${indicatorResponse?.poverty} %`}
valueType="text"
strongValue
/>
<TextOutput
label={strings.countryIndicatorsLifeExpectancyLabel}
value={indicatorResponse?.life_expectancy}
valueType="number"
strongValue
/>
<TextOutput
label={strings.countryIndicatorsLiteracyLabel}
value={`${indicatorResponse?.literacy} %`}
valueType="text"
strongValue
/>
</Container>
);
}

Expand Down
27 changes: 27 additions & 0 deletions src/views/CountryProfileOverview/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.country-indicators {
.indicator-content {
display: grid;
border-radius: var(--go-ui-border-radius-lg);
box-shadow: var(--go-ui-box-shadow-md);
background-color: var(--go-ui-color-background);
padding: var(--go-ui-spacing-md);
grid-gap: var(--go-ui-spacing-md);
grid-template-columns: 1fr 1fr 1fr;

@media screen and (max-width: 60rem) {
grid-template-columns: 1fr 1fr;
}

@media screen and (max-width: 30rem) {
grid-template-columns: 1fr;
}
}

.loading {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}

0 comments on commit 25563bf

Please sign in to comment.