diff --git a/crates/in-web/src/drive.rs b/crates/in-web/src/drive.rs index 01a4028..39146bf 100644 --- a/crates/in-web/src/drive.rs +++ b/crates/in-web/src/drive.rs @@ -61,7 +61,7 @@ struct DriveQuery { q: Option, edit: Option, sort: Option, - dir: Option, + share: Option, kind: Option, } @@ -222,25 +222,30 @@ impl KindFilter { } } -fn parse_sort(raw: Option<&str>) -> Option { - match raw.unwrap_or("") { - "name" => Some(SortKey::Name), - "uploaded" => Some(SortKey::Uploaded), - "size" => Some(SortKey::Size), - "downloads" => Some(SortKey::Downloads), - _ => None, - } -} - -fn parse_dir(raw: Option<&str>, key: Option) -> SortDir { - match raw.unwrap_or("") { +/// The sort off the query: `key:direction` in one value ("size:desc"), the +/// way the dropdown's options name it. A bare key reads with its natural +/// direction (names ascend, measures descend); anything else is no sort. +fn parse_sort(raw: Option<&str>) -> Option<(SortKey, SortDir)> { + let (key, dir) = raw + .unwrap_or("") + .split_once(':') + .unwrap_or((raw.unwrap_or(""), "")); + let key = match key { + "name" => SortKey::Name, + "uploaded" => SortKey::Uploaded, + "size" => SortKey::Size, + "downloads" => SortKey::Downloads, + _ => return None, + }; + let dir = match dir { "asc" => SortDir::Asc, "desc" => SortDir::Desc, _ => match key { - Some(SortKey::Name) | None => SortDir::Asc, + SortKey::Name => SortDir::Asc, _ => SortDir::Desc, }, - } + }; + Some((key, dir)) } fn parse_kind(raw: Option<&str>) -> KindFilter { @@ -318,13 +323,9 @@ async fn drive(cx: &Cx) -> Result { // standing order (folders-then-files as listed), ascending names, and // the unfiltered kind — a hand-edited query re-orders nothing, it // never refuses. - let sort_key = params + let sorting = params .as_ref() .and_then(|query| parse_sort(query.sort.as_deref())); - let sort_dir = parse_dir( - params.as_ref().and_then(|query| query.dir.as_deref()), - sort_key, - ); let kind = params .as_ref() .map(|query| parse_kind(query.kind.as_deref())) @@ -345,9 +346,9 @@ async fn drive(cx: &Cx) -> Result { }; // Sort and filter in the page layer, after the fetch — no store API // change. Each group keeps its own order; folders-then-files stands. - if let Some(key) = sort_key { - sort_folders(&mut listing.folders, key, sort_dir); - sort_files(&mut listing.files, key, sort_dir); + if let Some((key, dir)) = sorting { + sort_folders(&mut listing.folders, key, dir); + sort_files(&mut listing.files, key, dir); } match kind { KindFilter::All => {} @@ -355,9 +356,9 @@ async fn drive(cx: &Cx) -> Result { KindFilter::Files => listing.folders.clear(), } if let Some(found) = hits.as_mut() { - if let Some(key) = sort_key { - sort_folders(&mut found.folders, key, sort_dir); - sort_files(&mut found.files, key, sort_dir); + if let Some((key, dir)) = sorting { + sort_folders(&mut found.folders, key, dir); + sort_files(&mut found.files, key, dir); } match kind { KindFilter::All => {} @@ -392,15 +393,8 @@ async fn drive(cx: &Cx) -> Result { if !current_id.is_empty() { here_bits.push(format!("folder={current_id}")); } - if let Some(key) = sort_key { - here_bits.push(format!("sort={}", key.as_str())); - } - if params - .as_ref() - .and_then(|query| query.dir.clone()) - .is_some_and(|dir| dir == "asc" || dir == "desc") - { - here_bits.push(format!("dir={}", sort_dir.as_str())); + if let Some((key, dir)) = sorting { + here_bits.push(format!("sort={}:{}", key.as_str(), dir.as_str())); } if kind != KindFilter::All { here_bits.push(format!("kind={}", kind.as_str())); @@ -412,14 +406,27 @@ async fn drive(cx: &Cx) -> Result { }; // The edit links extend `here` with the matching separator. let edit_sep = if here.contains('?') { "&" } else { "?" }; - // The direction the toggle offers: the opposite of what is showing. - let dir_flip = match sort_dir { - SortDir::Asc => "desc", - SortDir::Desc => "asc", + // The value the sort dropdown shows as selected: the parsed pair, or the + // visual default when the standing order is on. + let sort_value = sorting + .map(|(key, dir)| format!("{}:{}", key.as_str(), dir.as_str())) + .unwrap_or_else(|| "name:asc".to_string()); + // The share dialog: `?share=kind:id` renders the entry's modal over the + // page (its forms come back here through Referer, so it stays open); the + // close link is this view without the pair. A pair that names nothing + // owned and live opens nothing. + let share_pair = params.as_ref().and_then(|query| query.share.as_deref()); + let share_dialog = match share_pair.and_then(|pair| pair.split_once(':')) { + Some((kind, id)) => { + crate::share::share_modal(cx, kind, id, &here, created.clone(), &origin).await? + } + None => None, }; - let dir_glyph = match sort_dir { - SortDir::Asc => "↑", - SortDir::Desc => "↓", + // The copy-once banner belongs to the modal when it is open. + let created_panel = if share_pair.is_some() { + None + } else { + created.clone() }; view! { @@ -451,43 +458,33 @@ async fn drive(cx: &Cx) -> Result { aria-label=(t(language, Key::SearchPlaceholder)) > - if sort_key.is_some() { - - } - - if kind != KindFilter::All { - - } + if sorting.is_some() { + + } + if kind != KindFilter::All { + + }
(t(language, Key::Sort)) - - - - - if kind != KindFilter::All { - - } - -
-
- - - if sort_key.is_some() { - - } - - if kind != KindFilter::All { - - } - -
+ + + + if kind != KindFilter::All { + + } + +
(t(language, Key::Kind)) - if sort_key.is_some() { - + if sorting.is_some() { + } -
@@ -517,7 +513,7 @@ async fn drive(cx: &Cx) -> Result { if let Some(refusal) = refusal {

(refusal.message_in(language))

} - if let Some(token) = created { + if let Some(token) = created_panel {

(t(language, Key::LinkCreated))

@@ -596,7 +592,7 @@ async fn drive(cx: &Cx) -> Result { (t(language, Key::Rename)) (t(language, Key::Share)) + href=(format!("{here}{edit_sep}share=folder:{}", folder.id))>(t(language, Key::Share))
@@ -647,7 +643,7 @@ async fn drive(cx: &Cx) -> Result { (t(language, Key::Rename)) (t(language, Key::Share)) + href=(format!("{here}{edit_sep}share=file:{}", file.id))>(t(language, Key::Share))
@@ -673,6 +669,9 @@ async fn drive(cx: &Cx) -> Result {
} + if let Some(dialog) = share_dialog { + (dialog) + } (crate::dropdown::dropdown_script(cx).await?) (upload_script(cx).await?) (options_menu_script(cx).await?) @@ -1107,6 +1106,11 @@ async fn options_menu_script(cx: &Cx) -> Result { var above = anchor.top - roomTop - 4; \ var below = roomBottom - anchor.bottom - 4; \ if (above >= down.height || above > below) { details.classList.add('menu-up'); } \ + /* Never taller than the room on the chosen side: without \ + the cap a drop-up reaches over the topbar. */ \ + var up = details.classList.contains('menu-up'); \ + panel.style.maxHeight = Math.max(96, (up ? above : below) - 4) + 'px'; \ + panel.style.overflowY = 'auto'; \ var r = panel.getBoundingClientRect(); \ if (r.top < roomTop && r.bottom > roomBottom) { panel.scrollIntoView({ block: 'nearest' }); } \ }); \ @@ -1128,9 +1132,6 @@ struct CreateFolderForm { /// `POST /api/folder/create`: one folder under the open one, or the root. /// -/// A form with no name is the + menu's quick create: a generic unique name -/// (`New folder`, `New folder 2`, …) and a 303 straight into that row's -/// rename form. A typed name keeps the old answer — back to the page. #[route(POST "/api/folder/create")] async fn create_folder(cx: &Cx, Form(input): Form) -> Redirect { let user = match require_user(cx).await { diff --git a/crates/in-web/src/dropdown.rs b/crates/in-web/src/dropdown.rs index 3bbfb0f..97c71af 100644 --- a/crates/in-web/src/dropdown.rs +++ b/crates/in-web/src/dropdown.rs @@ -197,7 +197,7 @@ pub async fn dropdown_script(cx: &Cx) -> Result { select.__ddPanel = panel;\ var allOpts = opts(select);\ var search = null;\ - if (allOpts.length > 7 || select.hasAttribute('data-search')) {\ + if ((allOpts.length > 7 && !select.hasAttribute('data-nosearch')) || select.hasAttribute('data-search')) {\ search = document.createElement('input');\ search.type = 'text';\ search.className = 'dd-search';\ diff --git a/crates/in-web/src/i18n.rs b/crates/in-web/src/i18n.rs index 83be804..416a87b 100644 --- a/crates/in-web/src/i18n.rs +++ b/crates/in-web/src/i18n.rs @@ -191,24 +191,34 @@ pub enum Key { DropFilesToUpload, Dismiss, Sort, - SortName, - SortUploaded, - SortSize, - SortDownloads, + SortNameAZ, + SortNameZA, + SortNewest, + SortOldest, + SortLargest, + SortSmallest, + SortMostDownloads, + SortLeastDownloads, + SortOwnerAZ, + SortOwnerZA, Kind, KindAll, KindFolders, KindFiles, - SortDeleted, - SortOwner, + DeletedLabel, // Settings limits redesign (SettingsBuild owns this block). - UploadLimitHelp, - EveryoneSubtitle, UploadLimitSection, // Per-entry share page (ShareBuild owns this block). CreateLink, ExpiresInDays, NoShares, + Copied, + WhoHasAccess, + YouSuffix, + OwnerRole, + PublicLinkLabel, + AnyoneWithLink, + NotActive, } pub fn t(lang: Lang, key: Key) -> &'static str { @@ -247,7 +257,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str { RenameFolder => "Rename folder", MoveFolder => "Move folder", DeleteFolder => "Delete folder", - EmptyFolder => "This folder is empty. Press + to create or upload, or drop files on this page.", + EmptyFolder => { + "This folder is empty. Press + to create or upload, or drop files on this page." + } FoldersHeading => "Folders", FilesHeading => "Files", NameColumn => "Name", @@ -324,18 +336,28 @@ pub fn t(lang: Lang, key: Key) -> &'static str { DropFilesToUpload => "Drop files to upload", Dismiss => "Dismiss", Sort => "Sort", - SortName => "Name", - SortUploaded => "Uploaded", - SortSize => "Size", - SortDownloads => "Downloads", + SortNameAZ => "Name A–Z", + SortNameZA => "Name Z–A", + SortNewest => "Newest first", + SortOldest => "Oldest first", + SortLargest => "Largest first", + SortSmallest => "Smallest first", + SortMostDownloads => "Most downloaded", + SortLeastDownloads => "Least downloaded", + SortOwnerAZ => "Owner A–Z", + SortOwnerZA => "Owner Z–A", Kind => "Kind", KindAll => "All", + Copied => "Copied", + WhoHasAccess => "Who has access", + YouSuffix => "(you)", + OwnerRole => "owner", + PublicLinkLabel => "Public link", + AnyoneWithLink => "Anyone on the Internet with the link", + NotActive => "Not active", KindFolders => "Folders", + DeletedLabel => "Deleted", KindFiles => "Files", - SortDeleted => "Deleted", - SortOwner => "Owner", - UploadLimitHelp => "The most one uploaded file may be.", - EveryoneSubtitle => "Per-person storage quotas below; the single-file upload limit follows.", UploadLimitSection => "Upload limit — applies to everyone.", CreateLink => "Create link", ExpiresInDays => "Expires in days", @@ -374,7 +396,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str { RenameFolder => "Klasörü yeniden adlandır", MoveFolder => "Klasörü taşı", DeleteFolder => "Klasörü sil", - EmptyFolder => "Bu klasör boş. + ile oluştur ya da yükle, ya da dosyaları bu sayfaya bırak.", + EmptyFolder => { + "Bu klasör boş. + ile oluştur ya da yükle, ya da dosyaları bu sayfaya bırak." + } FoldersHeading => "Klasörler", FilesHeading => "Dosyalar", NameColumn => "Ad", @@ -451,20 +475,30 @@ pub fn t(lang: Lang, key: Key) -> &'static str { DropFilesToUpload => "Yüklemek için dosyaları bırakın", Dismiss => "Kapat", Sort => "Sırala", - SortName => "Ad", - SortUploaded => "Yüklenme", - SortSize => "Boyut", - SortDownloads => "İndirme", + SortNameAZ => "Ad A–Z", + SortNameZA => "Ad Z–A", + SortNewest => "Önce en yeni", + SortOldest => "Önce en eski", + SortLargest => "Önce en büyük", + SortSmallest => "Önce en küçük", + SortMostDownloads => "En çok indirilen", + SortLeastDownloads => "En az indirilen", + SortOwnerAZ => "Sahip A–Z", + SortOwnerZA => "Sahip Z–A", Kind => "Tür", KindAll => "Tümü", KindFolders => "Klasörler", KindFiles => "Dosyalar", - SortDeleted => "Silindi", - SortOwner => "Sahibi", - UploadLimitHelp => "Tek bir dosyanın alabileceği en büyük boyut.", - EveryoneSubtitle => "Aşağıda kişi başına depolama kotaları; ardından herkes için geçerli tek dosyalık yükleme sınırı.", + DeletedLabel => "Silindi", UploadLimitSection => "Yükleme sınırı — herkes için geçerlidir.", CreateLink => "Bağlantı oluştur", + Copied => "Kopyalandı", + WhoHasAccess => "Erişimi olanlar", + YouSuffix => "(sen)", + OwnerRole => "sahip", + PublicLinkLabel => "Herkese açık bağlantı", + AnyoneWithLink => "Bağlantıya sahip olan herkes", + NotActive => "Etkin değil", ExpiresInDays => "Bitiş (gün)", NoShares => "Henüz kimseyle paylaşılmadı.", }, diff --git a/crates/in-web/src/layout.rs b/crates/in-web/src/layout.rs index a88270c..b117bcb 100644 --- a/crates/in-web/src/layout.rs +++ b/crates/in-web/src/layout.rs @@ -535,7 +535,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { scrims.forEach(function (el) { el.remove(); }); \ sweepPanels(); \ var u = new URL(window.location.href); \ - ['task', 'file', 'confirm', 'new', 'refusal', 'on'].forEach(function (k) { u.searchParams.delete(k); }); \ + ['task', 'file', 'confirm', 'new', 'refusal', 'on', 'share', 'created'].forEach(function (k) { u.searchParams.delete(k); }); \ var q = u.searchParams.toString(); \ history.replaceState(null, '', u.pathname + (q ? '?' + q : '')); \ return true; \ diff --git a/crates/in-web/src/settings.rs b/crates/in-web/src/settings.rs index b4f771a..99bf3f7 100644 --- a/crates/in-web/src/settings.rs +++ b/crates/in-web/src/settings.rs @@ -128,7 +128,11 @@ async fn set_quota(cx: &Cx, Form(input): Form) -> Redirect { return redirect_back(cx, "quota", Some(refusal)); } match unit_bytes(&input.quota, &input.quota_unit) { - Some(quota_bytes) => match app(cx).store.set_user_quota(&input.user_id, quota_bytes).await { + Some(quota_bytes) => match app(cx) + .store + .set_user_quota(&input.user_id, quota_bytes) + .await + { Ok(()) => redirect_back(cx, "quota", None), Err(error) => redirect_back(cx, "quota", Some(refusal_of(error))), }, @@ -158,10 +162,7 @@ async fn set_upload_limit(cx: &Cx, Form(input): Form) -> Redire match unit_bytes(&input.max_upload, &input.max_upload_unit) { Some(bytes) if bytes > 0 => match app(cx) .store - .set_setting( - crate::server::MAX_UPLOAD_SETTING, - &bytes.to_string(), - ) + .set_setting(crate::server::MAX_UPLOAD_SETTING, &bytes.to_string()) .await { Ok(()) => redirect_back(cx, "upload-limit", None), @@ -271,13 +272,8 @@ async fn settings(cx: &Cx) -> Result { let language = lang(cx).await; let store = app(cx).store; // Re-read the row so the quota bar never shows a stale number. - let fresh = store - .user(&user.id) - .await? - .unwrap_or_else(|| user.clone()); - let links = store - .share_links(&user.id) - .await?; + let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone()); + let links = store.share_links(&user.id).await?; let live_links: Vec<_> = links .iter() .filter(|link| link.revoked_at.is_none()) @@ -290,8 +286,18 @@ async fn settings(cx: &Cx) -> Result { let mut link_names: Vec<(&in_core::store::ShareLink, String)> = Vec::new(); for link in &live_links { let name = match link.kind { - ShareKind::File => store.file(&link.target_id).await.ok().flatten().map(|file| file.name), - ShareKind::Folder => store.folder(&link.target_id).await.ok().flatten().map(|folder| folder.name), + ShareKind::File => store + .file(&link.target_id) + .await + .ok() + .flatten() + .map(|file| file.name), + ShareKind::Folder => store + .folder(&link.target_id) + .await + .ok() + .flatten() + .map(|folder| folder.name), } .unwrap_or_else(|| link.target_id.clone()); link_names.push((*link, name)); @@ -403,7 +409,6 @@ async fn settings(cx: &Cx) -> Result {

(t(language, Key::AdminPanel))

-

(t(language, Key::EveryoneSubtitle))

@@ -458,19 +463,18 @@ async fn settings(cx: &Cx) -> Result {
- if let Some(limit) = upload_limit { -

(t(language, Key::UploadLimitSection))

-

(t(language, Key::UploadLimitHelp))

- - (format!("{}: {}", t(language, Key::CurrentUploadLimit), human_bytes(limit))) - - - - - } + if let Some(limit) = upload_limit { +
+ (t(language, Key::UploadLimitSection)) + (format!("{}: {}", t(language, Key::CurrentUploadLimit), human_bytes(limit))) + + + +
+ }
} diff --git a/crates/in-web/src/share.rs b/crates/in-web/src/share.rs index ddb5d5f..edfb6eb 100644 --- a/crates/in-web/src/share.rs +++ b/crates/in-web/src/share.rs @@ -22,15 +22,16 @@ use serde::Deserialize; use time::OffsetDateTime; use topcoat::Result; use topcoat::context::Cx; -use topcoat::router::error::not_found as page_not_found; use topcoat::router::content::Form; use topcoat::router::request::{headers as request_headers, uri}; use topcoat::router::response::IntoResponse; -use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, path_param, query_params, route}; +use topcoat::router::{ + HeaderName, StatusCode, header, page, path_param, query_params, route, +}; use topcoat::view::view; -use crate::i18n::{Key, Lang, lang, t}; use crate::files::entry_chip; +use crate::i18n::{Key, Lang, lang, t}; use crate::layout::{NavPage, topbar, wordmark}; use crate::server::{Refusal, app, back_to, require_user}; @@ -155,7 +156,11 @@ async fn owned_target( .map_err(|_| Refusal::Unavailable)? .is_some_and(|folder| folder.owner_id == user.id && folder.deleted_at.is_none()), }; - if owned { Ok(()) } else { Err(Refusal::NotFound) } + if owned { + Ok(()) + } else { + Err(Refusal::NotFound) + } } /// The target the caller owns, trashed or not: unsharing a trashed target /// still revokes the grant, and the grant row outlives the trash either way. @@ -178,7 +183,11 @@ async fn owned_target_for_unshare( .map_err(|_| Refusal::Unavailable)? .is_some_and(|folder| folder.owner_id == user.id), }; - if owned { Ok(()) } else { Err(Refusal::NotFound) } + if owned { + Ok(()) + } else { + Err(Refusal::NotFound) + } } #[derive(Deserialize)] @@ -349,7 +358,8 @@ async fn remove_share(cx: &Cx, Form(input): Form) -> Redirect { let Some(kind) = parse_kind(&input.kind) else { return redirect_back(cx, "/settings", "remove", Some(Refusal::NotFound)); }; - if let Err(refusal) = owned_target_for_unshare(app(cx).store.as_ref(), &user, kind, &input.target_id).await + if let Err(refusal) = + owned_target_for_unshare(app(cx).store.as_ref(), &user, kind, &input.target_id).await { return redirect_back(cx, "/settings", "remove", Some(refusal)); } @@ -445,7 +455,15 @@ async fn shared_link(cx: &Cx) -> topcoat::Result topcoat::Result topcoat::Result topcoat::Result { let language = lang(cx).await; - let here = store - .folder(at) - .await?; + let here = store.folder(at).await?; let Some(here) = here else { return dead_link(cx).await.into_response(cx); }; - let listing = store - .list_children(&root.owner_id, Some(at)) - .await?; + let listing = store.list_children(&root.owner_id, Some(at)).await?; let base = format!("/s/{token}"); let mut rows: Vec = Vec::new(); rows.extend(listing.folders.iter().map(PublicEntry::Folder)); @@ -769,7 +782,11 @@ async fn folder_card( /// cards render point back at the same token. fn current_path(cx: &Cx) -> String { let path = uri(cx).path(); - if path.is_empty() { "/".to_string() } else { path.to_string() } + if path.is_empty() { + "/".to_string() + } else { + path.to_string() + } } #[query_params] @@ -779,16 +796,27 @@ struct SharedPageQuery { q: Option, } -/// The shared list's sort, off the query: name, uploaded, size or owner. -/// Anything else is the default — by name. -fn valid_shared_sort(raw: Option<&str>) -> &'static str { - match raw { - Some("name") => "name", - Some("uploaded") => "uploaded", - Some("size") => "size", - Some("owner") => "owner", +/// The shared list's sort, off the query as `key:direction` ("owner:desc"): +/// name, uploaded, size or owner; name and owner ascend by default, the +/// measures descend. Anything else is the default — by name. +fn valid_shared_sort(raw: Option<&str>) -> (&'static str, bool) { + let (key, dir) = raw + .unwrap_or("") + .split_once(':') + .unwrap_or((raw.unwrap_or(""), "")); + let key = match key { + "name" => "name", + "uploaded" => "uploaded", + "size" => "size", + "owner" => "owner", _ => "name", - } + }; + let descending = match dir { + "asc" => false, + "desc" => true, + _ => matches!(key, "uploaded" | "size"), + }; + (key, descending) } /// The kind filter, off the query: all, folders or files. Anything else @@ -878,9 +906,7 @@ async fn shared(cx: &Cx) -> Result { .filter(|query| !query.is_empty()); let box_text = asked.clone().unwrap_or_default(); let store = app(cx).store; - let items = store - .shares_for_user(&user.id) - .await?; + let items = store.shares_for_user(&user.id).await?; let mut owners: std::collections::HashMap = std::collections::HashMap::new(); for item in &items { if !owners.contains_key(&item.owner_id) { @@ -939,31 +965,32 @@ async fn shared(cx: &Cx) -> Result { }); } let nothing_shared = rows.is_empty() && asked.is_none() && kind == "all"; - match sort { - "uploaded" => rows.sort_by(|a, b| { - b.uploaded - .cmp(&a.uploaded) - .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())) - }), - "size" => rows.sort_by(|a, b| { - b.size() - .cmp(&a.size()) - .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())) - }), - "owner" => rows.sort_by(|a, b| { - a.owner_name + let (sort, descending) = sort; + rows.sort_by(|a, b| { + let order = match sort { + "uploaded" => a + .uploaded + .cmp(&b.uploaded) + .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())), + "size" => a + .size() + .cmp(&b.size()) + .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())), + "owner" => a + .owner_name .to_lowercase() .cmp(&b.owner_name.to_lowercase()) - .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())) - }), - _ => rows.sort_by(|a, b| { - a.item + .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())), + _ => a + .item .name .to_lowercase() .cmp(&b.item.name.to_lowercase()) - .then_with(|| a.item.target_id.cmp(&b.item.target_id)) - }), - } + .then_with(|| a.item.target_id.cmp(&b.item.target_id)), + }; + if descending { order.reverse() } else { order } + }); + let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); view! { cx => (topbar(cx, NavPage::Shared, &user, language).await?) @@ -972,11 +999,15 @@ async fn shared(cx: &Cx) -> Result {
(t(language, Key::Sort)) - + + + + + + + + @@ -1037,6 +1068,7 @@ async fn shared(cx: &Cx) -> Result {
+ (crate::dropdown::dropdown_script(cx).await?) } } @@ -1049,74 +1081,64 @@ fn access_chip(language: Lang, can_download: bool) -> &'static str { } } -/// `GET /share/{kind}/{id}`: one entry's share surface — the page the drive -/// row's Share item links to. Owner only: a signed-out reader goes back to -/// the landing, and anyone else — a stranger, or a missing or trashed target -/// — answers not-found, the way the other owner surfaces do. +/// The share modal: the drive row's Share item links to `?share=kind:id` +/// and the drive page renders this over itself — the Proton-style dialog +/// (add-people row, who-has-access list, public-link section), not a +/// separate page. `None` when the target is missing, trashed, or not the +/// reader's — a hand-edited `?share=` pair simply opens nothing. /// -/// The public-link panel twins the settings page's shape: the live links for -/// this target with their expiry line, access chip and revoke form — or, when -/// none is live, the create form. The token's copy-once banner renders off -/// the create redirect's `?created=` pair, which lands back here through the -/// posting form's `Referer`, so no handler change was needed. The people -/// panel lists this target's grants with remove forms, plus the add form. -#[page("/share/{kind}/{id}")] -async fn share_entry(cx: &Cx) -> Result { - let kind_raw: &str = path_param::(cx); - let target_id: &str = path_param::(cx); +/// Every form inside posts to the existing share routes and comes back +/// through `Referer`, so the modal survives them; the minted token's +/// copy-once banner rides the `?created=` pair into the modal itself. +pub(crate) async fn share_modal( + cx: &Cx, + kind_raw: &str, + target_id: &str, + close_href: &str, + created: Option, + origin: &str, +) -> Result> { let Some(kind) = parse_kind(kind_raw) else { - return Err(page_not_found().into()); + return Ok(None); }; let user = match require_user(cx).await { Ok(user) => user, - Err(_) => { - let location = (header::LOCATION, HeaderValue::from_static("/")); - return view! { - cx => - (StatusCode::SEE_OTHER) - (location) - }; - } + Err(_) => return Ok(None), }; let language = lang(cx).await; let store = app(cx).store.clone(); // The owned, live target: present, untrashed, and theirs. Anything else - // is not-found — a stranger learns nothing about whose it is. + // opens nothing — a stranger learns not even whose it is. let (name, file): (String, Option) = match kind { ShareKind::File => { let Some(file) = store.file(target_id).await? else { - return Err(page_not_found().into()); + return Ok(None); }; if file.owner_id != user.id || file.deleted_at.is_some() { - return Err(page_not_found().into()); + return Ok(None); } (file.name.clone(), Some(file)) } ShareKind::Folder => { let Some(folder) = store.folder(target_id).await? else { - return Err(page_not_found().into()); + return Ok(None); }; if folder.owner_id != user.id || folder.deleted_at.is_some() { - return Err(page_not_found().into()); + return Ok(None); } (folder.name.clone(), None) } }; - // The live links for this target alone, newest first — the settings page - // lists every link; this page owns just its entry's. let links = store.share_links(&user.id).await?; let live: Vec<_> = links .iter() - .filter(|link| link.kind == kind && link.target_id == target_id && link.revoked_at.is_none()) + .filter(|link| { + link.kind == kind && link.target_id == target_id && link.revoked_at.is_none() + }) .collect(); - // The grants on this target. The ownership read above already vetted the - // caller, so a refusal here is only ever the target going missing - // mid-page — still not-found, never a leak. let grants = match store.shares_for_target(&user.id, kind, target_id).await { Ok(grants) => grants, - Err(StoreError::NotFound) | Err(StoreError::CrossOwner) => { - return Err(page_not_found().into()); - } + Err(StoreError::NotFound) | Err(StoreError::CrossOwner) => return Ok(None), Err(error) => return Err(error.into()), }; let mut people: Vec<(String, String, bool)> = Vec::new(); @@ -1125,117 +1147,124 @@ async fn share_entry(cx: &Cx) -> Result { people.push((grantee.display_name, grantee.email, grant.can_download)); } } - let created = created_token(uri(cx).query().unwrap_or("")); - let origin = app(cx).config.listen_url(); - view! { + let refusal = query_value(uri(cx).query().unwrap_or(""), "refusal").and_then(|code| Refusal::from_code(&code)); + Ok(Some(view! { cx => - (topbar(cx, NavPage::Drive, &user, language).await?) -
- -

- if kind == ShareKind::Folder { - - } - if let Some(file) = file.as_ref() { - (entry_chip(cx, file).await?) +

-

(kind.as_str())

- (refusal_banner(cx, language, &["create", "revoke", "add", "remove"]).await?) - if let Some(token) = created { -
-
-

(t(language, Key::LinkCreated))

-
-
-

(t(language, Key::CopyLinkOnce))

- + if let Some(token) = created { + + -
- } -
-
-

(t(language, Key::ShareLink))

+ } + + + + + + + + + -
- if live.is_empty() { -
+ for person in &people { +
+ (person.0.clone()) + (person.1.clone()) +
+ (access_chip(language, person.2)) + - - - + + - } - for link in live { -
- (format!("{} · {}", link.kind.as_str(), name.clone())) - (expiry_line(language, link.expires_at)) - (access_chip(language, link.can_download)) -
- - -
-
- } -
-
-
-
-

(t(language, Key::SharedWith))

-
-
- if people.is_empty() { -

(t(language, Key::NoShares))

- } - for person in &people { -
- (person.0.clone()) - (person.1.clone()) - (access_chip(language, person.2)) -
- - - - -
-
- } -
- - - - - -
-
-
-
+ + } + + if live.is_empty() { +
+ + + (t(language, Key::NotActive)) +
+ + + +
} + for link in live.iter().take(1) { +
+ (t(language, Key::AnyoneWithLink)) +
+ (expiry_line(language, link.expires_at)) + (access_chip(language, link.can_download)) +
+ + } + + + (share_copy_script(cx).await?) + }?)) } -/// The just-minted token off the redirect's `?created=` pair, if present. -/// Twins the drive and settings pages' helper; all three render the same -/// copy-once banner off the same pair. -fn created_token(query: &str) -> Option { - query.split('&').find_map(|pair| { - let (name, value) = pair.split_once('=')?; - (name == "created" && !value.is_empty()).then(|| value.to_string()) - }) +/// The copy button's client half: one delegated listener, idempotent across +/// the modal's re-renders (the `share-modal-copy` class marks a wired row). +async fn share_copy_script(cx: &Cx) -> Result { + use topcoat::view::Unescaped; + const JS: &str = "\ + (function () { \ + if (window.__inShareCopy) { return; } \ + window.__inShareCopy = true; \ + document.addEventListener('click', function (e) { \ + var b = e.target.closest ? e.target.closest('.share-copy') : null; \ + if (!b) { return; } \ + var u = b.parentNode.querySelector('.share-link-url'); \ + if (!u) { return; } \ + u.select(); \ + var done = function () { b.textContent = b.getAttribute('data-copied-label'); }; \ + if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(u.value).then(done, done); } \ + else { try { document.execCommand('copy'); } catch (err) {} done(); } \ + }); \ + })();"; + view! { cx => } } + /// When the link stops opening, or never on its own. Twins the settings /// page's helper; the share page renders the same expiry line. fn expiry_line(language: Lang, expires_at: Option) -> String { diff --git a/crates/in-web/src/trash.rs b/crates/in-web/src/trash.rs index 0f116e8..e9e4ed4 100644 --- a/crates/in-web/src/trash.rs +++ b/crates/in-web/src/trash.rs @@ -44,7 +44,11 @@ async fn trashed_row( .map_err(|_| Refusal::Unavailable)? .is_some_and(|folder| folder.owner_id == user.id && folder.deleted_at.is_some()), }; - if owned { Ok(()) } else { Err(Refusal::NotFound) } + if owned { + Ok(()) + } else { + Err(Refusal::NotFound) + } } type Redirect = Result<(StatusCode, [(HeaderName, String); 1])>; @@ -153,16 +157,27 @@ struct TrashQuery { q: Option, } -/// The trash's sort, off the query: name, deleted, uploaded or size. +/// The trash's sort, off the query as `key:direction` ("deleted:asc"): name, +/// deleted, uploaded or size; names ascend by default, measures descend. /// Anything else is the default — newest trash first. -fn valid_trash_sort(raw: Option<&str>) -> &'static str { - match raw { - Some("name") => "name", - Some("deleted") => "deleted", - Some("uploaded") => "uploaded", - Some("size") => "size", +fn valid_trash_sort(raw: Option<&str>) -> (&'static str, bool) { + let (key, dir) = raw + .unwrap_or("") + .split_once(':') + .unwrap_or((raw.unwrap_or(""), "")); + let key = match key { + "name" => "name", + "deleted" => "deleted", + "uploaded" => "uploaded", + "size" => "size", _ => "deleted", - } + }; + let descending = match dir { + "asc" => false, + "desc" => true, + _ => key != "name", + }; + (key, descending) } /// The kind filter, off the query: all, folders or files. Anything else @@ -227,13 +242,16 @@ impl TrashEntry<'_> { fn trash_details(language: Lang, row: &TrashEntry) -> String { let mut out = format!( "{} {} · {} {}", - t(language, Key::SortDeleted), + t(language, Key::DeletedLabel), row.deleted().date(), t(language, Key::UploadedLabel), row.uploaded().date() ); if let TrashEntry::File(file) = row { - out.push_str(&format!(" · {}", crate::settings::human_bytes(file.size_bytes))); + out.push_str(&format!( + " · {}", + crate::settings::human_bytes(file.size_bytes) + )); } out } @@ -265,10 +283,7 @@ async fn trash(cx: &Cx) -> Result { .map(|query| query.trim().to_string()) .filter(|query| !query.is_empty()); let box_text = asked.clone().unwrap_or_default(); - let listing = app(cx) - .store - .list_trash(&user.id) - .await?; + let listing = app(cx).store.list_trash(&user.id).await?; let nothing_trashed = listing.folders.is_empty() && listing.files.is_empty(); let mut rows: Vec = Vec::new(); if kind == "all" || kind == "folders" { @@ -281,29 +296,30 @@ async fn trash(cx: &Cx) -> Result { let needle = needle.to_lowercase(); rows.retain(|row| row.name().to_lowercase().contains(&needle)); } - match sort { - "name" => rows.sort_by(|a, b| { - a.name() + let (sort, descending) = sort; + rows.sort_by(|a, b| { + let order = match sort { + "name" => a + .name() .to_lowercase() .cmp(&b.name().to_lowercase()) - .then_with(|| a.id().cmp(b.id())) - }), - "uploaded" => rows.sort_by(|a, b| { - b.uploaded() - .cmp(&a.uploaded()) - .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())) - }), - "size" => rows.sort_by(|a, b| { - b.size() - .cmp(&a.size()) - .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())) - }), - _ => rows.sort_by(|a, b| { - b.deleted() - .cmp(&a.deleted()) - .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())) - }), - } + .then_with(|| a.id().cmp(b.id())), + "uploaded" => a + .uploaded() + .cmp(&b.uploaded()) + .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())), + "size" => a + .size() + .cmp(&b.size()) + .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())), + _ => a + .deleted() + .cmp(&b.deleted()) + .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())), + }; + if descending { order.reverse() } else { order } + }); + let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); view! { cx => (topbar(cx, NavPage::Trash, &user, language).await?) @@ -312,11 +328,15 @@ async fn trash(cx: &Cx) -> Result {
(t(language, Key::Sort)) - + + + + + + + + @@ -328,7 +348,7 @@ async fn trash(cx: &Cx) -> Result { - +
@@ -403,5 +423,6 @@ async fn trash(cx: &Cx) -> Result { + (crate::dropdown::dropdown_script(cx).await?) } } diff --git a/crates/in-web/tests/http.rs b/crates/in-web/tests/http.rs index bdec50a..8ddd41f 100644 --- a/crates/in-web/tests/http.rs +++ b/crates/in-web/tests/http.rs @@ -1395,11 +1395,13 @@ async fn link_create_without_the_flag_is_view_only() { blocked.text() ); // Both share surfaces print the target's name, never its raw id. - let named = app.get(&format!("/share/file/{file}"), Some(&admin)).await; + let named = app + .get(&format!("/drive?share=file:{file}"), Some(&admin)) + .await; assert_eq!(named.status, StatusCode::OK, "{}", named.text()); assert!( - named.text().contains("file · plain.txt"), - "share page showed no name: {}", + named.text().contains("plain.txt") && named.text().contains("modal-scrim"), + "share modal showed no name: {}", named.text() ); let settings = app.get("/settings", Some(&admin)).await; diff --git a/style/main.scss b/style/main.scss index 19f3168..db0785b 100644 --- a/style/main.scss +++ b/style/main.scss @@ -3202,7 +3202,7 @@ img.avatar { // draws the same chevron the rest of the app uses, so the closed look stands // in for the field it replaced. A native select keeps the browser's own // arrow on the plain .field-input box. -.field-input.dd-trigger { +.dd-trigger { appearance: none; -webkit-appearance: none; cursor: pointer; @@ -3215,7 +3215,7 @@ img.avatar { // Dark theme's lighter muted ink, baked into a second copy of the chevron: // a data-URI can't read custom properties. [data-theme="dark"] { - .field-input.dd-trigger { + .dd-trigger { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16' fill='none' stroke='%238b949e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); } } @@ -3253,6 +3253,7 @@ input[type="radio"] { // The trigger carries the select's own classes (`.status-select` or // `.field-input`), so its closed look is already right; this only resets // what a bare `