widget/reply: redirect to created comment
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 27 Dec 2020 01:32:00 +0000 (02:32 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 1 Jan 2021 17:30:40 +0000 (18:30 +0100)
Undo initial design of continuous uploads, rather have normal form behaviour
of showing feedback/results.

issue/index.php
progress.js
widget/reply.php

index 87b22a39d876ac8774a1a1a512e52e025e9176b0..62182ac28356c72c40bc029118f9c798a6497bc7 100644 (file)
@@ -5,7 +5,7 @@ require_once 'database.inc.php';
 
 if ($id and ctype_digit($id)) {
        $Page->title = "Issue #$id";
-       $Page->path = "/$id";  # minimal reference
+       $Page->link = $Page->handler . ($Page->path = "/$id");  # minimal reference
        $Issue = $Db->query(
                'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page->handler, $id]
        )->fetch();
index e59422de841e879c2c176475e2896796c6d3c7c8..575b98e83cf8ef74a833a471815fbf5132ded202 100644 (file)
@@ -3,6 +3,10 @@ function showsize(bytes) {
 }
 
 function trackupload(input) {
+       if (!input.value) {
+               return true; // default form action
+       }
+
        var progress = document.getElementById('progress');
        if (!progress) {
                progress = document.createElement('DIV');
@@ -26,7 +30,7 @@ function trackupload(input) {
                if (e.target.status == 200) {
                        progress.textContent = 'voltooid';
                        progress.innerHTML += ' <small>(' + showsize(input.files[0].size) + ' MB)</small>';
-                       input.value = '';
+                       window.location.assign(e.target.response);
                }
                else {
                        progress.textContent = 'fout';
@@ -53,14 +57,14 @@ function trackupload(input) {
        cancel.onclick = function () { ajax.abort() };
        cancel.style.float = 'left';
        input.parentNode.insertBefore(cancel, progress.parentNode);
+       return false;
 }
 
 document.addEventListener('DOMContentLoaded', e => {
        for (let row of document.forms[0].elements) {
                if (row.type == 'file') {
                        row.form.onsubmit = () => {
-                               trackupload(row);
-                               return false;
+                               return trackupload(row);
                        };
                }
        }
index 1f6d0e2ff0352f709ff0223fdd455c1d3962eded..0935567e82ecb51ba2aeb4ff0a6717b50e313abe 100644 (file)
@@ -61,9 +61,8 @@ if ($_POST) {
                        }
                }
 
-               if ($Page->api) {
-                       abort("/{$Page->link}", '200 reply success');
-               }
+               $target = "/{$Page->link}/$newcomment#$newcomment";
+               abort($target, ($Page->api ? 200 : 303) . ' reply success');
                $_POST['reply'] = NULL;
        }
        catch (Exception $e) {
@@ -81,7 +80,7 @@ print '<ul class="replies">';
 
 while ($row = $query->fetch()) {
        $rowuser = new User("profile/{$row->author}");
-       print '<li>';
+       printf('<li id="%d">', $row->id);
        printf('<strong>%s</strong> <small class=date>%s</small>',
                $rowuser->html, showdate(preg_split('/\D/', $row->created))
        );