1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Implement basic frontend notification system

This commit is contained in:
Lukas SP 2020-08-26 20:34:43 +02:00
parent 98cf1b396e
commit 76515c0108
7 changed files with 71 additions and 8 deletions

View File

@ -170,7 +170,25 @@ html, body {
font-size: 16px;
}
@media only screen and (max-width: 750px) {
.container #notifications {
position: fixed;
bottom: 0;
}
.container #notifications div {
width: 100vw;
padding: 10px 20px;
}
.container #notifications div.error {
background-color: #ff3d3d;
}
.container #notifications div.success {
background-color: #389b38;
}
@media only screen and (max-width: 650px) {
.navigation {
padding: 0 20px;
width: calc(100vw - 40px);

View File

@ -1,6 +1,6 @@
{
"version": 3,
"mappings": "AAAA,OAAO,CAAC,4EAAI;AAEZ,AAAA,IAAI,EAAE,IAAI,CAAC;EACP,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;EACV,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,4BAA4B;CAC5C;;AACD,AAAA,OAAO,CAAC;EACJ,OAAO,EAAE,IAAI;CAChB;;AAED,kBAAkB,CAAlB,OAAkB;EACd,EAAE;IACE,iBAAiB,EAAE,0BAA0B,CAAC,YAAY;IAClD,SAAS,EAAE,0BAA0B,CAAC,YAAY;;EAE9D,IAAI;IACA,iBAAiB,EAAE,0BAA0B,CAAC,cAAc;IACpD,SAAS,EAAE,0BAA0B,CAAC,cAAc;;;;AAGpE,UAAU,CAAV,OAAU;EACN,EAAE;IACE,iBAAiB,EAAE,0BAA0B,CAAC,YAAY;IAClD,SAAS,EAAE,0BAA0B,CAAC,YAAY;;EAE9D,IAAI;IACA,iBAAiB,EAAE,0BAA0B,CAAC,cAAc;IACpD,SAAS,EAAE,0BAA0B,CAAC,cAAc;;;;AAGpE,AAAA,QAAQ,CAAC;EACL,iBAAiB,EAAE,4BAA4B;EACvC,SAAS,EAAE,4BAA4B;EAC/C,4BAA4B,EAAE,OAAO;EAC7B,oBAAoB,EA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AAGI,WAHO,CAGL,OAAO,CAAC;IACN,OAAO,EAAE,SAAS;GAKrB;EATL,AAKQ,WALG,CAGL,OAAO,CAEH,GAAG,CAAC;IACF,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;GACf;EART,AAUI,WAVO,CAUL,KAAK,CAAC,QAAQ,CAAC;IACb,OAAO,EAAE,IAAI;GAChB",
"sources": [
"style.scss"
],

View File

@ -127,6 +127,20 @@ html, body {
font-size: 16px;
}
}
& #notifications {
position: fixed;
bottom: 0;
& div {
width: 100vw;
padding: 10px 20px;
&.error {
background-color: #ff3d3d;
}
&.success {
background-color: #389b38;
}
}
}
}
@media only screen and (max-width: 650px) {

View File

@ -2,6 +2,7 @@
import * as api from "./api.js";
import * as buttons from "./buttons.js";
import * as spinner from "./spinner.js";
import * as notifications from "./notifications.js";
// Set up the buttons
buttons.setupButtons();
@ -10,10 +11,13 @@ buttons.setupKeybinds();
// Load the API information
async function loadAPIInformation() {
const response = await api.getAPIInformation();
if (response.ok) {
const data = await response.json();
document.getElementById("version").innerText = data.version;
if (!response.ok) {
const data = await response.text();
notifications.error("Failed fetching the API information: <b>" + data + "</b>");
return;
}
const data = await response.json();
document.getElementById("version").innerText = data.version;
}
loadAPIInformation();

View File

@ -2,6 +2,7 @@
import * as api from "./api.js";
import * as autoload from "./autoload.js";
import * as spinner from "./spinner.js";
import * as notifications from "./notifications.js";
// setupKeybinds initializes the keybinds for the buttons
export function setupKeybinds() {
@ -56,7 +57,7 @@ export function setupButtons() {
// Create the paste
const response = await api.createPaste(input.value);
if (!response.ok) {
alert("Error:\n\n" + data);
notifications.error("Failed creating the paste: <b>" + data + "</b>");
return;
}
const data = await response.json();
@ -81,7 +82,7 @@ export function setupButtons() {
const response = await api.deletePaste(autoload.PASTE_ID, deletionToken);
const data = await response.text();
if (!response.ok) {
alert("Error:\n\n" + data);
notifications.error("Failed deleting the paste: <b>" + data + "</b>");
return;
}
@ -98,6 +99,7 @@ export function setupButtons() {
// Copy the code
await navigator.clipboard.writeText(document.getElementById("code").innerText);
notifications.success("Copied the code!");
});
});
}
@ -106,7 +108,7 @@ export function setupButtons() {
async function askClipboardPermissions() {
try {
const state = await navigator.permissions.query({
name: "clipbaord-write"
name: "clipboard-write"
});
return state === "granted";
} catch (error) {

View File

@ -0,0 +1,24 @@
// element holds the notification containers DOM element
const element = document.getElementById("notifications");
// error shows an error notifications
export function error(message) {
create("error", message, 3000);
}
// success shows a success notifications
export function success(message) {
create("success", message, 3000);
}
// create creates a new notification
function create(type, message, duration) {
const node = document.createElement("div");
node.classList.add(type);
node.innerHTML = message;
element.appendChild(node);
setTimeout(function() {
element.removeChild(node);
}, duration);
}

View File

@ -56,6 +56,7 @@
</div>
</div>
<div class="container">
<div id="notifications"></div>
<div id="linenos"><span>></span></div>
<div id="content">
<div id="code"></div>