add progress bar for editing posts

master
Aevann 2024-11-13 00:02:48 +02:00
parent 61b52ce2d9
commit 885414270b
3 changed files with 18 additions and 2 deletions

View File

@ -312,7 +312,7 @@ function reload() {
location.reload();
}
function sendFormXHR(form, extraActionsOnSuccess) {
function setupFormXhr(form, extraActionsOnSuccess) {
if (typeof close_inline_emoji_modal === "function") {
close_inline_emoji_modal();
}
@ -354,6 +354,11 @@ function sendFormXHR(form, extraActionsOnSuccess) {
form.classList.remove('is-submitting');
};
return xhr
}
function sendFormXHR(form, extraActionsOnSuccess) {
const xhr = setupFormXhr(form, extraActionsOnSuccess);
xhr.send(formData);
}

View File

@ -47,3 +47,10 @@ if (fake_textarea) {
location.href = fake_textarea.dataset.href;
});
}
function edit_post(form) {
const xhr = setupFormXhr(form, reload);
const upload_prog = document.getElementById('upload-prog-edit-post');
xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)};
xhr.send(formData);
}

View File

@ -215,7 +215,7 @@
{% if v and v.can_edit(p) %}
<div id="edit-post-body-{{p.id}}" class="d-none comment-write collapsed child">
<form id="post-edit-form-{{p.id}}" action="/edit_post/{{p.id}}" method="post" enctype="multipart/form-data" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRReload(this)">
<form id="post-edit-form-{{p.id}}" action="/edit_post/{{p.id}}" method="post" enctype="multipart/form-data" data-nonce="{{g.nonce}}" data-onsubmit="edit_post(this)">
<input hidden name="formkey" value="{{v|formkey}}" class="notranslate" translate="no">
<input hidden name="current_page" value="{{request.path}}">
<textarea id="post-edit-title" autocomplete="off" maxlength="500" name="title" class="comment-box form-control rounded" required placeholder="Title">{{p.title}}</textarea>
@ -234,6 +234,10 @@
<a class="text-small mt-3 d-inline-block" href="/formatting" data-target="t" target="_blank">Formatting help</a>
<button type="submit" form="post-edit-form-{{p.id}}" class="btn btn-primary ml-2 fl-r" data-nonce="{{g.nonce}}" data-onclick="remove_dialog()">Save Edit</button>
<button type="button" data-nonce="{{g.nonce}}" data-onclick="togglePostEdit('{{p.id}}');remove_dialog()" class="btn btn-link text-muted ml-auto fl-r">Cancel</button>
<span id="upload-prog-edit-post" class="d-none mt-1 mr-2 fl-r">
<progress max="100"></progress>
<span></span>
</span>
</form>
<div id="post-edit-{{p.id}}" class="preview mb-3 mt-5"></div>
</div>