forge
Explore
Log in

Don't you dare go Hollow

Empty files panel hints at upload, drag-and-drop lands

Browse files at this commit

2b5e0c8075896034d0231708dcd557c6ba28b719Ahmet Kaan GümüşParent: 9e827a0
  • feat
    • empty files panel hints at upload, drag-and-drop lands
Show full message
feat(ui): empty files panel hints at upload, drag-and-drop lands

An empty folder's files panel now says how to fill it: "Nothing here
yet — press + to upload, or drop files on this page." The sentence was
allowed to promise drop because the handler ships in the same commit:
dropping files anywhere on the drive page feeds them to the same
upload pipeline the + menu uses.
crates/in-web/src/drive.rsmodified+20 -0
@@ -375,6 +375,9 @@ async fn drive(cx: &Cx) -> Result {
375375 // none via the file-upload-input rule.
376376 <input id="drive-upload-input" class="file-upload-input" type="file" name="file" multiple="">
377377 </form>
378+ if listing.files.is_empty() {
379+ <p class="detail-quiet">(t(language, Key::EmptyFiles))</p>
380+ }
378381 <div class="file-list">
379382 for file in listing.files.iter() {
380383 <div class="dep-row">
@@ -561,6 +564,23 @@ async fn upload_script(cx: &Cx) -> Result {
561564 focusIt(); \
562565 document.addEventListener('in:wire', focusIt); \
563566 })(); \
567+ (function () { \
568+ if (window.__inDrop) { return; } \
569+ window.__inDrop = true; \
570+ function uploadForm() { return document.getElementById('upload-form'); } \
571+ document.addEventListener('dragover', function (e) { \
572+ if (uploadForm() && e.dataTransfer && e.dataTransfer.types && Array.prototype.indexOf.call(e.dataTransfer.types, 'Files') !== -1) { e.preventDefault(); } \
573+ }); \
574+ document.addEventListener('drop', function (e) { \
575+ var form = uploadForm(); \
576+ if (!form || !e.dataTransfer || !e.dataTransfer.files || !e.dataTransfer.files.length) { return; } \
577+ e.preventDefault(); \
578+ var input = form.querySelector('.file-upload-input'); \
579+ if (!input) { return; } \
580+ input.files = e.dataTransfer.files; \
581+ input.dispatchEvent(new Event('change', { bubbles: true })); \
582+ }); \
583+ })(); \
564584 })();";
565585 view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
566586 }
crates/in-web/src/i18n.rsmodified+3 -0
@@ -105,6 +105,7 @@ pub enum Key {
105105 MoveFolder,
106106 DeleteFolder,
107107 EmptyFolder,
108+ EmptyFiles,
108109 FoldersHeading,
109110 FilesHeading,
110111 NameColumn,
@@ -217,6 +218,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
217218 MoveFolder => "Move folder",
218219 DeleteFolder => "Delete folder",
219220 EmptyFolder => "This folder is empty.",
221+ EmptyFiles => "Nothing here yet — press + to upload, or drop files on this page.",
220222 FoldersHeading => "Folders",
221223 FilesHeading => "Files",
222224 NameColumn => "Name",
@@ -318,6 +320,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
318320 MoveFolder => "Klasörü taşı",
319321 DeleteFolder => "Klasörü sil",
320322 EmptyFolder => "Bu klasör boş.",
323+ EmptyFiles => "Henüz bir şey yok — + ile yükle ya da dosyaları bu sayfaya bırak.",
321324 FoldersHeading => "Klasörler",
322325 FilesHeading => "Dosyalar",
323326 NameColumn => "Ad",
crates/in-web/tests/http.rsmodified+15 -0
@@ -2703,3 +2703,18 @@ async fn drive_edit_row_renders_the_rename_form() {
27032703 assert!(body.contains("value=\"plans\""), "rename input is not pre-filled");
27042704 assert!(body.contains("__inEditFocus"), "no edit focus script");
27052705 }
2706+
2707+#[tokio::test]
2708+async fn an_empty_files_panel_says_how_to_fill_it() {
2709+ let app = TestApp::build().await;
2710+ let cookie = app.sign_in("sub-empty", "empty@in.test", "Empty").await;
2711+ let page = app.get("/drive", Some(&cookie)).await;
2712+ assert_eq!(page.status, StatusCode::OK, "{}", page.text());
2713+ assert!(
2714+ page.text().contains("Nothing here yet"),
2715+ "no empty-state hint: {}",
2716+ page.text()
2717+ );
2718+ // And the drop handler the hint promises is on the page.
2719+ assert!(page.text().contains("__inDrop"), "{}", page.text());
2720+}