Skip to content

Commit

Permalink
Change how to pull the last data update for the MarineConservation wi…
Browse files Browse the repository at this point in the history
…dget
  • Loading branch information
SARodrigues committed Oct 31, 2023
1 parent d7997d9 commit cbbec57
Showing 1 changed file with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,43 @@ type MarineConservationWidgetProps = {
};

const MarineConservationWidget: React.FC<MarineConservationWidgetProps> = ({ location }) => {
const defaultQueryParams = {
filters: {
location: {
code: location.code,
},
},
};

const { data: dataLastUpdate } = useGetProtectionCoverageStats(
{
...defaultQueryParams,
sort: 'updatedAt:desc',
'pagination[limit]': 1,
},
{
query: {
select: ({ data }) => data?.[0]?.attributes?.updatedAt,
placeholderData: { data: null },
},
}
);

const {
data: { data: protectionStatsData, meta: protectionStatsMeta },
data: { data: protectionStatsData },
} = useGetProtectionCoverageStats(
{
...defaultQueryParams,
populate: '*',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
'sort[year]': 'asc',
filters: {
location: {
code: location.code,
},
// protection_status: {
// slug: 'oecm', // oecm | mpa
// },
},
'pagination[limit]': -1,
},
{
query: {
select: ({ data, meta }) => ({ data, meta }),
placeholderData: { data: [], meta: undefined },
select: ({ data }) => ({ data }),
placeholderData: { data: [] },
},
}
);
Expand Down Expand Up @@ -119,7 +134,7 @@ const MarineConservationWidget: React.FC<MarineConservationWidgetProps> = ({ loc
if (!stats || !chartData) return null;

return (
<Widget title="Marine Conservation Coverage" lastUpdated={protectionStatsMeta?.updatedAt}>
<Widget title="Marine Conservation Coverage" lastUpdated={dataLastUpdate}>
<div className="mt-6 mb-4 flex flex-col text-blue">
<span className="text-5xl font-bold">
{stats?.protectedPercentage}
Expand Down

0 comments on commit cbbec57

Please sign in to comment.