First cut of read bookmarked item page (#14)

- Added Bookmarked link to header if items exist
This commit is contained in:
Daniel J. Summers 2024-05-23 23:02:07 -04:00
parent f4273935cb
commit 2495136fc9
2 changed files with 43 additions and 14 deletions

View File

@ -19,35 +19,48 @@ if (array_key_exists('refresh', $_GET)) {
} }
} }
$query = $db->prepare(<<<'SQL' if (key_exists('bookmarked', $_GET)) {
$itemCriteria = 'item.is_bookmarked = 1';
$returnURL = '&from=' . urlencode('/?bookmarked');
$type = 'Bookmarked';
} else {
$itemCriteria = 'item.is_read = 0';
$returnURL = '';
$type = 'Unread';
}
$title = "Your $type Items";
$query = $db->prepare(<<<SQL
SELECT item.id, item.feed_id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of, SELECT item.id, item.feed_id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of,
feed.title AS feed_title feed.title AS feed_title
FROM item FROM item
INNER JOIN feed ON feed.id = item.feed_id INNER JOIN feed ON feed.id = item.feed_id
WHERE feed.user_id = :userId WHERE feed.user_id = :userId
AND item.is_read = 0 AND $itemCriteria
ORDER BY coalesce(item.updated_on, item.published_on) DESC ORDER BY coalesce(item.updated_on, item.published_on) DESC
SQL); SQL);
$query->bindValue(':userId', $_SESSION[Key::USER_ID]); $query->bindValue(':userId', $_SESSION[Key::USER_ID]);
$result = $query->execute(); $result = $query->execute();
$item = $result ? $result->fetchArray(SQLITE3_ASSOC) : false; $item = $result ? $result->fetchArray(SQLITE3_ASSOC) : false;
page_head('Your Unread Items'); ?> page_head($title); ?>
<h1> <h1>
Your Unread Items &nbsp; <?=$title?><?php
<a class=refresh href=/?refresh hx-get=/?refresh hx-indicator="closest h1">(Refresh All Feeds)</a> if (!$type == 'Unread') { ?> &nbsp;
<span class=loading>Refreshing&hellip;</span> <a class=refresh href=/?refresh hx-get=/?refresh hx-indicator="closest h1">(Refresh All Feeds)</a>
<span class=loading>Refreshing&hellip;</span><?php
} ?>
</h1> </h1>
<article><?php <article><?php
if ($item) { if ($item) {
while ($item) { ?> while ($item) { ?>
<p><?=hx_get("/item?id={$item['id']}", strip_tags($item['item_title']))?><br> <p><?=hx_get("/item?id={$item['id']}$returnURL", strip_tags($item['item_title']))?><br>
<small><?=date_time($item['as_of'])?> &bull; <small><?=date_time($item['as_of'])?> &bull;
<?=hx_get("/feed/items?id={$item['feed_id']}&unread", htmlentities($item['feed_title']))?></small><?php <?=hx_get("/feed/items?id={$item['feed_id']}&unread", htmlentities($item['feed_title']))?></small><?php
$item = $result->fetchArray(SQLITE3_ASSOC); $item = $result->fetchArray(SQLITE3_ASSOC);
} }
} else { ?> } else { ?>
<p>There are no unread items</p><?php <p>There are no <?=strtolower($type)?> items<?php
} ?> } ?>
</article><?php </article><?php

View File

@ -52,13 +52,29 @@ function title_bar(): void {
default => FRC_VERSION default => FRC_VERSION
}; ?> }; ?>
<header hx-target=#main hx-push-url=true> <header hx-target=#main hx-push-url=true>
<div><?=hx_get('/', 'Feed Reader Central', 'class=title')?><span class=version>v<?=$version?></span></div> <div><a href=/ class=title>Feed Reader Central</a><span class=version>v<?=$version?></span></div>
<div><?php <div><?php
if (array_key_exists(Key::USER_ID, $_SESSION)) { ?> if (array_key_exists(Key::USER_ID, $_SESSION)) {
<?=hx_get('/feeds', 'Feeds')?> | <?=hx_get('/docs/', 'Docs')?> | $db = Data::getConnection();
<a href=/user/log-off>Log Off</a><?php try {
if ($_SESSION[Key::USER_EMAIL] != Security::SINGLE_USER_EMAIL) { ?> $bookQuery = $db->prepare(<<<'SQL'
| <?=$_SESSION[Key::USER_EMAIL]?><?php SELECT EXISTS(
SELECT 1
FROM item INNER JOIN feed ON item.feed_id = feed.id
WHERE feed.user_id = :id AND item.is_bookmarked = 1)
SQL);
$bookQuery->bindValue(':id', $_SESSION[Key::USER_ID]);
$bookResult = $bookQuery->execute();
$hasBookmarks = $bookResult ? $bookResult->fetchArray(SQLITE3_NUM)[0] : false; ?>
<?=hx_get('/feeds', 'Feeds')?> |
<?=$hasBookmarks ? hx_get('/?bookmarked', 'Bookmarked') . ' | ' : ''?>
<?=hx_get('/docs/', 'Docs')?> |
<a href=/user/log-off>Log Off</a><?php
if ($_SESSION[Key::USER_EMAIL] != Security::SINGLE_USER_EMAIL) { ?>
| <?=$_SESSION[Key::USER_EMAIL]?><?php
}
} finally {
$db->close();
} }
} else { ?> } else { ?>
<?=hx_get('/user/log-on', 'Log On')?> | <?=hx_get('/docs/', 'Docs')?><?php <?=hx_get('/user/log-on', 'Log On')?> | <?=hx_get('/docs/', 'Docs')?><?php