aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Digitigrade/Model/UserAccount.php13
-rw-r--r--locale/en_GB.json4
-rw-r--r--routes/note_fragment.php12
-rw-r--r--static/style.css39
-rw-r--r--templates/skeleton.php20
-rw-r--r--templates/write_note_form.php9
6 files changed, 83 insertions, 14 deletions
diff --git a/Digitigrade/Model/UserAccount.php b/Digitigrade/Model/UserAccount.php
index 3d0e2a4..72a9ce9 100644
--- a/Digitigrade/Model/UserAccount.php
+++ b/Digitigrade/Model/UserAccount.php
@@ -1,6 +1,7 @@
<?php
namespace Digitigrade\Model;
+use Digitigrade\HttpResponseStatus\Unauthorized;
use Digitigrade\Model;
class UserAccount extends Model {
@@ -46,6 +47,18 @@ class UserAccount extends Model {
return Session::findByToken($token)?->userAccount;
}
+ /**
+ * Gets the currently logged-in user account, or throws an error
+ * @throws Unauthorized if no account could be found
+ */
+ public static function requireByCurrentSession(): self {
+ $user = self::findByCurrentSession();
+ if ($user == null) {
+ throw new Unauthorized();
+ }
+ return $user;
+ }
+
public function verifyPassword(#[\SensitiveParameter] $attemptedPassword): bool {
return password_verify($attemptedPassword, $this->passwordHash);
}
diff --git a/locale/en_GB.json b/locale/en_GB.json
index 917e375..deda419 100644
--- a/locale/en_GB.json
+++ b/locale/en_GB.json
@@ -21,5 +21,7 @@
"login.password": "Password",
"login.rememberMe": "Remember me (stay logged in)",
"login.action": "Log in",
- "login.failed": "Invalid email address or password"
+ "login.failed": "Invalid email address or password",
+ "writeNote.label": "Write a note",
+ "writeNote.action": "Post"
}
diff --git a/routes/note_fragment.php b/routes/note_fragment.php
index ef2e7b0..3cb1fcc 100644
--- a/routes/note_fragment.php
+++ b/routes/note_fragment.php
@@ -1,10 +1,22 @@
<?php
use Digitigrade\Model\Note;
+use Digitigrade\Model\UserAccount;
use Digitigrade\Router;
Router::getInstance()->mount('/fragment/note/:id/:action', function (array $args) {
$note = Note::find($args['id']);
// TODO: actually like/dislike/reshare the note as the currently signed in user
render_template('interaction_button', ['action' => $args['action'], 'active' => true, 'note' => $note]);
+});
+
+Router::getInstance()->mount('/fragment/note', function (array $args) {
+ // posting a new note
+ $author = UserAccount::requireByCurrentSession();
+ if (isset($_POST['content'])) {
+ // TODO: summary field, post language, privacy, etc
+ $note = Note::create($author->actor, $_POST['content'], 'unk');
+ $note->publish();
+ }
+ render_template('write_note_form');
}); \ No newline at end of file
diff --git a/static/style.css b/static/style.css
index 15f2665..01281d8 100644
--- a/static/style.css
+++ b/static/style.css
@@ -6,20 +6,24 @@ body {
padding: 0;
font-family: "DM Sans", sans-serif;
font-size: 12pt;
- display: flex;
- flex-direction: column;
- align-items: center;
+ display: grid;
+ grid-template-rows: max-content 1fr;
+ justify-items: center;
+ min-height: 100vh;
+ width: 100%;
}
header {
background: #3b005e;
color: white;
+ position: sticky;
+ top: 0;
padding: 8px;
margin-bottom: 8px;
display: flex;
flex-direction: column;
align-items: center;
- width: 100vw;
+ width: 100%;
box-sizing: border-box;
}
@@ -28,7 +32,7 @@ header {
}
nav {
- width: min(800px, 100vw);
+ width: min(800px, 100%);
height: 32px;
box-sizing: border-box;
display: grid;
@@ -72,7 +76,20 @@ nav {
}
main {
- width: min(800px, 100vw);
+ width: min(1300px, 100%);
+ display: grid;
+ grid-template-columns: 1fr min(700px, 100%) 1fr;
+ height: 100%;
+ #leftPane,
+ #rightPane {
+ position: sticky;
+ top: 56px;
+ height: max-content;
+ }
+ @media (width < 1300px) {
+ grid-auto-flow: row;
+ grid-template-columns: 1fr;
+ }
}
h1 {
@@ -233,12 +250,13 @@ form {
gap: 16px;
max-width: max-content;
- label:has(+ input) {
+ label:has(+ input, + textarea) {
display: block;
font-size: 10pt;
color: #555;
}
- input:not([type="checkbox"]) {
+ input:not([type="checkbox"]),
+ textarea {
display: block;
border: 1px solid #3334;
border-radius: 8px;
@@ -248,7 +266,10 @@ form {
font-size: inherit;
color: inherit;
background: #fff;
- width: 24em;
+ width: min(60vw, 24em, calc(100% - 16px));
+ }
+ textarea {
+ resize: vertical;
}
button {
background: #3b005e;
diff --git a/templates/skeleton.php b/templates/skeleton.php
index 8ac1549..072f812 100644
--- a/templates/skeleton.php
+++ b/templates/skeleton.php
@@ -35,10 +35,22 @@ $user = Digitigrade\Model\UserAccount::findByCurrentSession();
</nav>
</header>
<main>
- <?php if (!isset($renderTitleHeading) || $renderTitleHeading): ?>
- <h1><?= $pageTitle ?></h1>
- <?php endif; ?>
- <?php slot(); ?>
+ <section id="leftPane">
+ <?php
+ if ($user != null) {
+ call_template('write_note_form');
+ }
+ ?>
+ </section>
+ <section id="centrePane">
+ <?php if (!isset($renderTitleHeading) || $renderTitleHeading): ?>
+ <h1><?= $pageTitle ?></h1>
+ <?php endif; ?>
+ <?php slot(); ?>
+ </section>
+ <section id="rightPane">
+
+ </section>
</main>
</body>
diff --git a/templates/write_note_form.php b/templates/write_note_form.php
new file mode 100644
index 0000000..49fcafc
--- /dev/null
+++ b/templates/write_note_form.php
@@ -0,0 +1,9 @@
+<form action="/todo" method="post" hx-post="/fragment/note" hx-swap="outerHTML" hx-disabled-elt="find button">
+ <div class="row">
+ <label for="noteContent"><?= __('writeNote.label') ?></label>
+ <textarea name="content" id="noteContent"></textarea>
+ </div>
+ <div class="row">
+ <button><?= __('writeNote.action') ?></button>
+ </div>
+</form> \ No newline at end of file