Spaces:
Running
Running
keep delving you got this. as well as the simple uploads paperclip functioning (say 50 mb cap) - Follow Up Deployment
Browse files- index.html +140 -5
index.html
CHANGED
@@ -225,18 +225,38 @@
|
|
225 |
</div>
|
226 |
|
227 |
<!-- Message Input -->
|
228 |
-
<div class="bg-gray-800 border-t border-gray-700 p-4">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
<div class="flex items-center space-x-2">
|
230 |
-
<
|
231 |
-
<
|
232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
<div class="flex-1 relative">
|
234 |
<input id="messageInput" type="text" placeholder="Message #general" class="w-full bg-gray-700 rounded-full px-4 py-2 focus:outline-none focus:ring-1 focus:ring-purple-500">
|
235 |
<div class="absolute right-2 top-1/2 transform -translate-y-1/2 flex space-x-1">
|
236 |
<button class="p-1 text-gray-400 hover:text-gray-200">
|
237 |
<i class="fas fa-smile"></i>
|
238 |
</button>
|
239 |
-
<button class="p-1 text-gray-400 hover:text-gray-200">
|
240 |
<i class="fas fa-paperclip"></i>
|
241 |
</button>
|
242 |
</div>
|
@@ -626,6 +646,121 @@
|
|
626 |
}
|
627 |
}
|
628 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
629 |
// Mobile sidebar toggle
|
630 |
mobileSidebarToggle.addEventListener('click', () => {
|
631 |
sidebar.classList.toggle('hidden');
|
|
|
225 |
</div>
|
226 |
|
227 |
<!-- Message Input -->
|
228 |
+
<div class="bg-gray-800 border-t border-gray-700 p-4 relative">
|
229 |
+
<div id="fileStatus" class="absolute -top-8 left-0 right-0 px-4 hidden">
|
230 |
+
<div class="bg-gray-700 rounded-t-lg px-3 py-1 text-sm flex items-center justify-between">
|
231 |
+
<span id="fileName" class="truncate text-purple-300"></span>
|
232 |
+
<div class="flex items-center space-x-2">
|
233 |
+
<span id="fileSize" class="text-xs text-gray-400">0/50MB</span>
|
234 |
+
<button id="cancelUpload" class="text-gray-400 hover:text-red-400">
|
235 |
+
<i class="fas fa-times"></i>
|
236 |
+
</button>
|
237 |
+
</div>
|
238 |
+
</div>
|
239 |
+
<div id="progressBar" class="h-1 bg-gray-600 rounded-b">
|
240 |
+
<div id="progress" class="h-full bg-purple-500 rounded-b" style="width: 0%"></div>
|
241 |
+
</div>
|
242 |
+
</div>
|
243 |
<div class="flex items-center space-x-2">
|
244 |
+
<div class="relative">
|
245 |
+
<input type="file" id="fileUpload" class="hidden" accept="image/*, video/*, audio/*, .pdf, .doc, .docx, .txt">
|
246 |
+
<button id="uploadButton" class="p-2 rounded-full hover:bg-gray-700">
|
247 |
+
<i class="fas fa-plus text-gray-400"></i>
|
248 |
+
</button>
|
249 |
+
<div id="uploadProgress" class="absolute -top-2 -right-2 w-4 h-4 rounded-full bg-purple-500 hidden flex items-center justify-center">
|
250 |
+
<span class="text-white text-xs">100</span>
|
251 |
+
</div>
|
252 |
+
</div>
|
253 |
<div class="flex-1 relative">
|
254 |
<input id="messageInput" type="text" placeholder="Message #general" class="w-full bg-gray-700 rounded-full px-4 py-2 focus:outline-none focus:ring-1 focus:ring-purple-500">
|
255 |
<div class="absolute right-2 top-1/2 transform -translate-y-1/2 flex space-x-1">
|
256 |
<button class="p-1 text-gray-400 hover:text-gray-200">
|
257 |
<i class="fas fa-smile"></i>
|
258 |
</button>
|
259 |
+
<button id="attachmentButton" class="p-1 text-gray-400 hover:text-gray-200">
|
260 |
<i class="fas fa-paperclip"></i>
|
261 |
</button>
|
262 |
</div>
|
|
|
646 |
}
|
647 |
}
|
648 |
|
649 |
+
// File upload functionality
|
650 |
+
const fileUpload = document.getElementById('fileUpload');
|
651 |
+
const attachmentButton = document.getElementById('attachmentButton');
|
652 |
+
const uploadButton = document.getElementById('uploadButton');
|
653 |
+
const fileStatus = document.getElementById('fileStatus');
|
654 |
+
const fileName = document.getElementById('fileName');
|
655 |
+
const fileSize = document.getElementById('fileSize');
|
656 |
+
const progress = document.getElementById('progress');
|
657 |
+
const progressBar = document.getElementById('progressBar');
|
658 |
+
const uploadProgress = document.getElementById('uploadProgress');
|
659 |
+
const cancelUpload = document.getElementById('cancelUpload');
|
660 |
+
let currentFile = null;
|
661 |
+
|
662 |
+
// Trigger file selection
|
663 |
+
uploadButton.addEventListener('click', () => fileUpload.click());
|
664 |
+
attachmentButton.addEventListener('click', () => fileUpload.click());
|
665 |
+
|
666 |
+
fileUpload.addEventListener('change', (e) => {
|
667 |
+
const file = e.target.files[0];
|
668 |
+
if (!file) return;
|
669 |
+
|
670 |
+
// Check file size (50MB limit)
|
671 |
+
if (file.size > 50 * 1024 * 1024) {
|
672 |
+
alert('File size exceeds 50MB limit');
|
673 |
+
return;
|
674 |
+
}
|
675 |
+
|
676 |
+
currentFile = file;
|
677 |
+
|
678 |
+
// Update UI
|
679 |
+
fileName.textContent = file.name;
|
680 |
+
fileSize.textContent = formatFileSize(file.size) + '/50MB';
|
681 |
+
fileStatus.classList.remove('hidden');
|
682 |
+
|
683 |
+
// Simulate upload progress
|
684 |
+
let progressValue = 0;
|
685 |
+
const uploadInterval = setInterval(() => {
|
686 |
+
progressValue += Math.random() * 10;
|
687 |
+
if (progressValue >= 100) {
|
688 |
+
progressValue = 100;
|
689 |
+
clearInterval(uploadInterval);
|
690 |
+
uploadProgress.classList.add('hidden');
|
691 |
+
|
692 |
+
// Send file message after upload completes
|
693 |
+
setTimeout(() => {
|
694 |
+
addFileMessage(file);
|
695 |
+
fileStatus.classList.add('hidden');
|
696 |
+
}, 500);
|
697 |
+
}
|
698 |
+
uploadProgress.classList.remove('hidden');
|
699 |
+
uploadProgress.querySelector('span').textContent = Math.round(progressValue);
|
700 |
+
progress.style.width = `${progressValue}%`;
|
701 |
+
}, 300);
|
702 |
+
});
|
703 |
+
|
704 |
+
cancelUpload.addEventListener('click', () => {
|
705 |
+
fileStatus.classList.add('hidden');
|
706 |
+
fileUpload.value = '';
|
707 |
+
currentFile = null;
|
708 |
+
});
|
709 |
+
|
710 |
+
function formatFileSize(bytes) {
|
711 |
+
if (bytes < 1024) return bytes + 'B';
|
712 |
+
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + 'KB';
|
713 |
+
else return (bytes / (1024 * 1024)).toFixed(1) + 'MB';
|
714 |
+
}
|
715 |
+
|
716 |
+
function addFileMessage(file) {
|
717 |
+
const now = new Date();
|
718 |
+
const timeString = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
719 |
+
const currentUser = localStorage.getItem('currentUser') || 'You';
|
720 |
+
|
721 |
+
const fileMessage = document.createElement('div');
|
722 |
+
fileMessage.className = 'message-enter flex space-x-3';
|
723 |
+
fileMessage.innerHTML = `
|
724 |
+
<div class="flex-shrink-0">
|
725 |
+
<div class="w-8 h-8 rounded-full bg-gradient-to-br from-red-500 to-orange-400 flex items-center justify-center text-white font-bold">
|
726 |
+
${currentUser.charAt(0).toUpperCase()}
|
727 |
+
</div>
|
728 |
+
</div>
|
729 |
+
<div>
|
730 |
+
<div class="flex items-baseline space-x-2">
|
731 |
+
<span class="font-semibold text-red-300">${currentUser}</span>
|
732 |
+
<span class="text-xs text-gray-400">${timeString}</span>
|
733 |
+
</div>
|
734 |
+
<div class="mt-1 max-w-xs bg-gray-700 rounded-lg p-3">
|
735 |
+
<div class="flex items-center space-x-2">
|
736 |
+
<i class="fas ${getFileIcon(file)} text-purple-400"></i>
|
737 |
+
<div class="flex-1 min-w-0">
|
738 |
+
<p class="text-sm font-medium truncate">${file.name}</p>
|
739 |
+
<p class="text-xs text-gray-400">${formatFileSize(file.size)}</p>
|
740 |
+
</div>
|
741 |
+
</div>
|
742 |
+
<a href="#" class="mt-2 inline-block text-sm text-purple-400 hover:text-purple-300">
|
743 |
+
<i class="fas fa-download mr-1"></i> Download
|
744 |
+
</a>
|
745 |
+
</div>
|
746 |
+
</div>
|
747 |
+
`;
|
748 |
+
|
749 |
+
messagesContainer.appendChild(fileMessage);
|
750 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
751 |
+
}
|
752 |
+
|
753 |
+
function getFileIcon(file) {
|
754 |
+
const type = file.type.split('/')[0];
|
755 |
+
if (type === 'image') return 'fa-image';
|
756 |
+
if (type === 'video') return 'fa-video';
|
757 |
+
if (type === 'audio') return 'fa-music';
|
758 |
+
if (file.name.match(/\.(pdf)$/i)) return 'fa-file-pdf';
|
759 |
+
if (file.name.match(/\.(docx?)$/i)) return 'fa-file-word';
|
760 |
+
if (file.name.match(/\.(xlsx?)$/i)) return 'fa-file-excel';
|
761 |
+
return 'fa-file';
|
762 |
+
}
|
763 |
+
|
764 |
// Mobile sidebar toggle
|
765 |
mobileSidebarToggle.addEventListener('click', () => {
|
766 |
sidebar.classList.toggle('hidden');
|