Skip to content

Commit

Permalink
replace comm count on dash with uptodate percent
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Dec 22, 2023
1 parent 6a0d4c6 commit e5221ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
7 changes: 3 additions & 4 deletions src/components/DashboardStat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
<div class="space-y-5 p-5 {border}">
<h3 class="text-center text-xl text-primary dark:text-white md:h-[56px] md:text-left">
{title}
{#if title === 'Number of communities'}
<a href="/communities"><i class="fa-solid fa-circle-info text-base" /></a>
{/if}
{#if loading}
<LoadingSpinner color="text-link" style="inline" />
{/if}
</h3>
<div class="flex justify-center md:justify-start">
{#if stat !== undefined}
<span class="text-5xl font-semibold text-primary dark:text-white">{stat}</span>
<span class="text-5xl font-semibold text-primary dark:text-white">
{stat}{title === 'Up-To-Date Percent' ? '%' : ''}
</span>
{#if percent}
<span
class="{percent === '+0'
Expand Down
42 changes: 13 additions & 29 deletions src/routes/dashboard/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<script lang="ts">
import { browser } from '$app/environment';
import { DashboardStat, Footer, Header, HeaderPlaceholder } from '$lib/comp';
import {
areaError,
areas,
eventError,
events,
reportError,
reports,
syncStatus,
theme
} from '$lib/store';
import { eventError, events, reportError, reports, syncStatus, theme } from '$lib/store';
import type { ChartHistory, EventType, Report } from '$lib/types';
import { detectTheme, errToast, updateChartThemes } from '$lib/utils';
import Chart from 'chart.js/auto';
Expand All @@ -20,9 +11,6 @@
// alert for event errors
$: $eventError && errToast($eventError);
// alert for area errors
$: $areaError && errToast($areaError);
// alert for report errors
$: $reportError && errToast($reportError);
Expand Down Expand Up @@ -80,20 +68,6 @@
})
: [];
$: communities =
$areas && $areas.length && $reports && $reports.length
? $areas.filter(
(area) =>
area.tags.type === 'community' &&
area.tags.geo_json &&
area.tags.name &&
area.tags['icon:square'] &&
area.tags.continent &&
Object.keys(area.tags).find((key) => key.includes('contact')) &&
$reports.find((report) => report.area_id === area.id)
)
: undefined;
const getStatPeriod = () => {
return new Date(new Date().getTime() - 24 * 60 * 60 * 1000).getTime();
};
Expand Down Expand Up @@ -140,6 +114,8 @@
$: lightning = stats && stats[0].tags.total_elements_lightning;
$: nfc = stats && stats[0].tags.total_elements_lightning_contactless;
$: upToDatePercent = stats && stats[0].tags.up_to_date_percent;
$: totalChange =
stats && total
? new Intl.NumberFormat('en-US', { signDisplay: 'always' }).format(
Expand Down Expand Up @@ -207,6 +183,13 @@
)
: '';
$: upToDatePercentChange =
stats && upToDatePercent
? new Intl.NumberFormat('en-US', { signDisplay: 'always' }).format(
upToDatePercent - stats[1].tags.up_to_date_percent
)
: undefined;
let upToDateChartCanvas: HTMLCanvasElement;
let upToDateChart: Chart<'line', number[] | undefined, string>;
let totalChartCanvas: HTMLCanvasElement;
Expand Down Expand Up @@ -703,8 +686,9 @@
loading={$syncStatus && chartsRendered}
/>
<DashboardStat
title="Number of communities"
stat={communities && communities.length}
title="Up-To-Date Percent"
stat={upToDatePercent}
change={upToDatePercentChange}
loading={$syncStatus && chartsRendered}
/>
</div>
Expand Down

0 comments on commit e5221ca

Please sign in to comment.