Skip to content

Commit

Permalink
Better notifications
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kastl <daniel@georepublic.de>
  • Loading branch information
dkastl committed Oct 3, 2024
1 parent cc1cad3 commit 80b71a9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
8 changes: 5 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ <h1>Meshtastic QR Code Generator</h1>

<form id="meshtasticForm">
<fieldset>
<legend>Generate Configuration</legend>
<legend>Share this with others</legend>

<div class="form-group">
<button type="button" id="generateConfig">Generate Configuration (QR Code)</button>
<canvas id="qrcode"></canvas>
</div>

<div class="form-group">
Expand All @@ -25,7 +25,7 @@ <h1>Meshtastic QR Code Generator</h1>
</div>

<div class="form-group">
<canvas id="qrcode"></canvas>
<button type="button" id="generateConfig">Generate Configuration (QR Code)</button>
</div>
</fieldset>

Expand Down Expand Up @@ -136,6 +136,8 @@ <h1>Meshtastic QR Code Generator</h1>
</fieldset>
</form>

<div id="copyNotification" class="hidden">URL copied to clipboard!</div>

<script type="module" src="./src/main.ts"></script>
</body>
</html>
32 changes: 24 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,29 @@ async function generateConfig(): Promise<void> {
function copyUrlToClipboard(): void {
const urlField = document.getElementById('generatedUrl') as HTMLInputElement;

// Use the Clipboard API to copy the URL
navigator.clipboard.writeText(urlField.value)
.then(() => {
alert('URL copied to clipboard!');
})
.catch(err => {
console.error('Failed to copy text: ', err);
alert('Failed to copy URL');
});
.then(() => {
showCopyNotification();
})
.catch(err => {
console.error('Failed to copy text: ', err);
alert('Failed to copy URL');
});
}

/**
* Show the "URL copied" notification with animation
*/
function showCopyNotification(): void {
const notification = document.getElementById('copyNotification');

if (notification) {
notification.classList.add('show');

// Hide the notification after 2 seconds
setTimeout(() => {
notification.classList.remove('show');
}, 2000);
}
}

25 changes: 25 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
body {
font-family: Arial, sans-serif;
}

fieldset {
margin-bottom: 20px;
padding: 10px;
Expand Down Expand Up @@ -32,3 +36,24 @@ button#generateConfig {
border: #4CAF50 1px solid;
font-size: large;
}

#copyNotification {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border-radius: 5px;
font-size: 14px;
opacity: 0;
visibility: hidden;
transition: opacity 0.5s ease, visibility 0.5s ease;
z-index: 1000;
}

#copyNotification.show {
visibility: visible;
opacity: 1;
}

0 comments on commit 80b71a9

Please sign in to comment.