Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

fixes

Murtaza Nasir7edd3c4b0946
diff --git a/templates/index.html b/templates/index.html
index 26bb3521..b60b3467 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -191,6 +191,53 @@
margin-bottom: 0.75rem;
color: #666;
}
+
+ /* Toast notification styles */
+ .toast-container {
+ position: fixed;
+ bottom: 20px;
+ right: 20px;
+ z-index: 1000;
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+ gap: 10px;
+ }
+
+ .toast {
+ padding: 10px 15px;
+ border-radius: 4px;
+ background-color: #4CAF50;
+ color: white;
+ font-size: 14px;
+ box-shadow: 0 2px 5px rgba(0,0,0,0.2);
+ opacity: 0;
+ transform: translateY(20px);
+ transition: all 0.3s ease;
+ display: flex;
+ align-items: center;
+ }
+
+ .toast.show {
+ opacity: 1;
+ transform: translateY(0);
+ }
+
+ .toast i {
+ margin-right: 8px;
+ }
+
+ /* Copy button animation */
+ @keyframes copy-success {
+ 0% { transform: scale(1); }
+ 50% { transform: scale(1.2); }
+ 100% { transform: scale(1); }
+ }
+
+ .copy-success {
+ animation: copy-success 0.3s ease;
+ color: #4CAF50 !important;
+ }
</style>
</head>
@@ -322,7 +369,7 @@
<div class="flex-grow">
<h4 class="font-semibold text-gray-700 mb-2 flex-shrink-0">Transcription</h4>
<div class="transcription-box p-4 bg-gray-50 rounded border border-gray-200 text-sm custom-scrollbar relative">
- <button @click="copyTranscription" class="copy-btn" title="Copy to clipboard">
+ <button @click="copyTranscription($event)" class="copy-btn" title="Copy to clipboard">
<i class="fas fa-copy mr-1"></i> Copy
</button>
<div v-if="selectedRecording.status === 'COMPLETED' || selectedRecording.status === 'SUMMARIZING'" class="copyable">
@@ -374,7 +421,7 @@
<div class="flex justify-between items-start">
<div class="flex-grow" v-if="message.role === 'user'">${ message.content }</div>
<div class="flex-grow" v-else v-html="message.html || message.content"></div>
- <button v-if="message.role === 'assistant'" @click="copyMessage(message.content)" class="ml-2 text-gray-400 hover:text-gray-600" title="Copy response">
+ <button v-if="message.role === 'assistant'" @click="copyMessage(message.content, $event)" class="ml-2 text-gray-400 hover:text-gray-600" title="Copy response">
<i class="fas fa-copy text-xs"></i>
</button>
</div>
@@ -551,7 +598,12 @@
</div>
</div>
- </div> <script>
+ </div>
+
+ <!-- Toast container for notifications -->
+ <div class="toast-container" id="toastContainer"></div>
+
+ <script>
const { createApp, ref, reactive, computed, onMounted, watch, nextTick } = Vue
createApp({
@@ -1201,31 +1253,127 @@
}
};
- const copyMessage = (text) => {
- navigator.clipboard.writeText(text)
- .then(() => {
- setGlobalError('Response copied to clipboard!', 2000);
- })
- .catch(err => {
- console.error('Copy failed:', err);
- setGlobalError('Failed to copy: ' + err.message);
- });
+ // Toast notification system
+ const showToast = (message, icon = 'fa-check-circle', duration = 2000) => {
+ const toastContainer = document.getElementById('toastContainer');
+
+ // Create toast element
+ const toast = document.createElement('div');
+ toast.className = 'toast';
+ toast.innerHTML = `<i class="fas ${icon}"></i> ${message}`;
+
+ // Add to container
+ toastContainer.appendChild(toast);
+
+ // Trigger animation
+ setTimeout(() => {
+ toast.classList.add('show');
+ }, 10);
+
+ // Remove after duration
+ setTimeout(() => {
+ toast.classList.remove('show');
+ setTimeout(() => {
+ toastContainer.removeChild(toast);
+ }, 300);
+ }, duration);
+ };
+
+ // Add animation to copy button
+ const animateCopyButton = (button) => {
+ button.classList.add('copy-success');
+
+ // Store original content
+ const originalContent = button.innerHTML;
+ button.innerHTML = '<i class="fas fa-check"></i>';
+
+ setTimeout(() => {
+ button.classList.remove('copy-success');
+ button.innerHTML = originalContent;
+ }, 1500);
};
- const copyTranscription = () => {
+ const copyMessage = (text, event) => {
+ // Get the button that was clicked
+ const button = event.currentTarget;
+
+ if (navigator.clipboard && window.isSecureContext) {
+ // Use clipboard API if available (secure context)
+ navigator.clipboard.writeText(text)
+ .then(() => {
+ showToast('Copied to clipboard!');
+ animateCopyButton(button);
+ })
+ .catch(err => {
+ console.error('Copy failed:', err);
+ showToast('Failed to copy: ' + err.message, 'fa-exclamation-circle');
+ fallbackCopyTextToClipboard(text, button);
+ });
+ } else {
+ // Fallback for non-secure contexts
+ fallbackCopyTextToClipboard(text, button);
+ }
+ };
+
+ // Fallback method using document.execCommand
+ const fallbackCopyTextToClipboard = (text, button = null) => {
+ try {
+ const textArea = document.createElement("textarea");
+ textArea.value = text;
+
+ // Make the textarea out of viewport
+ textArea.style.position = "fixed";
+ textArea.style.left = "-999999px";
+ textArea.style.top = "-999999px";
+ document.body.appendChild(textArea);
+
+ // Select and copy
+ textArea.focus();
+ textArea.select();
+ const successful = document.execCommand('copy');
+
+ // Clean up
+ document.body.removeChild(textArea);
+
+ if (successful) {
+ showToast('Copied to clipboard!');
+ if (button) animateCopyButton(button);
+ } else {
+ showToast('Copy failed. Your browser may not support this feature.', 'fa-exclamation-circle');
+ }
+ } catch (err) {
+ console.error('Fallback copy failed:', err);
+ showToast('Unable to copy: ' + err.message, 'fa-exclamation-circle');
+ }
+ };
+
+ const copyTranscription = (event) => {
if (!selectedRecording.value || !selectedRecording.value.transcription) {
- setGlobalError('No transcription available to copy.');
+ showToast('No transcription available to copy.', 'fa-exclamation-circle');
return;
}
- navigator.clipboard.writeText(selectedRecording.value.transcription)
- .then(() => {
- setGlobalError('Transcription copied to clipboard!', 2000);
- })
- .catch(err => {
- console.error('Copy failed:', err);
- setGlobalError('Failed to copy: ' + err.message);
- });
+ // Get the button that was clicked
+ const button = event.currentTarget;
+
+ // Show visual feedback on button
+ animateCopyButton(button);
+
+ if (navigator.clipboard && window.isSecureContext) {
+ // Use clipboard API if available (secure context)
+ navigator.clipboard.writeText(selectedRecording.value.transcription)
+ .then(() => {
+ showToast('Transcription copied to clipboard!');
+ })
+ .catch(err => {
+ console.error('Copy failed:', err);
+ showToast('Failed to copy: ' + err.message, 'fa-exclamation-circle');
+ fallbackCopyTextToClipboard(selectedRecording.value.transcription);
+ });
+ } else {
+ // Fallback for non-secure contexts
+ fallbackCopyTextToClipboard(selectedRecording.value.transcription);
+ }
};
// Clear chat messages when recording changes