added loading indicators on forms
This commit is contained in:
parent
b0bb02a9bd
commit
a9d2b49456
@ -18,6 +18,7 @@
|
|||||||
const { session } = stores();
|
const { session } = stores();
|
||||||
|
|
||||||
let editor, form, uploadForm;
|
let editor, form, uploadForm;
|
||||||
|
let loading = false;
|
||||||
let title = '', category = '';
|
let title = '', category = '';
|
||||||
export let categories;
|
export let categories;
|
||||||
|
|
||||||
@ -64,6 +65,8 @@
|
|||||||
let html = editor.getHtml(true);
|
let html = editor.getHtml(true);
|
||||||
let fd = new FormData(form);
|
let fd = new FormData(form);
|
||||||
fd.append('html', html);
|
fd.append('html', html);
|
||||||
|
loading = true;
|
||||||
|
try {
|
||||||
const res = await fetch(`/cms/article`, {
|
const res = await fetch(`/cms/article`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -77,6 +80,11 @@
|
|||||||
} else {
|
} else {
|
||||||
alert(`Error ${res.status}: ${json.message}`);
|
alert(`Error ${res.status}: ${json.message}`);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addCategory()
|
async function addCategory()
|
||||||
@ -164,4 +172,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<button on:click={submit}>Submit</button>
|
<button on:click={submit}>Submit</button>
|
||||||
|
{#if loading}
|
||||||
|
<progress>Uploading...</progress>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,11 +15,14 @@
|
|||||||
import { goto, stores } from '@sapper/app';
|
import { goto, stores } from '@sapper/app';
|
||||||
const { session } = stores();
|
const { session } = stores();
|
||||||
|
|
||||||
|
let loading = false;
|
||||||
let uploadForm;
|
let uploadForm;
|
||||||
|
|
||||||
async function upload()
|
async function upload()
|
||||||
{
|
{
|
||||||
let fd = new FormData(uploadForm);
|
let fd = new FormData(uploadForm);
|
||||||
|
loading = true;
|
||||||
|
try {
|
||||||
const res = await fetch(`/me/avatar`, {
|
const res = await fetch(`/me/avatar`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -33,6 +36,11 @@
|
|||||||
} else {
|
} else {
|
||||||
alert(`Error ${res.status}: ${json.message}`);
|
alert(`Error ${res.status}: ${json.message}`);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function del()
|
async function del()
|
||||||
@ -64,6 +72,9 @@
|
|||||||
Change your photo so you at least have a chance:
|
Change your photo so you at least have a chance:
|
||||||
<input type="file" name="upload">
|
<input type="file" name="upload">
|
||||||
<button type="submit">Upload</button>
|
<button type="submit">Upload</button>
|
||||||
|
{#if loading}
|
||||||
|
<progress>Uploading...</progress>
|
||||||
|
{/if}
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<p>Or better yet, erase your wretched face from this site entirely: <button on:click={del}>Reset Avatar</button></p>
|
<p>Or better yet, erase your wretched face from this site entirely: <button on:click={del}>Reset Avatar</button></p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user