List unread items on home page (#6)

- Fix feed update (latent bug on #4)
This commit is contained in:
Daniel J. Summers 2024-04-13 12:10:07 -04:00
parent d9dc3ec361
commit 9b2190252f
5 changed files with 50 additions and 9 deletions

View File

@ -190,10 +190,12 @@ class Feed {
&& ( $existing['published_on'] != $item['published']
|| $existing['updated_on'] ?? '' != $item['updated'] ?? '')) {
self::updateItem($existing['id'], $item, $db);
}
} else {
self::addItem($feedId, $item, $db);
}
} else {
throw new Exception($db->lastErrorMsg());
}
}
} catch (Exception $ex) {
return ['error' => $ex->getMessage()];

View File

@ -5,8 +5,15 @@ html {
body {
margin: 0;
font-size: 1rem;
background: linear-gradient(135deg, #eeeeff, #ddddff, #eeeeff, #ccccff);
/* background-color: #eeeeee; */
background: linear-gradient(135deg, #eeeeff, #ddddff, #eeeeff, #ccccff) fixed;
}
a:link, a:visited {
text-decoration: none;
font-weight: bold;
color: navy;
}
a:hover {
text-decoration: underline;
}
header {
padding: 0 1rem .5rem 1rem;
@ -25,10 +32,6 @@ header {
a:link, a:visited {
color: white;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
}
main {

View File

@ -9,6 +9,35 @@ include '../start.php';
Security::verifyUser();
$db = Data::getConnection();
$result = $db->query(<<<'SQL'
SELECT item.id, item.title AS item_title, coalesce(item.updated_on, item.published_on) AS as_of,
feed.title AS feed_title
FROM item
INNER JOIN feed ON feed.id = item.feed_id
WHERE item.is_read = 0
ORDER BY coalesce(item.updated_on, item.published_on) DESC
SQL);
$item = $result ? $result->fetchArray(SQLITE3_ASSOC) : false;
page_head('Welcome'); ?>
<p>Unread items go here</p><?php
<h1>Your Unread Items</h1>
<article><?php
if ($item) {
while ($item) {
try {
$asOf = (new DateTimeImmutable($item['as_of']))->format(DATE_TIME_FORMAT);
} catch (Exception) {
$asOf = '(invalid date)';
} ?>
<p><a href=/item/view?id=<?=$item['id']?>><?=htmlentities($item['item_title'])?></a><br>
<?=htmlentities($item['feed_title'])?><br><small><em><?=$asOf?></em></small><?php
$item = $result->fetchArray(SQLITE3_ASSOC);
}
} else { ?>
<p>There are no unread items</p><?php
} ?>
</article><?php
page_foot();
$db->close();

View File

@ -19,5 +19,12 @@ const SECURITY_MODEL = Security::SINGLE_USER;
/** The name of the database file where users and feeds should be kept */
const DATABASE_NAME = 'frc.db';
/**
* The format for date/time outputs; see https://www.php.net/manual/en/datetime.format.php for acceptable values
*
* The default, 'F j, Y \a\t g:ia', equates to "August 17, 2023 at 4:45pm"
*/
const DATE_TIME_FORMAT = 'F j, Y \a\t g:ia';
// END USER CONFIGURATION ITEMS
// (editing below this line is not advised)