Skip to content

Commit

Permalink
feat: show last updated at on public views (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio authored Nov 28, 2024
1 parent a24bdad commit 179678c
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 3 deletions.
37 changes: 37 additions & 0 deletions app/View/Components/LastUpdatedAt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\View\Components;

use App\Models\Election;
use Carbon\Carbon;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class LastUpdatedAt extends Component
{
public Election $election;

public ?Carbon $timestamp = null;

public function __construct(Election $election, string $page)
{
$this->election = $election;

$this->timestamp = match ($page) {
'turnout' => $election->turnouts_updated_at,
'results' => $election->records_updated_at,
};
}

public function shouldRender(): bool
{
return filled($this->timestamp);
}

public function render(): View
{
return view('components.last-updated-at');
}
}
2 changes: 2 additions & 0 deletions resources/views/components/election/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
{{ $election->subtitle }}
@endif
</span>

<x-last-updated-at :$election :$page />
</header>
2 changes: 1 addition & 1 deletion resources/views/components/election/title.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="flex justify-between">
<div class="">
<div>
<h1 class="text-xl font-semibold text-gray-900 sm:text-2xl">{{ $title }}</h1>
<h2 class="font-medium text-gray-900 sm:text-lg">
{{ $level->getLabel() }}
Expand Down
8 changes: 8 additions & 0 deletions resources/views/components/last-updated-at.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div {{ $attributes->class(['flex gap-1 text-sm']) }}>
<span class="text-gray-700">Ultima actualizare:</span>
<time
class="font-medium text-gray-900"
datetime="{{ $timestamp->toIso8601String() }}">
{{ $timestamp->toDateTimeString() }}
</time>
</div>
2 changes: 2 additions & 0 deletions resources/views/livewire/embeds/area.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:county="$county"
:locality="$locality" />

<x-last-updated-at :$election page="turnout" class="-mt-8" />

<livewire:charts.turnout-area-chart
:parameters="$this->getQueryParameters()"
:election="$election"
Expand Down
2 changes: 2 additions & 0 deletions resources/views/livewire/embeds/candidates.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
:county="$county"
:locality="$locality" />

<x-last-updated-at :$election page="turnout" class="-mt-8" />

<x-candidates.turnouts-table :items="$this->candidates" />
</div>
2 changes: 2 additions & 0 deletions resources/views/livewire/embeds/demographic.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:county="$county"
:locality="$locality" />

<x-last-updated-at :$election page="turnout" class="-mt-8" />

<livewire:charts.turnout-population-pyramid-chart
:parameters="$this->getQueryParameters()"
:election="$election"
Expand Down
2 changes: 2 additions & 0 deletions resources/views/livewire/embeds/election-results.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:county="$county"
:locality="$locality" />

<x-last-updated-at :$election page="results" class="-mt-8" />

@if (filled($this->aggregate))
<x-stacked-bar
:show-threshold="data_get($election, 'properties.show_threshold', false)"
Expand Down
2 changes: 2 additions & 0 deletions resources/views/livewire/embeds/election-turnouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
:county="$county"
:locality="$locality" />

<x-last-updated-at :$election page="turnout" class="-mt-8" />

@if (filled($this->aggregate))
@if ($this->aggregate->max)
<x-turnout-bar :value="$this->aggregate->value" :max="$this->aggregate->max" />
Expand Down
4 changes: 3 additions & 1 deletion resources/views/livewire/embeds/top-counties.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div class="grid gap-8">
<div class="grid gap-2">
<x-last-updated-at :$election page="turnout" class="justify-end" />

<livewire:charts.top-counties-chart :election="$election" />
</div>
4 changes: 3 additions & 1 deletion resources/views/livewire/embeds/top-localities.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div class="grid gap-8">
<div class="grid gap-2">
<x-last-updated-at :$election page="turnout" class="justify-end" />

<livewire:charts.top-localities-chart :election="$election" />
</div>

0 comments on commit 179678c

Please sign in to comment.