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
+16 -26
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();
+4 -2
View File
@@ -1,18 +1,20 @@
<?php declare(strict_types=1);
use MyPrayerJournal\Auth;
use MyPrayerJournal\UI;
require '../start.php';
Auth::requireUser();
$user = Auth::user();
$name = $user['first_name'] ?? 'Your';
$name = $user['given_name'] ?? 'Your';
page_head('Welcome'); ?>
<article class="container-fluid mt-3">
<h2 class=pb-3><?=$name?><?=$name == 'Your' ? '' : '&rsquo;s'?> Prayer Journal</h2>
<p class="pb-3 text-center"><?php
page_link('/request/new/edit', icon('add_box') . ' Add a Prayer Request', ['class' => 'btn btn-primary']); ?>
UI::pageLink('/request/edit?id=new', UI::icon('add_box') . ' Add a Prayer Request',
['class' => 'btn btn-primary']); ?>
<p hx-get=/components/journal-items hx-swap=outerHTML hx-trigger=load hx-target=this>
Loading your prayer journal&hellip;
<div id=notesModal class="modal fade" tabindex=-1 aria-labelledby=nodesModalLabel aria-hidden=true>
+7 -4
View File
@@ -1,5 +1,7 @@
<?php declare(strict_types=1);
use MyPrayerJournal\UI;
require '../../start.php';
page_head('Terms of Service'); ?>
@@ -20,8 +22,9 @@ page_head('Terms of Service'); ?>
<p class=card-text>
myPrayerJournal is a service that allows individuals to enter and amend their prayer requests. It
requires no registration by itself, but access is granted based on a successful login with an
external identity provider. See <?php page_link('/legal/privacy-policy', 'our privacy policy'); ?>
for details on how that information is accessed and stored.
external identity provider. See
<?php UI::pageLink('/legal/privacy-policy', 'our privacy policy'); ?> for details on how that
information is accessed and stored.
</div>
<div class=list-group-item>
<h3>3. Third Party Services</h3>
@@ -49,7 +52,7 @@ page_head('Terms of Service'); ?>
</div>
</div>
<p class=pt-3>
You may also wish to review our <?php page_link('/legal/privacy-policy', 'privacy policy'); ?> to learn how we
handle your data.
You may also wish to review our <?php UI::pageLink('/legal/privacy-policy', 'privacy policy'); ?> to learn how
we handle your data.
</article><?php
page_foot();