mirror of
https://github.com/v1k45/pastepass.git
synced 2026-05-01 21:05:48 +00:00
Add form submission loading indicator
This commit is contained in:
@@ -2,7 +2,7 @@ package views
|
||||
|
||||
templ Index() {
|
||||
@base() {
|
||||
<form method="post">
|
||||
<form method="post" onsubmit="event.target.querySelector('button').setAttribute('aria-busy', 'true');">
|
||||
<textarea
|
||||
name="text"
|
||||
placeholder="Paste your secret here, select expiration time and click 'Paste'"
|
||||
|
||||
@@ -29,7 +29,7 @@ func Index() templ.Component {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\"><textarea name=\"text\" placeholder=\"Paste your secret here, select expiration time and click 'Paste'\" aria-label=\"Paste your secret here, select expiration time and click 'Paste'\" rows=\"10\" required autofocus></textarea><div style=\"display: flex; align-items: end; justify-content: space-between;\"><div style=\"min-width: 33.33%\"><label for=\"expiration\">Expires In</label> <select id=\"expiration\" name=\"expiration\" aria-label=\"Expires In\"><option value=\"1h\" selected>1 Hour</option> <option value=\"1d\">1 Day</option> <option value=\"1w\">1 Week</option> <option value=\"2w\">2 weeks</option> <option value=\"4w\">4 weeks</option></select></div><div style=\"min-width: 33.33%\"><button type=\"submit\">Paste</button></div></div></form>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" onsubmit=\"event.target.querySelector('button').setAttribute('aria-busy', 'true');\"><textarea name=\"text\" placeholder=\"Paste your secret here, select expiration time and click 'Paste'\" aria-label=\"Paste your secret here, select expiration time and click 'Paste'\" rows=\"10\" required autofocus></textarea><div style=\"display: flex; align-items: end; justify-content: space-between;\"><div style=\"min-width: 33.33%\"><label for=\"expiration\">Expires In</label> <select id=\"expiration\" name=\"expiration\" aria-label=\"Expires In\"><option value=\"1h\" selected>1 Hour</option> <option value=\"1d\">1 Day</option> <option value=\"1w\">1 Week</option> <option value=\"2w\">2 weeks</option> <option value=\"4w\">4 weeks</option></select></div><div style=\"min-width: 33.33%\"><button type=\"submit\">Paste</button></div></div></form>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@@ -11,9 +11,33 @@ templ View() {
|
||||
</small>
|
||||
</p>
|
||||
</hgroup>
|
||||
<form method="post">
|
||||
<form method="post" onsubmit="showPaste(event)">
|
||||
<button type="submit" style="width: auto;">Show Paste</button>
|
||||
</form>
|
||||
<script>
|
||||
// submit a post request and replace the current page with the response
|
||||
// this is to prevent user from resubmitting the form when they refresh the page
|
||||
function showPaste(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// show loading
|
||||
event.target.querySelector('button').setAttribute('aria-busy', 'true');
|
||||
|
||||
fetch(window.location.href, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'submit=true',
|
||||
}).then(function(response) {
|
||||
return response.text();
|
||||
}).then(function(body) {
|
||||
document.open();
|
||||
document.write(body);
|
||||
document.close();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func View() templ.Component {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div style=\"padding-bottom: 5rem;\"><hgroup><h3>View Paste</h3><p><small style=\"color: #8891A4;\">You can only view this paste once. Make sure to copy it before you close this page.</small></p></hgroup><form method=\"post\"><button type=\"submit\" style=\"width: auto;\">Show Paste</button></form></div>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div style=\"padding-bottom: 5rem;\"><hgroup><h3>View Paste</h3><p><small style=\"color: #8891A4;\">You can only view this paste once. Make sure to copy it before you close this page.</small></p></hgroup><form method=\"post\" onsubmit=\"showPaste(event)\"><button type=\"submit\" style=\"width: auto;\">Show Paste</button></form><script>\n // submit a post request and replace the current page with the response\n // this is to prevent user from resubmitting the form when they refresh the page\n function showPaste(event) {\n event.preventDefault();\n\n // show loading\n event.target.querySelector('button').setAttribute('aria-busy', 'true');\n\n fetch(window.location.href, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: 'submit=true',\n }).then(function(response) {\n return response.text();\n }).then(function(body) {\n document.open();\n document.write(body);\n document.close();\n });\n }\n </script></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user