Add no purge, manual delete options (#12)

- Add htmx, hx attributes
- Only add/update items since last check
- Move messages to session to persist across redirects
- Polish styles a bit (still WIP)
This commit is contained in:
2024-04-30 18:51:09 -04:00
parent d8ba178c55
commit b14399deb8
10 changed files with 163 additions and 71 deletions

View File

@@ -30,6 +30,26 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
frc_redirect('/');
}
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
$deleteQuery = $db->prepare(<<<'SQL'
DELETE FROM item
WHERE id IN (
SELECT item.id
FROM item INNER JOIN feed ON feed.id = item.feed_id
WHERE item.id = :id
AND feed.user_id = :user)
SQL);
$deleteQuery->bindValue(':id', $_GET['id']);
$deleteQuery->bindValue(':user', $_SESSION[Key::USER_ID]);
if ($deleteQuery->execute()) {
add_info('Item deleted');
} else {
add_error(Data::error($db)['error']);
}
$db->close();
frc_redirect('/');
}
$query = $db->prepare(<<<'SQL'
SELECT item.title AS item_title, item.item_link, item.published_on, item.updated_on, item.content,
feed.title AS feed_title
@@ -61,10 +81,11 @@ page_head(htmlentities("{$item['item_title']} | {$item['feed_title']}")); ?>
</div>
<article>
<div class=item_content><?=str_replace('<a ', '<a target=_blank rel=noopener ', $item['content'])?></div>
<form class=action_buttons action=/item method=POST>
<form class=action_buttons action=/item method=POST hx-post=/item>
<input type=hidden name=id value=<?=$_GET['id']?>>
<a href="/">Done</a>
<a href=/ hx-get="/">Done</a>
<button type=submit>Keep as New</button>
<button type=button hx-delete=/item>Delete</button>
</form>
</article><?php
page_foot();