Journal renders correctly

This commit is contained in:
2024-06-22 12:30:26 -04:00
parent 4ea55d4d25
commit 0b7fa77247
7 changed files with 188 additions and 86 deletions

View File

@@ -1,64 +1,54 @@
<?php declare(strict_types=1);
use BitBadger\PDODocument\{Custom, Query};
use BitBadger\PDODocument\Mapper\DocumentMapper;
use MyPrayerJournal\{Auth,History,Layout,Request,Table};
use MyPrayerJournal\{Auth, Layout, Request, UI};
require '../../start.php';
Auth::requireUser(false);
bare_head();
$reqs = Custom::list(
Query::selectFromTable(Table::REQUEST) . " WHERE data->>'userId' = :userId AND data->>'$.history[0].action' <> 'Answered'",
[':userId' => Auth::user()['sub']], new DocumentMapper(Request::class));
Layout::bareHead();
$reqs = Request::forJournal();
if ($reqs->hasItems()) { ?>
<section id=journalItems class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 g-3" hx-target=this
hx-swap=outerHTML aria-label="Prayer Requests"><?php
$spacer = '<span>&nbsp;</span>';
foreach ($reqs->items() as /** @var Request $req */ $req) {
$withText = array_filter($req->history, fn($hist) => isset($hist->text));
$text = $withText[array_key_first($withText)]->text; ?>
foreach ($reqs->items() as /** @var Request $req */ $req) { ?>
<div class=col>
<div class="card h-100">
<div class="card-header p-0 d-flex" role=toolbar><?php
page_link("/request/edit?id=$req->id", icon('edit'),
UI::pageLink("/request/edit?id=$req->id", UI::icon('edit'),
['class' => 'btn btn-secondary', 'title' => 'Edit Request']); ?>
<?=$spacer?>
<button type=button class="btn btn-secondary" title="Add Notes" data-bs-toggle=modal
data-bs-target=#notesModal hx-get="/components/request/add-notes?id=<?=$req->id?>"
hx-target=#notesBody hx-swap=innerHTML><?=icon('comment');?></button>
hx-target=#notesBody hx-swap=innerHTML><?=UI::icon('comment');?></button>
<?=$spacer?>
<button type=button class="btn btn-secondary" title="Snooze Request" data-bs-toggle=modal
data-bs-target=#snoozeModal hx-get="/components/request/snooze?id=<?=$req->id?>"
hx-target=#snoozeBody hx-swap=innerHTML><?=icon('schedule');?></button>
hx-target=#snoozeBody hx-swap=innerHTML><?=UI::icon('schedule');?></button>
<div class=flex-grow-1></div>
<button type=button class="btn btn-success w-25" hx-patch="/request/prayed?id=<?=$req->id?>"
title="Mark as Prayed"><?=icon('done');?></button>
title="Mark as Prayed"><?=UI::icon('done');?></button>
</div>
<div class=card-body>
<p class=request-text><?=htmlentities($text);?>
<p class=request-text><?=htmlentities($req->currentText());?>
</div>
<div class="card-footer text-end text-muted px-1 py-0">
<em>last activity <?=$req->history[0]->asOf?></em>
<?php /*
TODO: relative time
[] [
match req.LastPrayed with
| Some dt -> str "last prayed "; relativeDate dt now tz
| None -> str "last activity "; relativeDate req.AsOf now tz
] */ ?>
<em><?php
$lastPrayed = $req->lastPrayed();
echo 'last ' . (is_null($lastPrayed) ? 'activity': 'prayed') . ' ';
UI::relativeDate($lastPrayed ?? $req->history[0]->asOf); ?>
</em>
</div>
</div>
</div><?php
} ?>
</section><?php
} else {
Layout::noResults('No Active Requests', '/request/edit?id=new', 'Add a Request', <<<'TEXT'
UI::noResults('No Active Requests', '/request/edit?id=new', 'Add a Request', <<<'TEXT'
You have no requests to be shown; see the &ldquo;Active&rdquo; link above for snoozed or deferred requests, and
the &ldquo;Answered&rdquo; link for answered requests
TEXT);
}
bare_foot();
Layout::bareFoot();