WIP on add/edit feed page (#4)

This commit is contained in:
Daniel J. Summers 2024-04-06 11:02:48 -04:00
parent 74bc83f266
commit 7d30454d90
6 changed files with 94 additions and 7 deletions

View File

@ -4,6 +4,6 @@
} }
http://localhost:8205 { http://localhost:8205 {
root ./public root ./public
try_files {uri} {uri}.php try_files {path} {path}.php
php_server php_server
} }

View File

@ -23,7 +23,7 @@ class Data {
$tableQuery = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'"); $tableQuery = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'");
while ($table = $tableQuery->fetchArray(SQLITE3_NUM)) $tables[] = $table[0]; while ($table = $tableQuery->fetchArray(SQLITE3_NUM)) $tables[] = $table[0];
if (!in_array('frc_user', $tables)) { if (!in_array('frc_user', $tables)) {
$query = <<<SQL $query = <<<'SQL'
CREATE TABLE frc_user ( CREATE TABLE frc_user (
id INTEGER NOT NULL PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
email TEXT NOT NULL, email TEXT NOT NULL,
@ -33,18 +33,20 @@ class Data {
$db->exec('CREATE INDEX idx_user_email ON frc_user (email)'); $db->exec('CREATE INDEX idx_user_email ON frc_user (email)');
} }
if (!in_array('feed', $tables)) { if (!in_array('feed', $tables)) {
$query = <<<SQL $query = <<<'SQL'
CREATE TABLE feed ( CREATE TABLE feed (
id INTEGER NOT NULL PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
url TEXT NOT NULL, url TEXT NOT NULL,
title TEXT,
updated_on TEXT,
checked_on TEXT, checked_on TEXT,
FOREIGN KEY (user_id) REFERENCES frc_user (id)) FOREIGN KEY (user_id) REFERENCES frc_user (id))
SQL; SQL;
$db->exec($query); $db->exec($query);
} }
if (!in_array('item', $tables)) { if (!in_array('item', $tables)) {
$query = <<<SQL $query = <<<'SQL'
CREATE TABLE item ( CREATE TABLE item (
id INTEGER NOT NULL PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
feed_id INTEGER NOT NULL, feed_id INTEGER NOT NULL,

View File

@ -0,0 +1,35 @@
html {
min-height: 100vh;
font-family: sans-serif;
}
body {
margin: 0;
font-size: 1rem;
background-color: #eeeeee;
}
header {
padding: 0 1rem .5rem 1rem;
background: linear-gradient(#000064, #000048, #000032);
border-bottom-left-radius: .5rem;
border-bottom-right-radius: .5rem;
color: white;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: baseline;
.title {
font-size: 1.5rem;
}
a:link, a:visited {
color: white;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
}
main {
padding: 0 .5rem;
}

30
src/public/feed.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Add/Edit Feed Page
*
* Allows users to add or edit RSS feeds
*/
include '../start.php';
Security::verifyUser();
page_head('Feed page');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// TODO: get feed, add if new, reject if existing but not owned by this user, update otherwise
$feed = array();
} else {
// TODO: Retrieve feed by ID if not new
$feed = [ 'id' => $_GET['id'], 'url' => '' ];
}
?>
<h1>Add/Edit Feed</h1>
<form method=POST action=/feed hx-post=/feed>
<input type=hidden name=id value="<?=$feed['id']?>">
<label>
Feed URL
<input type=url name=url required autofocus value="<?=$feed['url']?>">
</label>
</form>
<?php
page_foot();

View File

@ -1,10 +1,16 @@
<?php <?php
/**
* Home Page
*
* Displays a list of unread feed items for the current user
*/
include '../start.php'; include '../start.php';
Security::verifyUser(); Security::verifyUser();
page_head('Welcome'); page_head('Welcome');
?> ?>
<p>User ID <?=$_REQUEST['FRC_USER_ID']?> - e-mail <?=$_REQUEST['FRC_USER_EMAIL']?></p>
<?php <?php
page_foot(); page_foot();

View File

@ -21,13 +21,27 @@ function page_head(string $title): void {
<html lang="en"> <html lang="en">
<head> <head>
<title><?=$title?> | Feed Reader Central</title> <title><?=$title?> | Feed Reader Central</title>
<link href=/assets/style.css rel=stylesheet>
</head> </head>
<body><?php <body>
<header>
<div class=title>Feed Reader Central</div>
<div><?php
if (array_key_exists('FRC_USER_ID', $_REQUEST)) {
echo '<a href=/feed?id=new>Add Feed</a>';
if ($_REQUEST['FRC_USER_EMAIL'] != 'solouser@example.com') {
echo " | {$_REQUEST['FRC_USER_EMAIL']}";
}
} ?>
</div>
</header>
<main hx-target=this>
<?php
} }
/** /**
* Render the end of the page * Render the end of the page
*/ */
function page_foot(): void { function page_foot(): void {
?></body></html><?php ?></main></body></html><?php
} }