Spaces:
Runtime error
Runtime error
Commit ·
bf5c835
1
Parent(s): 01ffc0c
feat :ability to drag and drop
Browse files52 unmodified lines535455565758596016 unmodified lines77787980818283848586878889909192939452 unmodified lines<!-- File Input --><div id="file_input" style="display: none;"><label class="block font-mono text-sm text-gray-400 mb-2">Files (Multiple allowed)</label><input type="file" name="files" multipleclass="w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 font-mono focus:outline-none focus:border-blue-500 transition file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:bg-blue-500/20 file:text-blue-400 file:font-mono file:text-sm hover:file:bg-blue-500/30"></div><!-- Link Input -->16 unmodified lines</div><script>function toggleInputType() {const type = document.getElementById('note_type').value;const fileInput = document.getElementById('file_input');const linkInput = document.getElementById('link_input');if (type === 'file') {fileInput.style.display = 'block';linkInput.style.display = 'none';} else if (type === 'link') {fileInput.style.display = 'none';linkInput.style.display = 'block';}}</script>{% endblock %}52 unmodified lines53545556575859606162636416 unmodified lines8182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615752 unmodified lines<!-- File Input --><div id="file_input" style="display: none;"><label class="block font-mono text-sm text-gray-400 mb-2">Files (Multiple allowed)</label><div id="file_dropzone" class="w-full border-2 border-dashed border-white/20 bg-white/5 rounded-xl px-4 py-8 text-center transition cursor-pointer hover:border-blue-500/60 hover:bg-blue-500/5"><p class="font-mono text-sm text-gray-300">Drop files here or click to browse</p><p id="selected_file_count" class="font-mono text-xs text-gray-500 mt-2">No files selected</p><input id="files" type="file" name="files" multipleclass="hidden w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 font-mono focus:outline-none focus:border-blue-500 transition file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:bg-blue-500/20 file:text-blue-400 file:font-mono file:text-sm hover:file:bg-blue-500/30"></div></div><!-- Link Input -->16 unmodified lines</div><script>const noteTypeInput = document.getElementById('note_type');const fileInput = document.getElementById('file_input');const linkInput = document.getElementById('link_input');const dropzone = document.getElementById('file_dropzone');const filesField = document.getElementById('files');const fileCount = document.getElementById('selected_file_count');function updateSelectedFileText(files) {if (!files || files.length === 0) {fileCount.textContent = 'No files selected';return;}fileCount.textContent = files.length === 1? `Selected: ${files[0].name}`: `${files.length} files selected`;}function toggleInputType() {const type = noteTypeInput.value;if (type === 'file') {fileInput.style.display = 'block';linkInput.style.display = 'none';} else if (type === 'link') {fileInput.style.display = 'none';linkInput.style.display = 'block';} else {fileInput.style.display = 'none';linkInput.style.display = 'none';}}dropzone.addEventListener('click', () => filesField.click());filesField.addEventListener('change', () => {updateSelectedFileText(filesField.files);});['dragenter', 'dragover'].forEach((eventName) => {dropzone.addEventListener(eventName, (event) => {event.preventDefault();event.stopPropagation();dropzone.classList.add('border-blue-500', 'bg-blue-500/10');});});['dragleave', 'drop'].forEach((eventName) => {dropzone.addEventListener(eventName, (event) => {event.preventDefault();event.stopPropagation();dropzone.classList.remove('border-blue-500', 'bg-blue-500/10');});});dropzone.addEventListener('drop', (event) => {if (!event.dataTransfer || !event.dataTransfer.files.length) {return;}try {filesField.files = event.dataTransfer.files;} catch (error) {const dt = new DataTransfer();Array.from(event.dataTransfer.files).forEach((file) => dt.items.add(file));filesField.files = dt.files;}updateSelectedFileText(filesField.files);});toggleInputType();</script>{% endblock %}
app/templates/upload.html+70-7