Share modal, directional sort dropdowns, flat Options menu
Browse files at this commit73b13bcfd792c7c477e44f075d64776e99c2faa1Parent: da9eb91- feat
- share modal, directional sort dropdowns, flat Options menu
9 changed files +581 -390
- crates/in-web/src/drive.rs +85 -84
- crates/in-web/src/dropdown.rs +1 -1
- crates/in-web/src/i18n.rs +60 -26
- crates/in-web/src/layout.rs +1 -1
- crates/in-web/src/settings.rs +32 -28
- crates/in-web/src/share.rs +229 -200
- crates/in-web/src/trash.rs +64 -43
- crates/in-web/tests/http.rs +5 -3
- style/main.scss +104 -4
crates/in-web/src/drive.rsmodified+85 -84
| @@ -61,7 +61,7 @@ struct DriveQuery { | ||
| 61 | 61 | q: Option<String>, |
| 62 | 62 | edit: Option<String>, |
| 63 | 63 | sort: Option<String>, |
| 64 | - dir: Option<String>, | |
| 64 | + share: Option<String>, | |
| 65 | 65 | kind: Option<String>, |
| 66 | 66 | } |
| 67 | 67 | |
| @@ -222,25 +222,30 @@ impl KindFilter { | ||
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | -fn parse_sort(raw: Option<&str>) -> Option<SortKey> { | |
| 226 | - match raw.unwrap_or("") { | |
| 227 | - "name" => Some(SortKey::Name), | |
| 228 | - "uploaded" => Some(SortKey::Uploaded), | |
| 229 | - "size" => Some(SortKey::Size), | |
| 230 | - "downloads" => Some(SortKey::Downloads), | |
| 231 | - _ => None, | |
| 232 | - } | |
| 233 | -} | |
| 234 | - | |
| 235 | -fn parse_dir(raw: Option<&str>, key: Option<SortKey>) -> SortDir { | |
| 236 | - match raw.unwrap_or("") { | |
| 225 | +/// The sort off the query: `key:direction` in one value ("size:desc"), the | |
| 226 | +/// way the dropdown's options name it. A bare key reads with its natural | |
| 227 | +/// direction (names ascend, measures descend); anything else is no sort. | |
| 228 | +fn parse_sort(raw: Option<&str>) -> Option<(SortKey, SortDir)> { | |
| 229 | + let (key, dir) = raw | |
| 230 | + .unwrap_or("") | |
| 231 | + .split_once(':') | |
| 232 | + .unwrap_or((raw.unwrap_or(""), "")); | |
| 233 | + let key = match key { | |
| 234 | + "name" => SortKey::Name, | |
| 235 | + "uploaded" => SortKey::Uploaded, | |
| 236 | + "size" => SortKey::Size, | |
| 237 | + "downloads" => SortKey::Downloads, | |
| 238 | + _ => return None, | |
| 239 | + }; | |
| 240 | + let dir = match dir { | |
| 237 | 241 | "asc" => SortDir::Asc, |
| 238 | 242 | "desc" => SortDir::Desc, |
| 239 | 243 | _ => match key { |
| 240 | - Some(SortKey::Name) | None => SortDir::Asc, | |
| 244 | + SortKey::Name => SortDir::Asc, | |
| 241 | 245 | _ => SortDir::Desc, |
| 242 | 246 | }, |
| 243 | - } | |
| 247 | + }; | |
| 248 | + Some((key, dir)) | |
| 244 | 249 | } |
| 245 | 250 | |
| 246 | 251 | fn parse_kind(raw: Option<&str>) -> KindFilter { |
| @@ -318,13 +323,9 @@ async fn drive(cx: &Cx) -> Result { | ||
| 318 | 323 | // standing order (folders-then-files as listed), ascending names, and |
| 319 | 324 | // the unfiltered kind — a hand-edited query re-orders nothing, it |
| 320 | 325 | // never refuses. |
| 321 | - let sort_key = params | |
| 326 | + let sorting = params | |
| 322 | 327 | .as_ref() |
| 323 | 328 | .and_then(|query| parse_sort(query.sort.as_deref())); |
| 324 | - let sort_dir = parse_dir( | |
| 325 | - params.as_ref().and_then(|query| query.dir.as_deref()), | |
| 326 | - sort_key, | |
| 327 | - ); | |
| 328 | 329 | let kind = params |
| 329 | 330 | .as_ref() |
| 330 | 331 | .map(|query| parse_kind(query.kind.as_deref())) |
| @@ -345,9 +346,9 @@ async fn drive(cx: &Cx) -> Result { | ||
| 345 | 346 | }; |
| 346 | 347 | // Sort and filter in the page layer, after the fetch — no store API |
| 347 | 348 | // change. Each group keeps its own order; folders-then-files stands. |
| 348 | - if let Some(key) = sort_key { | |
| 349 | - sort_folders(&mut listing.folders, key, sort_dir); | |
| 350 | - sort_files(&mut listing.files, key, sort_dir); | |
| 349 | + if let Some((key, dir)) = sorting { | |
| 350 | + sort_folders(&mut listing.folders, key, dir); | |
| 351 | + sort_files(&mut listing.files, key, dir); | |
| 351 | 352 | } |
| 352 | 353 | match kind { |
| 353 | 354 | KindFilter::All => {} |
| @@ -355,9 +356,9 @@ async fn drive(cx: &Cx) -> Result { | ||
| 355 | 356 | KindFilter::Files => listing.folders.clear(), |
| 356 | 357 | } |
| 357 | 358 | if let Some(found) = hits.as_mut() { |
| 358 | - if let Some(key) = sort_key { | |
| 359 | - sort_folders(&mut found.folders, key, sort_dir); | |
| 360 | - sort_files(&mut found.files, key, sort_dir); | |
| 359 | + if let Some((key, dir)) = sorting { | |
| 360 | + sort_folders(&mut found.folders, key, dir); | |
| 361 | + sort_files(&mut found.files, key, dir); | |
| 361 | 362 | } |
| 362 | 363 | match kind { |
| 363 | 364 | KindFilter::All => {} |
| @@ -392,15 +393,8 @@ async fn drive(cx: &Cx) -> Result { | ||
| 392 | 393 | if !current_id.is_empty() { |
| 393 | 394 | here_bits.push(format!("folder={current_id}")); |
| 394 | 395 | } |
| 395 | - if let Some(key) = sort_key { | |
| 396 | - here_bits.push(format!("sort={}", key.as_str())); | |
| 397 | - } | |
| 398 | - if params | |
| 399 | - .as_ref() | |
| 400 | - .and_then(|query| query.dir.clone()) | |
| 401 | - .is_some_and(|dir| dir == "asc" || dir == "desc") | |
| 402 | - { | |
| 403 | - here_bits.push(format!("dir={}", sort_dir.as_str())); | |
| 396 | + if let Some((key, dir)) = sorting { | |
| 397 | + here_bits.push(format!("sort={}:{}", key.as_str(), dir.as_str())); | |
| 404 | 398 | } |
| 405 | 399 | if kind != KindFilter::All { |
| 406 | 400 | here_bits.push(format!("kind={}", kind.as_str())); |
| @@ -412,14 +406,27 @@ async fn drive(cx: &Cx) -> Result { | ||
| 412 | 406 | }; |
| 413 | 407 | // The edit links extend `here` with the matching separator. |
| 414 | 408 | let edit_sep = if here.contains('?') { "&" } else { "?" }; |
| 415 | - // The direction the toggle offers: the opposite of what is showing. | |
| 416 | - let dir_flip = match sort_dir { | |
| 417 | - SortDir::Asc => "desc", | |
| 418 | - SortDir::Desc => "asc", | |
| 409 | + // The value the sort dropdown shows as selected: the parsed pair, or the | |
| 410 | + // visual default when the standing order is on. | |
| 411 | + let sort_value = sorting | |
| 412 | + .map(|(key, dir)| format!("{}:{}", key.as_str(), dir.as_str())) | |
| 413 | + .unwrap_or_else(|| "name:asc".to_string()); | |
| 414 | + // The share dialog: `?share=kind:id` renders the entry's modal over the | |
| 415 | + // page (its forms come back here through Referer, so it stays open); the | |
| 416 | + // close link is this view without the pair. A pair that names nothing | |
| 417 | + // owned and live opens nothing. | |
| 418 | + let share_pair = params.as_ref().and_then(|query| query.share.as_deref()); | |
| 419 | + let share_dialog = match share_pair.and_then(|pair| pair.split_once(':')) { | |
| 420 | + Some((kind, id)) => { | |
| 421 | + crate::share::share_modal(cx, kind, id, &here, created.clone(), &origin).await? | |
| 422 | + } | |
| 423 | + None => None, | |
| 419 | 424 | }; |
| 420 | - let dir_glyph = match sort_dir { | |
| 421 | - SortDir::Asc => "↑", | |
| 422 | - SortDir::Desc => "↓", | |
| 425 | + // The copy-once banner belongs to the modal when it is open. | |
| 426 | + let created_panel = if share_pair.is_some() { | |
| 427 | + None | |
| 428 | + } else { | |
| 429 | + created.clone() | |
| 423 | 430 | }; |
| 424 | 431 | |
| 425 | 432 | view! { |
| @@ -451,43 +458,33 @@ async fn drive(cx: &Cx) -> Result { | ||
| 451 | 458 | aria-label=(t(language, Key::SearchPlaceholder)) |
| 452 | 459 | > |
| 453 | 460 | <input type="hidden" name="folder" value=(current_id.clone())> |
| 454 | - if sort_key.is_some() { | |
| 455 | - <input type="hidden" name="sort" value=(sort_key.map(|key| key.as_str()).unwrap_or(""))> | |
| 456 | - } | |
| 457 | - <input type="hidden" name="dir" value=(sort_dir.as_str())> | |
| 458 | - if kind != KindFilter::All { | |
| 459 | - <input type="hidden" name="kind" value=(kind.as_str())> | |
| 460 | - } | |
| 461 | + if sorting.is_some() { | |
| 462 | + <input type="hidden" name="sort" value=(sort_value.clone())> | |
| 463 | + } | |
| 464 | + if kind != KindFilter::All { | |
| 465 | + <input type="hidden" name="kind" value=(kind.as_str())> | |
| 466 | + } | |
| 461 | 467 | </form> |
| 462 | 468 | <div class="spacer"></div> |
| 463 | 469 | <form class="field-box field-box-sort" method="get" action="/drive"> |
| 464 | 470 | <span class="field-text">(t(language, Key::Sort))</span> |
| 465 | - <select class="status-select" name="sort" data-autosubmit="" aria-label=(t(language, Key::Sort))> | |
| 466 | - <option value="name" selected=(sort_key.is_none() || sort_key == Some(SortKey::Name))>(t(language, Key::SortName))</option> | |
| 467 | - <option value="uploaded" selected=(sort_key == Some(SortKey::Uploaded))>(t(language, Key::SortUploaded))</option> | |
| 468 | - <option value="size" selected=(sort_key == Some(SortKey::Size))>(t(language, Key::SortSize))</option> | |
| 469 | - <option value="downloads" selected=(sort_key == Some(SortKey::Downloads))>(t(language, Key::SortDownloads))</option> | |
| 470 | - </select> | |
| 471 | - <input type="hidden" name="folder" value=(current_id.clone())> | |
| 472 | - <input type="hidden" name="q" value=(box_text.clone())> | |
| 473 | - <input type="hidden" name="dir" value=(sort_dir.as_str())> | |
| 474 | - if kind != KindFilter::All { | |
| 475 | - <input type="hidden" name="kind" value=(kind.as_str())> | |
| 476 | - } | |
| 477 | - <button class="quiet" type="submit" aria-label=(t(language, Key::Sort))>"→"</button> | |
| 478 | - </form> | |
| 479 | - <form class="field-box field-box-sort" method="get" action="/drive"> | |
| 480 | - <input type="hidden" name="folder" value=(current_id.clone())> | |
| 481 | - <input type="hidden" name="q" value=(box_text.clone())> | |
| 482 | - if sort_key.is_some() { | |
| 483 | - <input type="hidden" name="sort" value=(sort_key.map(|key| key.as_str()).unwrap_or(""))> | |
| 484 | - } | |
| 485 | - <input type="hidden" name="dir" value=(dir_flip)> | |
| 486 | - if kind != KindFilter::All { | |
| 487 | - <input type="hidden" name="kind" value=(kind.as_str())> | |
| 488 | - } | |
| 489 | - <button class="quiet" type="submit" aria-label=(t(language, Key::Sort))>(dir_glyph)</button> | |
| 490 | - </form> | |
| 471 | + <select class="status-select" name="sort" data-autosubmit="" data-nosearch="" aria-label=(t(language, Key::Sort))> | |
| 472 | + <option value="name:asc" selected=(sort_value == "name:asc")>(t(language, Key::SortNameAZ))</option> | |
| 473 | + <option value="name:desc" selected=(sort_value == "name:desc")>(t(language, Key::SortNameZA))</option> | |
| 474 | + <option value="uploaded:desc" selected=(sort_value == "uploaded:desc")>(t(language, Key::SortNewest))</option> | |
| 475 | + <option value="uploaded:asc" selected=(sort_value == "uploaded:asc")>(t(language, Key::SortOldest))</option> | |
| 476 | + <option value="size:desc" selected=(sort_value == "size:desc")>(t(language, Key::SortLargest))</option> | |
| 477 | + <option value="size:asc" selected=(sort_value == "size:asc")>(t(language, Key::SortSmallest))</option> | |
| 478 | + <option value="downloads:desc" selected=(sort_value == "downloads:desc")>(t(language, Key::SortMostDownloads))</option> | |
| 479 | + <option value="downloads:asc" selected=(sort_value == "downloads:asc")>(t(language, Key::SortLeastDownloads))</option> | |
| 480 | + </select> | |
| 481 | + <input type="hidden" name="folder" value=(current_id.clone())> | |
| 482 | + <input type="hidden" name="q" value=(box_text.clone())> | |
| 483 | + if kind != KindFilter::All { | |
| 484 | + <input type="hidden" name="kind" value=(kind.as_str())> | |
| 485 | + } | |
| 486 | + <button class="quiet" type="submit" aria-label=(t(language, Key::Sort))>"→"</button> | |
| 487 | + </form> | |
| 491 | 488 | <form class="field-box field-box-sort" method="get" action="/drive"> |
| 492 | 489 | <span class="field-text">(t(language, Key::Kind))</span> |
| 493 | 490 | <select class="status-select" name="kind" data-autosubmit="" aria-label=(t(language, Key::Kind))> |
| @@ -497,10 +494,9 @@ async fn drive(cx: &Cx) -> Result { | ||
| 497 | 494 | </select> |
| 498 | 495 | <input type="hidden" name="folder" value=(current_id.clone())> |
| 499 | 496 | <input type="hidden" name="q" value=(box_text.clone())> |
| 500 | - if sort_key.is_some() { | |
| 501 | - <input type="hidden" name="sort" value=(sort_key.map(|key| key.as_str()).unwrap_or(""))> | |
| 497 | + if sorting.is_some() { | |
| 498 | + <input type="hidden" name="sort" value=(sort_value.clone())> | |
| 502 | 499 | } |
| 503 | - <input type="hidden" name="dir" value=(sort_dir.as_str())> | |
| 504 | 500 | <button class="quiet" type="submit" aria-label=(t(language, Key::Kind))>"→"</button> |
| 505 | 501 | </form> |
| 506 | 502 | <details class="user-menu drive-add"> |
| @@ -517,7 +513,7 @@ async fn drive(cx: &Cx) -> Result { | ||
| 517 | 513 | if let Some(refusal) = refusal { |
| 518 | 514 | <p class="field-error">(refusal.message_in(language))</p> |
| 519 | 515 | } |
| 520 | - if let Some(token) = created { | |
| 516 | + if let Some(token) = created_panel { | |
| 521 | 517 | <section class="panel"> |
| 522 | 518 | <h2 class="panel-title">(t(language, Key::LinkCreated))</h2> |
| 523 | 519 | <div class="panel-body"> |
| @@ -596,7 +592,7 @@ async fn drive(cx: &Cx) -> Result { | ||
| 596 | 592 | <a class="user-menu-item" |
| 597 | 593 | href=(format!("{here}{edit_sep}edit={}", folder.id))>(t(language, Key::Rename))</a> |
| 598 | 594 | <a class="user-menu-item" |
| 599 | - href=(format!("/share/folder/{}", folder.id))>(t(language, Key::Share))</a> | |
| 595 | + href=(format!("{here}{edit_sep}share=folder:{}", folder.id))>(t(language, Key::Share))</a> | |
| 600 | 596 | <form class="user-menu-item-form" method="post" action="/api/folder/move"> |
| 601 | 597 | <input type="hidden" name="id" value=(folder.id.clone())> |
| 602 | 598 | <div class="user-menu-item-move"> |
| @@ -647,7 +643,7 @@ async fn drive(cx: &Cx) -> Result { | ||
| 647 | 643 | <a class="user-menu-item" |
| 648 | 644 | href=(format!("{here}{edit_sep}edit={}", file.id))>(t(language, Key::Rename))</a> |
| 649 | 645 | <a class="user-menu-item" |
| 650 | - href=(format!("/share/file/{}", file.id))>(t(language, Key::Share))</a> | |
| 646 | + href=(format!("{here}{edit_sep}share=file:{}", file.id))>(t(language, Key::Share))</a> | |
| 651 | 647 | <form class="user-menu-item-form" method="post" action="/api/file/move"> |
| 652 | 648 | <input type="hidden" name="id" value=(file.id.clone())> |
| 653 | 649 | <div class="user-menu-item-move"> |
| @@ -673,6 +669,9 @@ async fn drive(cx: &Cx) -> Result { | ||
| 673 | 669 | </section> |
| 674 | 670 | } |
| 675 | 671 | </main> |
| 672 | + if let Some(dialog) = share_dialog { | |
| 673 | + (dialog) | |
| 674 | + } | |
| 676 | 675 | (crate::dropdown::dropdown_script(cx).await?) |
| 677 | 676 | (upload_script(cx).await?) |
| 678 | 677 | (options_menu_script(cx).await?) |
| @@ -1107,6 +1106,11 @@ async fn options_menu_script(cx: &Cx) -> Result { | ||
| 1107 | 1106 | var above = anchor.top - roomTop - 4; \ |
| 1108 | 1107 | var below = roomBottom - anchor.bottom - 4; \ |
| 1109 | 1108 | if (above >= down.height || above > below) { details.classList.add('menu-up'); } \ |
| 1109 | + /* Never taller than the room on the chosen side: without \ | |
| 1110 | + the cap a drop-up reaches over the topbar. */ \ | |
| 1111 | + var up = details.classList.contains('menu-up'); \ | |
| 1112 | + panel.style.maxHeight = Math.max(96, (up ? above : below) - 4) + 'px'; \ | |
| 1113 | + panel.style.overflowY = 'auto'; \ | |
| 1110 | 1114 | var r = panel.getBoundingClientRect(); \ |
| 1111 | 1115 | if (r.top < roomTop && r.bottom > roomBottom) { panel.scrollIntoView({ block: 'nearest' }); } \ |
| 1112 | 1116 | }); \ |
| @@ -1128,9 +1132,6 @@ struct CreateFolderForm { | ||
| 1128 | 1132 | |
| 1129 | 1133 | /// `POST /api/folder/create`: one folder under the open one, or the root. |
| 1130 | 1134 | /// |
| 1131 | -/// A form with no name is the + menu's quick create: a generic unique name | |
| 1132 | -/// (`New folder`, `New folder 2`, …) and a 303 straight into that row's | |
| 1133 | -/// rename form. A typed name keeps the old answer — back to the page. | |
| 1134 | 1135 | #[route(POST "/api/folder/create")] |
| 1135 | 1136 | async fn create_folder(cx: &Cx, Form(input): Form<CreateFolderForm>) -> Redirect { |
| 1136 | 1137 | let user = match require_user(cx).await { |
crates/in-web/src/dropdown.rsmodified+1 -1
| @@ -197,7 +197,7 @@ pub async fn dropdown_script(cx: &Cx) -> Result { | ||
| 197 | 197 | select.__ddPanel = panel;\ |
| 198 | 198 | var allOpts = opts(select);\ |
| 199 | 199 | var search = null;\ |
| 200 | - if (allOpts.length > 7 || select.hasAttribute('data-search')) {\ | |
| 200 | + if ((allOpts.length > 7 && !select.hasAttribute('data-nosearch')) || select.hasAttribute('data-search')) {\ | |
| 201 | 201 | search = document.createElement('input');\ |
| 202 | 202 | search.type = 'text';\ |
| 203 | 203 | search.className = 'dd-search';\ |
crates/in-web/src/i18n.rsmodified+60 -26
| @@ -191,24 +191,34 @@ pub enum Key { | ||
| 191 | 191 | DropFilesToUpload, |
| 192 | 192 | Dismiss, |
| 193 | 193 | Sort, |
| 194 | - SortName, | |
| 195 | - SortUploaded, | |
| 196 | - SortSize, | |
| 197 | - SortDownloads, | |
| 194 | + SortNameAZ, | |
| 195 | + SortNameZA, | |
| 196 | + SortNewest, | |
| 197 | + SortOldest, | |
| 198 | + SortLargest, | |
| 199 | + SortSmallest, | |
| 200 | + SortMostDownloads, | |
| 201 | + SortLeastDownloads, | |
| 202 | + SortOwnerAZ, | |
| 203 | + SortOwnerZA, | |
| 198 | 204 | Kind, |
| 199 | 205 | KindAll, |
| 200 | 206 | KindFolders, |
| 201 | 207 | KindFiles, |
| 202 | - SortDeleted, | |
| 203 | - SortOwner, | |
| 208 | + DeletedLabel, | |
| 204 | 209 | // Settings limits redesign (SettingsBuild owns this block). |
| 205 | - UploadLimitHelp, | |
| 206 | - EveryoneSubtitle, | |
| 207 | 210 | UploadLimitSection, |
| 208 | 211 | // Per-entry share page (ShareBuild owns this block). |
| 209 | 212 | CreateLink, |
| 210 | 213 | ExpiresInDays, |
| 211 | 214 | NoShares, |
| 215 | + Copied, | |
| 216 | + WhoHasAccess, | |
| 217 | + YouSuffix, | |
| 218 | + OwnerRole, | |
| 219 | + PublicLinkLabel, | |
| 220 | + AnyoneWithLink, | |
| 221 | + NotActive, | |
| 212 | 222 | } |
| 213 | 223 | |
| 214 | 224 | pub fn t(lang: Lang, key: Key) -> &'static str { |
| @@ -247,7 +257,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 247 | 257 | RenameFolder => "Rename folder", |
| 248 | 258 | MoveFolder => "Move folder", |
| 249 | 259 | DeleteFolder => "Delete folder", |
| 250 | - EmptyFolder => "This folder is empty. Press + to create or upload, or drop files on this page.", | |
| 260 | + EmptyFolder => { | |
| 261 | + "This folder is empty. Press + to create or upload, or drop files on this page." | |
| 262 | + } | |
| 251 | 263 | FoldersHeading => "Folders", |
| 252 | 264 | FilesHeading => "Files", |
| 253 | 265 | NameColumn => "Name", |
| @@ -324,18 +336,28 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 324 | 336 | DropFilesToUpload => "Drop files to upload", |
| 325 | 337 | Dismiss => "Dismiss", |
| 326 | 338 | Sort => "Sort", |
| 327 | - SortName => "Name", | |
| 328 | - SortUploaded => "Uploaded", | |
| 329 | - SortSize => "Size", | |
| 330 | - SortDownloads => "Downloads", | |
| 339 | + SortNameAZ => "Name A–Z", | |
| 340 | + SortNameZA => "Name Z–A", | |
| 341 | + SortNewest => "Newest first", | |
| 342 | + SortOldest => "Oldest first", | |
| 343 | + SortLargest => "Largest first", | |
| 344 | + SortSmallest => "Smallest first", | |
| 345 | + SortMostDownloads => "Most downloaded", | |
| 346 | + SortLeastDownloads => "Least downloaded", | |
| 347 | + SortOwnerAZ => "Owner A–Z", | |
| 348 | + SortOwnerZA => "Owner Z–A", | |
| 331 | 349 | Kind => "Kind", |
| 332 | 350 | KindAll => "All", |
| 351 | + Copied => "Copied", | |
| 352 | + WhoHasAccess => "Who has access", | |
| 353 | + YouSuffix => "(you)", | |
| 354 | + OwnerRole => "owner", | |
| 355 | + PublicLinkLabel => "Public link", | |
| 356 | + AnyoneWithLink => "Anyone on the Internet with the link", | |
| 357 | + NotActive => "Not active", | |
| 333 | 358 | KindFolders => "Folders", |
| 359 | + DeletedLabel => "Deleted", | |
| 334 | 360 | KindFiles => "Files", |
| 335 | - SortDeleted => "Deleted", | |
| 336 | - SortOwner => "Owner", | |
| 337 | - UploadLimitHelp => "The most one uploaded file may be.", | |
| 338 | - EveryoneSubtitle => "Per-person storage quotas below; the single-file upload limit follows.", | |
| 339 | 361 | UploadLimitSection => "Upload limit — applies to everyone.", |
| 340 | 362 | CreateLink => "Create link", |
| 341 | 363 | ExpiresInDays => "Expires in days", |
| @@ -374,7 +396,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 374 | 396 | RenameFolder => "Klasörü yeniden adlandır", |
| 375 | 397 | MoveFolder => "Klasörü taşı", |
| 376 | 398 | DeleteFolder => "Klasörü sil", |
| 377 | - EmptyFolder => "Bu klasör boş. + ile oluştur ya da yükle, ya da dosyaları bu sayfaya bırak.", | |
| 399 | + EmptyFolder => { | |
| 400 | + "Bu klasör boş. + ile oluştur ya da yükle, ya da dosyaları bu sayfaya bırak." | |
| 401 | + } | |
| 378 | 402 | FoldersHeading => "Klasörler", |
| 379 | 403 | FilesHeading => "Dosyalar", |
| 380 | 404 | NameColumn => "Ad", |
| @@ -451,20 +475,30 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | ||
| 451 | 475 | DropFilesToUpload => "Yüklemek için dosyaları bırakın", |
| 452 | 476 | Dismiss => "Kapat", |
| 453 | 477 | Sort => "Sırala", |
| 454 | - SortName => "Ad", | |
| 455 | - SortUploaded => "Yüklenme", | |
| 456 | - SortSize => "Boyut", | |
| 457 | - SortDownloads => "İndirme", | |
| 478 | + SortNameAZ => "Ad A–Z", | |
| 479 | + SortNameZA => "Ad Z–A", | |
| 480 | + SortNewest => "Önce en yeni", | |
| 481 | + SortOldest => "Önce en eski", | |
| 482 | + SortLargest => "Önce en büyük", | |
| 483 | + SortSmallest => "Önce en küçük", | |
| 484 | + SortMostDownloads => "En çok indirilen", | |
| 485 | + SortLeastDownloads => "En az indirilen", | |
| 486 | + SortOwnerAZ => "Sahip A–Z", | |
| 487 | + SortOwnerZA => "Sahip Z–A", | |
| 458 | 488 | Kind => "Tür", |
| 459 | 489 | KindAll => "Tümü", |
| 460 | 490 | KindFolders => "Klasörler", |
| 461 | 491 | KindFiles => "Dosyalar", |
| 462 | - SortDeleted => "Silindi", | |
| 463 | - SortOwner => "Sahibi", | |
| 464 | - UploadLimitHelp => "Tek bir dosyanın alabileceği en büyük boyut.", | |
| 465 | - 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ı.", | |
| 492 | + DeletedLabel => "Silindi", | |
| 466 | 493 | UploadLimitSection => "Yükleme sınırı — herkes için geçerlidir.", |
| 467 | 494 | CreateLink => "Bağlantı oluştur", |
| 495 | + Copied => "Kopyalandı", | |
| 496 | + WhoHasAccess => "Erişimi olanlar", | |
| 497 | + YouSuffix => "(sen)", | |
| 498 | + OwnerRole => "sahip", | |
| 499 | + PublicLinkLabel => "Herkese açık bağlantı", | |
| 500 | + AnyoneWithLink => "Bağlantıya sahip olan herkes", | |
| 501 | + NotActive => "Etkin değil", | |
| 468 | 502 | ExpiresInDays => "Bitiş (gün)", |
| 469 | 503 | NoShares => "Henüz kimseyle paylaşılmadı.", |
| 470 | 504 | }, |
crates/in-web/src/layout.rsmodified+1 -1
| @@ -535,7 +535,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | ||
| 535 | 535 | scrims.forEach(function (el) { el.remove(); }); \ |
| 536 | 536 | sweepPanels(); \ |
| 537 | 537 | var u = new URL(window.location.href); \ |
| 538 | - ['task', 'file', 'confirm', 'new', 'refusal', 'on'].forEach(function (k) { u.searchParams.delete(k); }); \ | |
| 538 | + ['task', 'file', 'confirm', 'new', 'refusal', 'on', 'share', 'created'].forEach(function (k) { u.searchParams.delete(k); }); \ | |
| 539 | 539 | var q = u.searchParams.toString(); \ |
| 540 | 540 | history.replaceState(null, '', u.pathname + (q ? '?' + q : '')); \ |
| 541 | 541 | return true; \ |
crates/in-web/src/settings.rsmodified+32 -28
| @@ -128,7 +128,11 @@ async fn set_quota(cx: &Cx, Form(input): Form<QuotaForm>) -> Redirect { | ||
| 128 | 128 | return redirect_back(cx, "quota", Some(refusal)); |
| 129 | 129 | } |
| 130 | 130 | match unit_bytes(&input.quota, &input.quota_unit) { |
| 131 | - Some(quota_bytes) => match app(cx).store.set_user_quota(&input.user_id, quota_bytes).await { | |
| 131 | + Some(quota_bytes) => match app(cx) | |
| 132 | + .store | |
| 133 | + .set_user_quota(&input.user_id, quota_bytes) | |
| 134 | + .await | |
| 135 | + { | |
| 132 | 136 | Ok(()) => redirect_back(cx, "quota", None), |
| 133 | 137 | Err(error) => redirect_back(cx, "quota", Some(refusal_of(error))), |
| 134 | 138 | }, |
| @@ -158,10 +162,7 @@ async fn set_upload_limit(cx: &Cx, Form(input): Form<UploadLimitForm>) -> Redire | ||
| 158 | 162 | match unit_bytes(&input.max_upload, &input.max_upload_unit) { |
| 159 | 163 | Some(bytes) if bytes > 0 => match app(cx) |
| 160 | 164 | .store |
| 161 | - .set_setting( | |
| 162 | - crate::server::MAX_UPLOAD_SETTING, | |
| 163 | - &bytes.to_string(), | |
| 164 | - ) | |
| 165 | + .set_setting(crate::server::MAX_UPLOAD_SETTING, &bytes.to_string()) | |
| 165 | 166 | .await |
| 166 | 167 | { |
| 167 | 168 | Ok(()) => redirect_back(cx, "upload-limit", None), |
| @@ -271,13 +272,8 @@ async fn settings(cx: &Cx) -> Result { | ||
| 271 | 272 | let language = lang(cx).await; |
| 272 | 273 | let store = app(cx).store; |
| 273 | 274 | // Re-read the row so the quota bar never shows a stale number. |
| 274 | - let fresh = store | |
| 275 | - .user(&user.id) | |
| 276 | - .await? | |
| 277 | - .unwrap_or_else(|| user.clone()); | |
| 278 | - let links = store | |
| 279 | - .share_links(&user.id) | |
| 280 | - .await?; | |
| 275 | + let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone()); | |
| 276 | + let links = store.share_links(&user.id).await?; | |
| 281 | 277 | let live_links: Vec<_> = links |
| 282 | 278 | .iter() |
| 283 | 279 | .filter(|link| link.revoked_at.is_none()) |
| @@ -290,8 +286,18 @@ async fn settings(cx: &Cx) -> Result { | ||
| 290 | 286 | let mut link_names: Vec<(&in_core::store::ShareLink, String)> = Vec::new(); |
| 291 | 287 | for link in &live_links { |
| 292 | 288 | let name = match link.kind { |
| 293 | - ShareKind::File => store.file(&link.target_id).await.ok().flatten().map(|file| file.name), | |
| 294 | - ShareKind::Folder => store.folder(&link.target_id).await.ok().flatten().map(|folder| folder.name), | |
| 289 | + ShareKind::File => store | |
| 290 | + .file(&link.target_id) | |
| 291 | + .await | |
| 292 | + .ok() | |
| 293 | + .flatten() | |
| 294 | + .map(|file| file.name), | |
| 295 | + ShareKind::Folder => store | |
| 296 | + .folder(&link.target_id) | |
| 297 | + .await | |
| 298 | + .ok() | |
| 299 | + .flatten() | |
| 300 | + .map(|folder| folder.name), | |
| 295 | 301 | } |
| 296 | 302 | .unwrap_or_else(|| link.target_id.clone()); |
| 297 | 303 | link_names.push((*link, name)); |
| @@ -403,7 +409,6 @@ async fn settings(cx: &Cx) -> Result { | ||
| 403 | 409 | <h2 class="panel-title">(t(language, Key::AdminPanel))</h2> |
| 404 | 410 | </div> |
| 405 | 411 | <div class="panel-body"> |
| 406 | - <p class="field-note">(t(language, Key::EveryoneSubtitle))</p> | |
| 407 | 412 | <div class="table-pan"> |
| 408 | 413 | <table class="member-table"> |
| 409 | 414 | <thead> |
| @@ -458,19 +463,18 @@ async fn settings(cx: &Cx) -> Result { | ||
| 458 | 463 | </tbody> |
| 459 | 464 | </table> |
| 460 | 465 | </div> |
| 461 | - if let Some(limit) = upload_limit { | |
| 462 | - <p class="field-note">(t(language, Key::UploadLimitSection))</p> | |
| 463 | - <p class="field-note">(t(language, Key::UploadLimitHelp))</p> | |
| 464 | - <form class="pop-row-form" method="post" action="/api/settings/upload-limit"> | |
| 465 | - <span class="field-note">(format!("{}: {}", t(language, Key::CurrentUploadLimit), human_bytes(limit)))</span> | |
| 466 | - <input class="field-input" type="number" name="max_upload" min="0" step="any" value=(bytes_as_unit(limit).0) aria-label=(t(language, Key::MaxUploadBytes))> | |
| 467 | - <select class="field-input" name="max_upload_unit" aria-label=(t(language, Key::MaxUploadBytes))> | |
| 468 | - <option value="MiB" selected=(bytes_as_unit(limit).1 == "MiB")>"MiB"</option> | |
| 469 | - <option value="GiB" selected=(bytes_as_unit(limit).1 == "GiB")>"GiB"</option> | |
| 470 | - </select> | |
| 471 | - <button class="quiet" type="submit">(t(language, Key::Save))</button> | |
| 472 | - </form> | |
| 473 | - } | |
| 466 | + if let Some(limit) = upload_limit { | |
| 467 | + <form class="pop-row-form member-quota" method="post" action="/api/settings/upload-limit"> | |
| 468 | + <span class="field-note">(t(language, Key::UploadLimitSection))</span> | |
| 469 | + <span class="field-note">(format!("{}: {}", t(language, Key::CurrentUploadLimit), human_bytes(limit)))</span> | |
| 470 | + <input class="field-input" type="number" name="max_upload" min="0" step="any" value=(bytes_as_unit(limit).0) aria-label=(t(language, Key::MaxUploadBytes))> | |
| 471 | + <select class="field-input" name="max_upload_unit" aria-label=(t(language, Key::MaxUploadBytes))> | |
| 472 | + <option value="MiB" selected=(bytes_as_unit(limit).1 == "MiB")>"MiB"</option> | |
| 473 | + <option value="GiB" selected=(bytes_as_unit(limit).1 == "GiB")>"GiB"</option> | |
| 474 | + </select> | |
| 475 | + <button class="quiet" type="submit">(t(language, Key::Save))</button> | |
| 476 | + </form> | |
| 477 | + } | |
| 474 | 478 | </div> |
| 475 | 479 | </section> |
| 476 | 480 | } |
crates/in-web/src/share.rsmodified+229 -200
| @@ -22,15 +22,16 @@ use serde::Deserialize; | ||
| 22 | 22 | use time::OffsetDateTime; |
| 23 | 23 | use topcoat::Result; |
| 24 | 24 | use topcoat::context::Cx; |
| 25 | -use topcoat::router::error::not_found as page_not_found; | |
| 26 | 25 | use topcoat::router::content::Form; |
| 27 | 26 | use topcoat::router::request::{headers as request_headers, uri}; |
| 28 | 27 | use topcoat::router::response::IntoResponse; |
| 29 | -use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, path_param, query_params, route}; | |
| 28 | +use topcoat::router::{ | |
| 29 | + HeaderName, StatusCode, header, page, path_param, query_params, route, | |
| 30 | +}; | |
| 30 | 31 | use topcoat::view::view; |
| 31 | 32 | |
| 32 | -use crate::i18n::{Key, Lang, lang, t}; | |
| 33 | 33 | use crate::files::entry_chip; |
| 34 | +use crate::i18n::{Key, Lang, lang, t}; | |
| 34 | 35 | use crate::layout::{NavPage, topbar, wordmark}; |
| 35 | 36 | use crate::server::{Refusal, app, back_to, require_user}; |
| 36 | 37 | |
| @@ -155,7 +156,11 @@ async fn owned_target( | ||
| 155 | 156 | .map_err(|_| Refusal::Unavailable)? |
| 156 | 157 | .is_some_and(|folder| folder.owner_id == user.id && folder.deleted_at.is_none()), |
| 157 | 158 | }; |
| 158 | - if owned { Ok(()) } else { Err(Refusal::NotFound) } | |
| 159 | + if owned { | |
| 160 | + Ok(()) | |
| 161 | + } else { | |
| 162 | + Err(Refusal::NotFound) | |
| 163 | + } | |
| 159 | 164 | } |
| 160 | 165 | /// The target the caller owns, trashed or not: unsharing a trashed target |
| 161 | 166 | /// still revokes the grant, and the grant row outlives the trash either way. |
| @@ -178,7 +183,11 @@ async fn owned_target_for_unshare( | ||
| 178 | 183 | .map_err(|_| Refusal::Unavailable)? |
| 179 | 184 | .is_some_and(|folder| folder.owner_id == user.id), |
| 180 | 185 | }; |
| 181 | - if owned { Ok(()) } else { Err(Refusal::NotFound) } | |
| 186 | + if owned { | |
| 187 | + Ok(()) | |
| 188 | + } else { | |
| 189 | + Err(Refusal::NotFound) | |
| 190 | + } | |
| 182 | 191 | } |
| 183 | 192 | |
| 184 | 193 | #[derive(Deserialize)] |
| @@ -349,7 +358,8 @@ async fn remove_share(cx: &Cx, Form(input): Form<ShareUserForm>) -> Redirect { | ||
| 349 | 358 | let Some(kind) = parse_kind(&input.kind) else { |
| 350 | 359 | return redirect_back(cx, "/settings", "remove", Some(Refusal::NotFound)); |
| 351 | 360 | }; |
| 352 | - if let Err(refusal) = owned_target_for_unshare(app(cx).store.as_ref(), &user, kind, &input.target_id).await | |
| 361 | + if let Err(refusal) = | |
| 362 | + owned_target_for_unshare(app(cx).store.as_ref(), &user, kind, &input.target_id).await | |
| 353 | 363 | { |
| 354 | 364 | return redirect_back(cx, "/settings", "remove", Some(refusal)); |
| 355 | 365 | } |
| @@ -445,7 +455,15 @@ async fn shared_link(cx: &Cx) -> topcoat::Result<topcoat::router::response::Resp | ||
| 445 | 455 | return dead_link(cx).await.into_response(cx); |
| 446 | 456 | } |
| 447 | 457 | if query.dl { |
| 448 | - return download_bytes(cx, store.as_ref(), &file.id, &file.name, &file.mime, link.can_download).await; | |
| 458 | + return download_bytes( | |
| 459 | + cx, | |
| 460 | + store.as_ref(), | |
| 461 | + &file.id, | |
| 462 | + &file.name, | |
| 463 | + &file.mime, | |
| 464 | + link.can_download, | |
| 465 | + ) | |
| 466 | + .await; | |
| 449 | 467 | } |
| 450 | 468 | if query.thumb { |
| 451 | 469 | return public_thumb(cx, store.as_ref(), &file.id).await; |
| @@ -471,10 +489,7 @@ async fn shared_link(cx: &Cx) -> topcoat::Result<topcoat::router::response::Resp | ||
| 471 | 489 | let Some(file_id) = query.file.as_deref() else { |
| 472 | 490 | return dead_link(cx).await.into_response(cx); |
| 473 | 491 | }; |
| 474 | - let file = store | |
| 475 | - .file(file_id) | |
| 476 | - .await | |
| 477 | - .map_err(|_| Refusal::Unavailable); | |
| 492 | + let file = store.file(file_id).await.map_err(|_| Refusal::Unavailable); | |
| 478 | 493 | let Ok(Some(file)) = file else { |
| 479 | 494 | return dead_link(cx).await.into_response(cx); |
| 480 | 495 | }; |
| @@ -484,16 +499,21 @@ async fn shared_link(cx: &Cx) -> topcoat::Result<topcoat::router::response::Resp | ||
| 484 | 499 | { |
| 485 | 500 | return dead_link(cx).await.into_response(cx); |
| 486 | 501 | } |
| 487 | - return download_bytes(cx, store.as_ref(), &file.id, &file.name, &file.mime, link.can_download).await; | |
| 502 | + return download_bytes( | |
| 503 | + cx, | |
| 504 | + store.as_ref(), | |
| 505 | + &file.id, | |
| 506 | + &file.name, | |
| 507 | + &file.mime, | |
| 508 | + link.can_download, | |
| 509 | + ) | |
| 510 | + .await; | |
| 488 | 511 | } |
| 489 | 512 | if query.thumb { |
| 490 | 513 | let Some(file_id) = query.file.as_deref() else { |
| 491 | 514 | return dead_link(cx).await.into_response(cx); |
| 492 | 515 | }; |
| 493 | - let file = store | |
| 494 | - .file(file_id) | |
| 495 | - .await | |
| 496 | - .map_err(|_| Refusal::Unavailable); | |
| 516 | + let file = store.file(file_id).await.map_err(|_| Refusal::Unavailable); | |
| 497 | 517 | let Ok(Some(file)) = file else { |
| 498 | 518 | return dead_link(cx).await.into_response(cx); |
| 499 | 519 | }; |
| @@ -601,10 +621,7 @@ async fn public_thumb( | ||
| 601 | 621 | header::CACHE_CONTROL, |
| 602 | 622 | HeaderValue::from_static("private, max-age=31536000, immutable"), |
| 603 | 623 | ); |
| 604 | - headers.insert( | |
| 605 | - header::CONTENT_TYPE, | |
| 606 | - HeaderValue::from_static("image/webp"), | |
| 607 | - ); | |
| 624 | + headers.insert(header::CONTENT_TYPE, HeaderValue::from_static("image/webp")); | |
| 608 | 625 | let if_none_match = request_headers(cx) |
| 609 | 626 | .get(header::IF_NONE_MATCH) |
| 610 | 627 | .and_then(|value| value.to_str().ok()); |
| @@ -715,15 +732,11 @@ async fn folder_card( | ||
| 715 | 732 | token: &str, |
| 716 | 733 | ) -> topcoat::Result<topcoat::router::response::Response> { |
| 717 | 734 | let language = lang(cx).await; |
| 718 | - let here = store | |
| 719 | - .folder(at) | |
| 720 | - .await?; | |
| 735 | + let here = store.folder(at).await?; | |
| 721 | 736 | let Some(here) = here else { |
| 722 | 737 | return dead_link(cx).await.into_response(cx); |
| 723 | 738 | }; |
| 724 | - let listing = store | |
| 725 | - .list_children(&root.owner_id, Some(at)) | |
| 726 | - .await?; | |
| 739 | + let listing = store.list_children(&root.owner_id, Some(at)).await?; | |
| 727 | 740 | let base = format!("/s/{token}"); |
| 728 | 741 | let mut rows: Vec<PublicEntry> = Vec::new(); |
| 729 | 742 | rows.extend(listing.folders.iter().map(PublicEntry::Folder)); |
| @@ -769,7 +782,11 @@ async fn folder_card( | ||
| 769 | 782 | /// cards render point back at the same token. |
| 770 | 783 | fn current_path(cx: &Cx) -> String { |
| 771 | 784 | let path = uri(cx).path(); |
| 772 | - if path.is_empty() { "/".to_string() } else { path.to_string() } | |
| 785 | + if path.is_empty() { | |
| 786 | + "/".to_string() | |
| 787 | + } else { | |
| 788 | + path.to_string() | |
| 789 | + } | |
| 773 | 790 | } |
| 774 | 791 | |
| 775 | 792 | #[query_params] |
| @@ -779,16 +796,27 @@ struct SharedPageQuery { | ||
| 779 | 796 | q: Option<String>, |
| 780 | 797 | } |
| 781 | 798 | |
| 782 | -/// The shared list's sort, off the query: name, uploaded, size or owner. | |
| 783 | -/// Anything else is the default — by name. | |
| 784 | -fn valid_shared_sort(raw: Option<&str>) -> &'static str { | |
| 785 | - match raw { | |
| 786 | - Some("name") => "name", | |
| 787 | - Some("uploaded") => "uploaded", | |
| 788 | - Some("size") => "size", | |
| 789 | - Some("owner") => "owner", | |
| 799 | +/// The shared list's sort, off the query as `key:direction` ("owner:desc"): | |
| 800 | +/// name, uploaded, size or owner; name and owner ascend by default, the | |
| 801 | +/// measures descend. Anything else is the default — by name. | |
| 802 | +fn valid_shared_sort(raw: Option<&str>) -> (&'static str, bool) { | |
| 803 | + let (key, dir) = raw | |
| 804 | + .unwrap_or("") | |
| 805 | + .split_once(':') | |
| 806 | + .unwrap_or((raw.unwrap_or(""), "")); | |
| 807 | + let key = match key { | |
| 808 | + "name" => "name", | |
| 809 | + "uploaded" => "uploaded", | |
| 810 | + "size" => "size", | |
| 811 | + "owner" => "owner", | |
| 790 | 812 | _ => "name", |
| 791 | - } | |
| 813 | + }; | |
| 814 | + let descending = match dir { | |
| 815 | + "asc" => false, | |
| 816 | + "desc" => true, | |
| 817 | + _ => matches!(key, "uploaded" | "size"), | |
| 818 | + }; | |
| 819 | + (key, descending) | |
| 792 | 820 | } |
| 793 | 821 | |
| 794 | 822 | /// The kind filter, off the query: all, folders or files. Anything else |
| @@ -878,9 +906,7 @@ async fn shared(cx: &Cx) -> Result { | ||
| 878 | 906 | .filter(|query| !query.is_empty()); |
| 879 | 907 | let box_text = asked.clone().unwrap_or_default(); |
| 880 | 908 | let store = app(cx).store; |
| 881 | - let items = store | |
| 882 | - .shares_for_user(&user.id) | |
| 883 | - .await?; | |
| 909 | + let items = store.shares_for_user(&user.id).await?; | |
| 884 | 910 | let mut owners: std::collections::HashMap<String, String> = std::collections::HashMap::new(); |
| 885 | 911 | for item in &items { |
| 886 | 912 | if !owners.contains_key(&item.owner_id) { |
| @@ -939,31 +965,32 @@ async fn shared(cx: &Cx) -> Result { | ||
| 939 | 965 | }); |
| 940 | 966 | } |
| 941 | 967 | let nothing_shared = rows.is_empty() && asked.is_none() && kind == "all"; |
| 942 | - match sort { | |
| 943 | - "uploaded" => rows.sort_by(|a, b| { | |
| 944 | - b.uploaded | |
| 945 | - .cmp(&a.uploaded) | |
| 946 | - .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())) | |
| 947 | - }), | |
| 948 | - "size" => rows.sort_by(|a, b| { | |
| 949 | - b.size() | |
| 950 | - .cmp(&a.size()) | |
| 951 | - .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())) | |
| 952 | - }), | |
| 953 | - "owner" => rows.sort_by(|a, b| { | |
| 954 | - a.owner_name | |
| 968 | + let (sort, descending) = sort; | |
| 969 | + rows.sort_by(|a, b| { | |
| 970 | + let order = match sort { | |
| 971 | + "uploaded" => a | |
| 972 | + .uploaded | |
| 973 | + .cmp(&b.uploaded) | |
| 974 | + .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())), | |
| 975 | + "size" => a | |
| 976 | + .size() | |
| 977 | + .cmp(&b.size()) | |
| 978 | + .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())), | |
| 979 | + "owner" => a | |
| 980 | + .owner_name | |
| 955 | 981 | .to_lowercase() |
| 956 | 982 | .cmp(&b.owner_name.to_lowercase()) |
| 957 | - .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())) | |
| 958 | - }), | |
| 959 | - _ => rows.sort_by(|a, b| { | |
| 960 | - a.item | |
| 983 | + .then_with(|| a.item.name.to_lowercase().cmp(&b.item.name.to_lowercase())), | |
| 984 | + _ => a | |
| 985 | + .item | |
| 961 | 986 | .name |
| 962 | 987 | .to_lowercase() |
| 963 | 988 | .cmp(&b.item.name.to_lowercase()) |
| 964 | - .then_with(|| a.item.target_id.cmp(&b.item.target_id)) | |
| 965 | - }), | |
| 966 | - } | |
| 989 | + .then_with(|| a.item.target_id.cmp(&b.item.target_id)), | |
| 990 | + }; | |
| 991 | + if descending { order.reverse() } else { order } | |
| 992 | + }); | |
| 993 | + let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); | |
| 967 | 994 | view! { |
| 968 | 995 | cx => |
| 969 | 996 | (topbar(cx, NavPage::Shared, &user, language).await?) |
| @@ -972,11 +999,15 @@ async fn shared(cx: &Cx) -> Result { | ||
| 972 | 999 | <div class="filterbar"> |
| 973 | 1000 | <form class="field-box field-box-sort" method="get" action="/shared"> |
| 974 | 1001 | <span class="field-text">(t(language, Key::Sort))</span> |
| 975 | - <select class="status-select" name="sort" data-autosubmit="" aria-label=(t(language, Key::Sort))> | |
| 976 | - <option value="name" selected=(sort == "name")>(t(language, Key::SortName))</option> | |
| 977 | - <option value="uploaded" selected=(sort == "uploaded")>(t(language, Key::SortUploaded))</option> | |
| 978 | - <option value="size" selected=(sort == "size")>(t(language, Key::SortSize))</option> | |
| 979 | - <option value="owner" selected=(sort == "owner")>(t(language, Key::SortOwner))</option> | |
| 1002 | + <select class="status-select" name="sort" data-autosubmit="" data-nosearch="" aria-label=(t(language, Key::Sort))> | |
| 1003 | + <option value="name:asc" selected=(sort_value == "name:asc")>(t(language, Key::SortNameAZ))</option> | |
| 1004 | + <option value="name:desc" selected=(sort_value == "name:desc")>(t(language, Key::SortNameZA))</option> | |
| 1005 | + <option value="uploaded:desc" selected=(sort_value == "uploaded:desc")>(t(language, Key::SortNewest))</option> | |
| 1006 | + <option value="uploaded:asc" selected=(sort_value == "uploaded:asc")>(t(language, Key::SortOldest))</option> | |
| 1007 | + <option value="size:desc" selected=(sort_value == "size:desc")>(t(language, Key::SortLargest))</option> | |
| 1008 | + <option value="size:asc" selected=(sort_value == "size:asc")>(t(language, Key::SortSmallest))</option> | |
| 1009 | + <option value="owner:asc" selected=(sort_value == "owner:asc")>(t(language, Key::SortOwnerAZ))</option> | |
| 1010 | + <option value="owner:desc" selected=(sort_value == "owner:desc")>(t(language, Key::SortOwnerZA))</option> | |
| 980 | 1011 | </select> |
| 981 | 1012 | <input type="hidden" name="kind" value=(kind.to_string())> |
| 982 | 1013 | <input type="hidden" name="q" value=(box_text.clone())> |
| @@ -1037,6 +1068,7 @@ async fn shared(cx: &Cx) -> Result { | ||
| 1037 | 1068 | </div> |
| 1038 | 1069 | </section> |
| 1039 | 1070 | </main> |
| 1071 | + (crate::dropdown::dropdown_script(cx).await?) | |
| 1040 | 1072 | } |
| 1041 | 1073 | } |
| 1042 | 1074 | |
| @@ -1049,74 +1081,64 @@ fn access_chip(language: Lang, can_download: bool) -> &'static str { | ||
| 1049 | 1081 | } |
| 1050 | 1082 | } |
| 1051 | 1083 | |
| 1052 | -/// `GET /share/{kind}/{id}`: one entry's share surface — the page the drive | |
| 1053 | -/// row's Share item links to. Owner only: a signed-out reader goes back to | |
| 1054 | -/// the landing, and anyone else — a stranger, or a missing or trashed target | |
| 1055 | -/// — answers not-found, the way the other owner surfaces do. | |
| 1084 | +/// The share modal: the drive row's Share item links to `?share=kind:id` | |
| 1085 | +/// and the drive page renders this over itself — the Proton-style dialog | |
| 1086 | +/// (add-people row, who-has-access list, public-link section), not a | |
| 1087 | +/// separate page. `None` when the target is missing, trashed, or not the | |
| 1088 | +/// reader's — a hand-edited `?share=` pair simply opens nothing. | |
| 1056 | 1089 | /// |
| 1057 | -/// The public-link panel twins the settings page's shape: the live links for | |
| 1058 | -/// this target with their expiry line, access chip and revoke form — or, when | |
| 1059 | -/// none is live, the create form. The token's copy-once banner renders off | |
| 1060 | -/// the create redirect's `?created=` pair, which lands back here through the | |
| 1061 | -/// posting form's `Referer`, so no handler change was needed. The people | |
| 1062 | -/// panel lists this target's grants with remove forms, plus the add form. | |
| 1063 | -#[page("/share/{kind}/{id}")] | |
| 1064 | -async fn share_entry(cx: &Cx) -> Result { | |
| 1065 | - let kind_raw: &str = path_param::<Kind>(cx); | |
| 1066 | - let target_id: &str = path_param::<Id>(cx); | |
| 1090 | +/// Every form inside posts to the existing share routes and comes back | |
| 1091 | +/// through `Referer`, so the modal survives them; the minted token's | |
| 1092 | +/// copy-once banner rides the `?created=` pair into the modal itself. | |
| 1093 | +pub(crate) async fn share_modal( | |
| 1094 | + cx: &Cx, | |
| 1095 | + kind_raw: &str, | |
| 1096 | + target_id: &str, | |
| 1097 | + close_href: &str, | |
| 1098 | + created: Option<String>, | |
| 1099 | + origin: &str, | |
| 1100 | +) -> Result<Option<topcoat::view::View>> { | |
| 1067 | 1101 | let Some(kind) = parse_kind(kind_raw) else { |
| 1068 | - return Err(page_not_found().into()); | |
| 1102 | + return Ok(None); | |
| 1069 | 1103 | }; |
| 1070 | 1104 | let user = match require_user(cx).await { |
| 1071 | 1105 | Ok(user) => user, |
| 1072 | - Err(_) => { | |
| 1073 | - let location = (header::LOCATION, HeaderValue::from_static("/")); | |
| 1074 | - return view! { | |
| 1075 | - cx => | |
| 1076 | - (StatusCode::SEE_OTHER) | |
| 1077 | - (location) | |
| 1078 | - }; | |
| 1079 | - } | |
| 1106 | + Err(_) => return Ok(None), | |
| 1080 | 1107 | }; |
| 1081 | 1108 | let language = lang(cx).await; |
| 1082 | 1109 | let store = app(cx).store.clone(); |
| 1083 | 1110 | // The owned, live target: present, untrashed, and theirs. Anything else |
| 1084 | - // is not-found — a stranger learns nothing about whose it is. | |
| 1111 | + // opens nothing — a stranger learns not even whose it is. | |
| 1085 | 1112 | let (name, file): (String, Option<File>) = match kind { |
| 1086 | 1113 | ShareKind::File => { |
| 1087 | 1114 | let Some(file) = store.file(target_id).await? else { |
| 1088 | - return Err(page_not_found().into()); | |
| 1115 | + return Ok(None); | |
| 1089 | 1116 | }; |
| 1090 | 1117 | if file.owner_id != user.id || file.deleted_at.is_some() { |
| 1091 | - return Err(page_not_found().into()); | |
| 1118 | + return Ok(None); | |
| 1092 | 1119 | } |
| 1093 | 1120 | (file.name.clone(), Some(file)) |
| 1094 | 1121 | } |
| 1095 | 1122 | ShareKind::Folder => { |
| 1096 | 1123 | let Some(folder) = store.folder(target_id).await? else { |
| 1097 | - return Err(page_not_found().into()); | |
| 1124 | + return Ok(None); | |
| 1098 | 1125 | }; |
| 1099 | 1126 | if folder.owner_id != user.id || folder.deleted_at.is_some() { |
| 1100 | - return Err(page_not_found().into()); | |
| 1127 | + return Ok(None); | |
| 1101 | 1128 | } |
| 1102 | 1129 | (folder.name.clone(), None) |
| 1103 | 1130 | } |
| 1104 | 1131 | }; |
| 1105 | - // The live links for this target alone, newest first — the settings page | |
| 1106 | - // lists every link; this page owns just its entry's. | |
| 1107 | 1132 | let links = store.share_links(&user.id).await?; |
| 1108 | 1133 | let live: Vec<_> = links |
| 1109 | 1134 | .iter() |
| 1110 | - .filter(|link| link.kind == kind && link.target_id == target_id && link.revoked_at.is_none()) | |
| 1135 | + .filter(|link| { | |
| 1136 | + link.kind == kind && link.target_id == target_id && link.revoked_at.is_none() | |
| 1137 | + }) | |
| 1111 | 1138 | .collect(); |
| 1112 | - // The grants on this target. The ownership read above already vetted the | |
| 1113 | - // caller, so a refusal here is only ever the target going missing | |
| 1114 | - // mid-page — still not-found, never a leak. | |
| 1115 | 1139 | let grants = match store.shares_for_target(&user.id, kind, target_id).await { |
| 1116 | 1140 | Ok(grants) => grants, |
| 1117 | - Err(StoreError::NotFound) | Err(StoreError::CrossOwner) => { | |
| 1118 | - return Err(page_not_found().into()); | |
| 1119 | - } | |
| 1141 | + Err(StoreError::NotFound) | Err(StoreError::CrossOwner) => return Ok(None), | |
| 1120 | 1142 | Err(error) => return Err(error.into()), |
| 1121 | 1143 | }; |
| 1122 | 1144 | let mut people: Vec<(String, String, bool)> = Vec::new(); |
| @@ -1125,117 +1147,124 @@ async fn share_entry(cx: &Cx) -> Result { | ||
| 1125 | 1147 | people.push((grantee.display_name, grantee.email, grant.can_download)); |
| 1126 | 1148 | } |
| 1127 | 1149 | } |
| 1128 | - let created = created_token(uri(cx).query().unwrap_or("")); | |
| 1129 | - let origin = app(cx).config.listen_url(); | |
| 1130 | - view! { | |
| 1150 | + let refusal = query_value(uri(cx).query().unwrap_or(""), "refusal").and_then(|code| Refusal::from_code(&code)); | |
| 1151 | + Ok(Some(view! { | |
| 1131 | 1152 | cx => |
| 1132 | - (topbar(cx, NavPage::Drive, &user, language).await?) | |
| 1133 | - <main class="settings-stage stage-wide"> | |
| 1134 | - <div class="viewer-head"> | |
| 1135 | - <a class="quiet" href="/drive">(t(language, Key::BackToDrive))</a> | |
| 1136 | - </div> | |
| 1137 | - <h1 class="settings-title viewer-title"> | |
| 1138 | - if kind == ShareKind::Folder { | |
| 1139 | - <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | |
| 1140 | - } | |
| 1141 | - if let Some(file) = file.as_ref() { | |
| 1142 | - (entry_chip(cx, file).await?) | |
| 1153 | + <div class="modal-scrim"> | |
| 1154 | + <div class="modal share-modal"> | |
| 1155 | + <div class="viewer-head"> | |
| 1156 | + <h2 class="settings-title share-modal-title"> | |
| 1157 | + if kind == ShareKind::Folder { | |
| 1158 | + <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | |
| 1159 | + } | |
| 1160 | + if let Some(file) = file.as_ref() { | |
| 1161 | + (entry_chip(cx, file).await?) | |
| 1162 | + } | |
| 1163 | + (format!("{} “{}”", t(language, Key::Share), name.clone())) | |
| 1164 | + </h2> | |
| 1165 | + <div class="spacer"></div> | |
| 1166 | + <a class="quiet" href=(close_href.to_string()) aria-label=(t(language, Key::Close))>(t(language, Key::Close))</a> | |
| 1167 | + </div> | |
| 1168 | + if let Some(refusal) = refusal { | |
| 1169 | + <p class="field-error share-modal-note">(refusal.message_in(language))</p> | |
| 1143 | 1170 | } |
| 1144 | - (name.clone()) | |
| 1145 | - </h1> | |
| 1146 | - <p class="field-note">(kind.as_str())</p> | |
| 1147 | - (refusal_banner(cx, language, &["create", "revoke", "add", "remove"]).await?) | |
| 1148 | - if let Some(token) = created { | |
| 1149 | - <section class="panel"> | |
| 1150 | - <div class="panel-head"> | |
| 1151 | - <h2 class="panel-title">(t(language, Key::LinkCreated))</h2> | |
| 1152 | - </div> | |
| 1153 | - <div class="panel-body"> | |
| 1154 | - <p class="field-note">(t(language, Key::CopyLinkOnce))</p> | |
| 1155 | - <p class="member-link-value">(format!("{origin}/s/{token}"))</p> | |
| 1171 | + if let Some(token) = created { | |
| 1172 | + <p class="field-note share-modal-note">(t(language, Key::CopyLinkOnce))</p> | |
| 1173 | + <div class="share-link-row"> | |
| 1174 | + <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/{token}")) aria-label=(t(language, Key::ShareLink))> | |
| 1175 | + <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button> | |
| 1156 | 1176 | </div> |
| 1157 | - </section> | |
| 1158 | - } | |
| 1159 | - <section class="panel"> | |
| 1160 | - <div class="panel-head"> | |
| 1161 | - <h2 class="panel-title">(t(language, Key::ShareLink))</h2> | |
| 1177 | + } | |
| 1178 | + <form class="pop-row-form share-add" method="post" action="/api/share/user/add"> | |
| 1179 | + <input type="hidden" name="kind" value=(kind.as_str())> | |
| 1180 | + <input type="hidden" name="target_id" value=(target_id.to_string())> | |
| 1181 | + <input class="field-input share-add-email" type="email" name="email" required="" placeholder=(t(language, Key::SharePlaceholder)) aria-label=(t(language, Key::EmailAddress))> | |
| 1182 | + <select class="field-input" name="can_download" aria-label=(t(language, Key::CanDownload))> | |
| 1183 | + <option value="1">(t(language, Key::CanDownload))</option> | |
| 1184 | + <option value="0">(t(language, Key::ViewOnly))</option> | |
| 1185 | + </select> | |
| 1186 | + <button class="quiet" type="submit">(t(language, Key::Share))</button> | |
| 1187 | + </form> | |
| 1188 | + <p class="share-section">(t(language, Key::WhoHasAccess))</p> | |
| 1189 | + <div class="member-row share-owner"> | |
| 1190 | + <span class="member-name">(format!("{} {}", user.display_name.clone(), t(language, Key::YouSuffix)))</span> | |
| 1191 | + <span class="field-note">(user.email.clone())</span> | |
| 1192 | + <div class="spacer"></div> | |
| 1193 | + <span class="field-note">(t(language, Key::OwnerRole))</span> | |
| 1162 | 1194 | </div> |
| 1163 | - <div class="panel-body"> | |
| 1164 | - if live.is_empty() { | |
| 1165 | - <form class="pop-row-form" method="post" action="/api/share/link/create"> | |
| 1195 | + for person in &people { | |
| 1196 | + <div class="member-row"> | |
| 1197 | + <span class="member-name">(person.0.clone())</span> | |
| 1198 | + <span class="field-note">(person.1.clone())</span> | |
| 1199 | + <div class="spacer"></div> | |
| 1200 | + <span class="field-note">(access_chip(language, person.2))</span> | |
| 1201 | + <form class="pop-row-form" method="post" action="/api/share/user/remove"> | |
| 1166 | 1202 | <input type="hidden" name="kind" value=(kind.as_str())> |
| 1167 | 1203 | <input type="hidden" name="target_id" value=(target_id.to_string())> |
| 1168 | - <label class="field"> | |
| 1169 | - <input type="checkbox" name="can_download" value="1" checked=""> | |
| 1170 | - <span class="field-label">(t(language, Key::CanDownload))</span> | |
| 1171 | - </label> | |
| 1172 | - <label class="field"> | |
| 1173 | - <span class="field-label">(t(language, Key::ExpiresInDays))</span> | |
| 1174 | - <input class="field-input" type="number" name="expires_in_days" min="1" step="1"> | |
| 1175 | - </label> | |
| 1176 | - <button type="submit">(t(language, Key::CreateLink))</button> | |
| 1204 | + <input type="hidden" name="email" value=(person.1.clone())> | |
| 1205 | + <button class="quiet" type="submit">(t(language, Key::RemoveAccess))</button> | |
| 1177 | 1206 | </form> |
| 1178 | - } | |
| 1179 | - for link in live { | |
| 1180 | - <div class="member-row"> | |
| 1181 | - <span class="member-name">(format!("{} · {}", link.kind.as_str(), name.clone()))</span> | |
| 1182 | - <span class="field-note">(expiry_line(language, link.expires_at))</span> | |
| 1183 | - <span class="field-note">(access_chip(language, link.can_download))</span> | |
| 1184 | - <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | |
| 1185 | - <input type="hidden" name="id" value=(link.id.clone())> | |
| 1186 | - <button type="submit">(t(language, Key::RevokeLink))</button> | |
| 1187 | - </form> | |
| 1188 | - </div> | |
| 1189 | - } | |
| 1190 | - </div> | |
| 1191 | - </section> | |
| 1192 | - <section class="panel"> | |
| 1193 | - <div class="panel-head"> | |
| 1194 | - <h2 class="panel-title">(t(language, Key::SharedWith))</h2> | |
| 1195 | - </div> | |
| 1196 | - <div class="panel-body"> | |
| 1197 | - if people.is_empty() { | |
| 1198 | - <p class="field-note">(t(language, Key::NoShares))</p> | |
| 1199 | - } | |
| 1200 | - for person in &people { | |
| 1201 | - <div class="member-row"> | |
| 1202 | - <span class="member-name">(person.0.clone())</span> | |
| 1203 | - <span class="field-note">(person.1.clone())</span> | |
| 1204 | - <span class="field-note">(access_chip(language, person.2))</span> | |
| 1205 | - <form class="pop-row-form" method="post" action="/api/share/user/remove"> | |
| 1206 | - <input type="hidden" name="kind" value=(kind.as_str())> | |
| 1207 | - <input type="hidden" name="target_id" value=(target_id.to_string())> | |
| 1208 | - <input type="hidden" name="email" value=(person.1.clone())> | |
| 1209 | - <button type="submit">(t(language, Key::RemoveAccess))</button> | |
| 1210 | - </form> | |
| 1211 | - </div> | |
| 1212 | - } | |
| 1213 | - <form class="pop-row-form" method="post" action="/api/share/user/add"> | |
| 1214 | - <input type="hidden" name="kind" value=(kind.as_str())> | |
| 1215 | - <input type="hidden" name="target_id" value=(target_id.to_string())> | |
| 1216 | - <input class="field-input" type="email" name="email" required="" placeholder=(t(language, Key::SharePlaceholder)) aria-label=(t(language, Key::EmailAddress))> | |
| 1217 | - <label class="field"> | |
| 1218 | - <input type="checkbox" name="can_download" value="1" checked=""> | |
| 1219 | - <span class="field-label">(t(language, Key::CanDownload))</span> | |
| 1220 | - </label> | |
| 1221 | - <button type="submit">(t(language, Key::Share))</button> | |
| 1222 | - </form> | |
| 1223 | - </div> | |
| 1224 | - </section> | |
| 1225 | - </main> | |
| 1207 | + </div> | |
| 1208 | + } | |
| 1209 | + <p class="share-section">(t(language, Key::PublicLinkLabel))</p> | |
| 1210 | + if live.is_empty() { | |
| 1211 | + <form class="pop-row-form" method="post" action="/api/share/link/create"> | |
| 1212 | + <input type="hidden" name="kind" value=(kind.as_str())> | |
| 1213 | + <input type="hidden" name="target_id" value=(target_id.to_string())> | |
| 1214 | + <span class="field-note">(t(language, Key::NotActive))</span> | |
| 1215 | + <div class="spacer"></div> | |
| 1216 | + <select class="field-input" name="can_download" aria-label=(t(language, Key::CanDownload))> | |
| 1217 | + <option value="1">(t(language, Key::CanDownload))</option> | |
| 1218 | + <option value="0">(t(language, Key::ViewOnly))</option> | |
| 1219 | + </select> | |
| 1220 | + <input class="field-input share-expiry" type="number" name="expires_in_days" min="1" step="1" placeholder=(t(language, Key::ExpiresInDays)) aria-label=(t(language, Key::ExpiresInDays))> | |
| 1221 | + <button class="quiet" type="submit">(t(language, Key::CreateLink))</button> | |
| 1222 | + </form> | |
| 1226 | 1223 | } |
| 1224 | + for link in live.iter().take(1) { | |
| 1225 | + <div class="member-row"> | |
| 1226 | + <span class="member-name">(t(language, Key::AnyoneWithLink))</span> | |
| 1227 | + <div class="spacer"></div> | |
| 1228 | + <span class="field-note">(expiry_line(language, link.expires_at))</span> | |
| 1229 | + <span class="field-note">(access_chip(language, link.can_download))</span> | |
| 1230 | + </div> | |
| 1231 | + <div class="share-link-row"> | |
| 1232 | + <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))> | |
| 1233 | + <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | |
| 1234 | + <input type="hidden" name="id" value=(link.id.clone())> | |
| 1235 | + <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> | |
| 1236 | + </form> | |
| 1237 | + </div> | |
| 1238 | + } | |
| 1239 | + </div> | |
| 1240 | + </div> | |
| 1241 | + (share_copy_script(cx).await?) | |
| 1242 | + }?)) | |
| 1227 | 1243 | } |
| 1228 | 1244 | |
| 1229 | -/// The just-minted token off the redirect's `?created=` pair, if present. | |
| 1230 | -/// Twins the drive and settings pages' helper; all three render the same | |
| 1231 | -/// copy-once banner off the same pair. | |
| 1232 | -fn created_token(query: &str) -> Option<String> { | |
| 1233 | - query.split('&').find_map(|pair| { | |
| 1234 | - let (name, value) = pair.split_once('=')?; | |
| 1235 | - (name == "created" && !value.is_empty()).then(|| value.to_string()) | |
| 1236 | - }) | |
| 1245 | +/// The copy button's client half: one delegated listener, idempotent across | |
| 1246 | +/// the modal's re-renders (the `share-modal-copy` class marks a wired row). | |
| 1247 | +async fn share_copy_script(cx: &Cx) -> Result { | |
| 1248 | + use topcoat::view::Unescaped; | |
| 1249 | + const JS: &str = "\ | |
| 1250 | + (function () { \ | |
| 1251 | + if (window.__inShareCopy) { return; } \ | |
| 1252 | + window.__inShareCopy = true; \ | |
| 1253 | + document.addEventListener('click', function (e) { \ | |
| 1254 | + var b = e.target.closest ? e.target.closest('.share-copy') : null; \ | |
| 1255 | + if (!b) { return; } \ | |
| 1256 | + var u = b.parentNode.querySelector('.share-link-url'); \ | |
| 1257 | + if (!u) { return; } \ | |
| 1258 | + u.select(); \ | |
| 1259 | + var done = function () { b.textContent = b.getAttribute('data-copied-label'); }; \ | |
| 1260 | + if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(u.value).then(done, done); } \ | |
| 1261 | + else { try { document.execCommand('copy'); } catch (err) {} done(); } \ | |
| 1262 | + }); \ | |
| 1263 | + })();"; | |
| 1264 | + view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | |
| 1237 | 1265 | } |
| 1238 | 1266 | |
| 1267 | + | |
| 1239 | 1268 | /// When the link stops opening, or never on its own. Twins the settings |
| 1240 | 1269 | /// page's helper; the share page renders the same expiry line. |
| 1241 | 1270 | fn expiry_line(language: Lang, expires_at: Option<OffsetDateTime>) -> String { |
crates/in-web/src/trash.rsmodified+64 -43
| @@ -44,7 +44,11 @@ async fn trashed_row( | ||
| 44 | 44 | .map_err(|_| Refusal::Unavailable)? |
| 45 | 45 | .is_some_and(|folder| folder.owner_id == user.id && folder.deleted_at.is_some()), |
| 46 | 46 | }; |
| 47 | - if owned { Ok(()) } else { Err(Refusal::NotFound) } | |
| 47 | + if owned { | |
| 48 | + Ok(()) | |
| 49 | + } else { | |
| 50 | + Err(Refusal::NotFound) | |
| 51 | + } | |
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | type Redirect = Result<(StatusCode, [(HeaderName, String); 1])>; |
| @@ -153,16 +157,27 @@ struct TrashQuery { | ||
| 153 | 157 | q: Option<String>, |
| 154 | 158 | } |
| 155 | 159 | |
| 156 | -/// The trash's sort, off the query: name, deleted, uploaded or size. | |
| 160 | +/// The trash's sort, off the query as `key:direction` ("deleted:asc"): name, | |
| 161 | +/// deleted, uploaded or size; names ascend by default, measures descend. | |
| 157 | 162 | /// Anything else is the default — newest trash first. |
| 158 | -fn valid_trash_sort(raw: Option<&str>) -> &'static str { | |
| 159 | - match raw { | |
| 160 | - Some("name") => "name", | |
| 161 | - Some("deleted") => "deleted", | |
| 162 | - Some("uploaded") => "uploaded", | |
| 163 | - Some("size") => "size", | |
| 163 | +fn valid_trash_sort(raw: Option<&str>) -> (&'static str, bool) { | |
| 164 | + let (key, dir) = raw | |
| 165 | + .unwrap_or("") | |
| 166 | + .split_once(':') | |
| 167 | + .unwrap_or((raw.unwrap_or(""), "")); | |
| 168 | + let key = match key { | |
| 169 | + "name" => "name", | |
| 170 | + "deleted" => "deleted", | |
| 171 | + "uploaded" => "uploaded", | |
| 172 | + "size" => "size", | |
| 164 | 173 | _ => "deleted", |
| 165 | - } | |
| 174 | + }; | |
| 175 | + let descending = match dir { | |
| 176 | + "asc" => false, | |
| 177 | + "desc" => true, | |
| 178 | + _ => key != "name", | |
| 179 | + }; | |
| 180 | + (key, descending) | |
| 166 | 181 | } |
| 167 | 182 | |
| 168 | 183 | /// The kind filter, off the query: all, folders or files. Anything else |
| @@ -227,13 +242,16 @@ impl TrashEntry<'_> { | ||
| 227 | 242 | fn trash_details(language: Lang, row: &TrashEntry) -> String { |
| 228 | 243 | let mut out = format!( |
| 229 | 244 | "{} {} · {} {}", |
| 230 | - t(language, Key::SortDeleted), | |
| 245 | + t(language, Key::DeletedLabel), | |
| 231 | 246 | row.deleted().date(), |
| 232 | 247 | t(language, Key::UploadedLabel), |
| 233 | 248 | row.uploaded().date() |
| 234 | 249 | ); |
| 235 | 250 | if let TrashEntry::File(file) = row { |
| 236 | - out.push_str(&format!(" · {}", crate::settings::human_bytes(file.size_bytes))); | |
| 251 | + out.push_str(&format!( | |
| 252 | + " · {}", | |
| 253 | + crate::settings::human_bytes(file.size_bytes) | |
| 254 | + )); | |
| 237 | 255 | } |
| 238 | 256 | out |
| 239 | 257 | } |
| @@ -265,10 +283,7 @@ async fn trash(cx: &Cx) -> Result { | ||
| 265 | 283 | .map(|query| query.trim().to_string()) |
| 266 | 284 | .filter(|query| !query.is_empty()); |
| 267 | 285 | let box_text = asked.clone().unwrap_or_default(); |
| 268 | - let listing = app(cx) | |
| 269 | - .store | |
| 270 | - .list_trash(&user.id) | |
| 271 | - .await?; | |
| 286 | + let listing = app(cx).store.list_trash(&user.id).await?; | |
| 272 | 287 | let nothing_trashed = listing.folders.is_empty() && listing.files.is_empty(); |
| 273 | 288 | let mut rows: Vec<TrashEntry> = Vec::new(); |
| 274 | 289 | if kind == "all" || kind == "folders" { |
| @@ -281,29 +296,30 @@ async fn trash(cx: &Cx) -> Result { | ||
| 281 | 296 | let needle = needle.to_lowercase(); |
| 282 | 297 | rows.retain(|row| row.name().to_lowercase().contains(&needle)); |
| 283 | 298 | } |
| 284 | - match sort { | |
| 285 | - "name" => rows.sort_by(|a, b| { | |
| 286 | - a.name() | |
| 299 | + let (sort, descending) = sort; | |
| 300 | + rows.sort_by(|a, b| { | |
| 301 | + let order = match sort { | |
| 302 | + "name" => a | |
| 303 | + .name() | |
| 287 | 304 | .to_lowercase() |
| 288 | 305 | .cmp(&b.name().to_lowercase()) |
| 289 | - .then_with(|| a.id().cmp(b.id())) | |
| 290 | - }), | |
| 291 | - "uploaded" => rows.sort_by(|a, b| { | |
| 292 | - b.uploaded() | |
| 293 | - .cmp(&a.uploaded()) | |
| 294 | - .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())) | |
| 295 | - }), | |
| 296 | - "size" => rows.sort_by(|a, b| { | |
| 297 | - b.size() | |
| 298 | - .cmp(&a.size()) | |
| 299 | - .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())) | |
| 300 | - }), | |
| 301 | - _ => rows.sort_by(|a, b| { | |
| 302 | - b.deleted() | |
| 303 | - .cmp(&a.deleted()) | |
| 304 | - .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())) | |
| 305 | - }), | |
| 306 | - } | |
| 306 | + .then_with(|| a.id().cmp(b.id())), | |
| 307 | + "uploaded" => a | |
| 308 | + .uploaded() | |
| 309 | + .cmp(&b.uploaded()) | |
| 310 | + .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())), | |
| 311 | + "size" => a | |
| 312 | + .size() | |
| 313 | + .cmp(&b.size()) | |
| 314 | + .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())), | |
| 315 | + _ => a | |
| 316 | + .deleted() | |
| 317 | + .cmp(&b.deleted()) | |
| 318 | + .then_with(|| a.name().to_lowercase().cmp(&b.name().to_lowercase())), | |
| 319 | + }; | |
| 320 | + if descending { order.reverse() } else { order } | |
| 321 | + }); | |
| 322 | + let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); | |
| 307 | 323 | view! { |
| 308 | 324 | cx => |
| 309 | 325 | (topbar(cx, NavPage::Trash, &user, language).await?) |
| @@ -312,11 +328,15 @@ async fn trash(cx: &Cx) -> Result { | ||
| 312 | 328 | <div class="filterbar"> |
| 313 | 329 | <form class="field-box field-box-sort" method="get" action="/trash"> |
| 314 | 330 | <span class="field-text">(t(language, Key::Sort))</span> |
| 315 | - <select class="status-select" name="sort" data-autosubmit="" aria-label=(t(language, Key::Sort))> | |
| 316 | - <option value="deleted" selected=(sort == "deleted")>(t(language, Key::SortDeleted))</option> | |
| 317 | - <option value="name" selected=(sort == "name")>(t(language, Key::SortName))</option> | |
| 318 | - <option value="uploaded" selected=(sort == "uploaded")>(t(language, Key::SortUploaded))</option> | |
| 319 | - <option value="size" selected=(sort == "size")>(t(language, Key::SortSize))</option> | |
| 331 | + <select class="status-select" name="sort" data-autosubmit="" data-nosearch="" aria-label=(t(language, Key::Sort))> | |
| 332 | + <option value="deleted:desc" selected=(sort_value == "deleted:desc")>(t(language, Key::SortNewest))</option> | |
| 333 | + <option value="deleted:asc" selected=(sort_value == "deleted:asc")>(t(language, Key::SortOldest))</option> | |
| 334 | + <option value="name:asc" selected=(sort_value == "name:asc")>(t(language, Key::SortNameAZ))</option> | |
| 335 | + <option value="name:desc" selected=(sort_value == "name:desc")>(t(language, Key::SortNameZA))</option> | |
| 336 | + <option value="uploaded:desc" selected=(sort_value == "uploaded:desc")>(t(language, Key::SortNewest))</option> | |
| 337 | + <option value="uploaded:asc" selected=(sort_value == "uploaded:asc")>(t(language, Key::SortOldest))</option> | |
| 338 | + <option value="size:desc" selected=(sort_value == "size:desc")>(t(language, Key::SortLargest))</option> | |
| 339 | + <option value="size:asc" selected=(sort_value == "size:asc")>(t(language, Key::SortSmallest))</option> | |
| 320 | 340 | </select> |
| 321 | 341 | <input type="hidden" name="kind" value=(kind.to_string())> |
| 322 | 342 | <input type="hidden" name="q" value=(box_text.clone())> |
| @@ -328,7 +348,7 @@ async fn trash(cx: &Cx) -> Result { | ||
| 328 | 348 | <option value="folders" selected=(kind == "folders")>(t(language, Key::KindFolders))</option> |
| 329 | 349 | <option value="files" selected=(kind == "files")>(t(language, Key::KindFiles))</option> |
| 330 | 350 | </select> |
| 331 | - <input type="hidden" name="sort" value=(sort.to_string())> | |
| 351 | + <input type="hidden" name="sort" value=(sort_value.clone())> | |
| 332 | 352 | <input type="hidden" name="q" value=(box_text.clone())> |
| 333 | 353 | </form> |
| 334 | 354 | <form class="field-box field-box-search" method="get" action="/trash"> |
| @@ -341,7 +361,7 @@ async fn trash(cx: &Cx) -> Result { | ||
| 341 | 361 | placeholder=(t(language, Key::SearchPlaceholder)) |
| 342 | 362 | aria-label=(t(language, Key::SearchPlaceholder)) |
| 343 | 363 | > |
| 344 | - <input type="hidden" name="sort" value=(sort.to_string())> | |
| 364 | + <input type="hidden" name="sort" value=(sort_value.clone())> | |
| 345 | 365 | <input type="hidden" name="kind" value=(kind.to_string())> |
| 346 | 366 | </form> |
| 347 | 367 | </div> |
| @@ -403,5 +423,6 @@ async fn trash(cx: &Cx) -> Result { | ||
| 403 | 423 | </div> |
| 404 | 424 | </section> |
| 405 | 425 | </main> |
| 426 | + (crate::dropdown::dropdown_script(cx).await?) | |
| 406 | 427 | } |
| 407 | 428 | } |
crates/in-web/tests/http.rsmodified+5 -3
| @@ -1395,11 +1395,13 @@ async fn link_create_without_the_flag_is_view_only() { | ||
| 1395 | 1395 | blocked.text() |
| 1396 | 1396 | ); |
| 1397 | 1397 | // Both share surfaces print the target's name, never its raw id. |
| 1398 | - let named = app.get(&format!("/share/file/{file}"), Some(&admin)).await; | |
| 1398 | + let named = app | |
| 1399 | + .get(&format!("/drive?share=file:{file}"), Some(&admin)) | |
| 1400 | + .await; | |
| 1399 | 1401 | assert_eq!(named.status, StatusCode::OK, "{}", named.text()); |
| 1400 | 1402 | assert!( |
| 1401 | - named.text().contains("file · plain.txt"), | |
| 1402 | - "share page showed no name: {}", | |
| 1403 | + named.text().contains("plain.txt") && named.text().contains("modal-scrim"), | |
| 1404 | + "share modal showed no name: {}", | |
| 1403 | 1405 | named.text() |
| 1404 | 1406 | ); |
| 1405 | 1407 | let settings = app.get("/settings", Some(&admin)).await; |
style/main.scssmodified+104 -4
| @@ -3202,7 +3202,7 @@ img.avatar { | ||
| 3202 | 3202 | // draws the same chevron the rest of the app uses, so the closed look stands |
| 3203 | 3203 | // in for the field it replaced. A native select keeps the browser's own |
| 3204 | 3204 | // arrow on the plain .field-input box. |
| 3205 | -.field-input.dd-trigger { | |
| 3205 | +.dd-trigger { | |
| 3206 | 3206 | appearance: none; |
| 3207 | 3207 | -webkit-appearance: none; |
| 3208 | 3208 | cursor: pointer; |
| @@ -3215,7 +3215,7 @@ img.avatar { | ||
| 3215 | 3215 | // Dark theme's lighter muted ink, baked into a second copy of the chevron: |
| 3216 | 3216 | // a data-URI can't read custom properties. |
| 3217 | 3217 | [data-theme="dark"] { |
| 3218 | - .field-input.dd-trigger { | |
| 3218 | + .dd-trigger { | |
| 3219 | 3219 | 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"); |
| 3220 | 3220 | } |
| 3221 | 3221 | } |
| @@ -3253,6 +3253,7 @@ input[type="radio"] { | ||
| 3253 | 3253 | // The trigger carries the select's own classes (`.status-select` or |
| 3254 | 3254 | // `.field-input`), so its closed look is already right; this only resets |
| 3255 | 3255 | // what a bare `<button>` adds on top of that. |
| 3256 | +.status-select.dd-trigger { padding: 0 24px 0 0; background-position: right 4px center; } | |
| 3256 | 3257 | .dd-trigger { |
| 3257 | 3258 | display: flex; |
| 3258 | 3259 | align-items: center; |
| @@ -3261,7 +3262,6 @@ input[type="radio"] { | ||
| 3261 | 3262 | cursor: pointer; |
| 3262 | 3263 | } |
| 3263 | 3264 | |
| 3264 | -.status-select.dd-trigger { padding: 0; } | |
| 3265 | 3265 | |
| 3266 | 3266 | .dd-panel { |
| 3267 | 3267 | position: fixed; |
| @@ -4777,7 +4777,13 @@ input[type="radio"] { | ||
| 4777 | 4777 | // sits flush inside the field box instead of framing itself twice. |
| 4778 | 4778 | .field-box .dd-trigger { |
| 4779 | 4779 | border: none; |
| 4780 | - background: transparent; | |
| 4780 | + background-color: transparent; | |
| 4781 | +} | |
| 4782 | + | |
| 4783 | +// The → submit is the no-script path: once `dropdown.rs` has enhanced the | |
| 4784 | +// select it only repeats the autosubmit, so it bows out. | |
| 4785 | +.field-box:has([data-dd-done]) > button[type="submit"] { | |
| 4786 | + display: none; | |
| 4781 | 4787 | } |
| 4782 | 4788 | |
| 4783 | 4789 | // The native select behind an enhanced trigger never takes space: the |
| @@ -4834,3 +4840,97 @@ div.member-row { | ||
| 4834 | 4840 | div.member-row + div.member-row { |
| 4835 | 4841 | border-top: 1px solid var(--border); |
| 4836 | 4842 | } |
| 4843 | + | |
| 4844 | +// -- entry Options menu: flat rows, no boxed buttons ------------------------- | |
| 4845 | +// | |
| 4846 | +// Inside the menu, `.quiet`'s border box reads as a second frame (his round-4 | |
| 4847 | +// screenshot): the Delete and Move submits become flat menu rows like the | |
| 4848 | +// Rename/Share links — Delete keeps only its danger ink, Move only the | |
| 4849 | +// accent. The Move row's select trigger keeps the house chevron. | |
| 4850 | +.entry-options .user-menu-panel .quiet { | |
| 4851 | + border: none; | |
| 4852 | + background: none; | |
| 4853 | + border-radius: 0; | |
| 4854 | + width: 100%; | |
| 4855 | + height: 32px; | |
| 4856 | + justify-content: flex-start; | |
| 4857 | + padding: 0 14px; | |
| 4858 | + font-size: 13px; | |
| 4859 | + color: var(--ink-soft); | |
| 4860 | + | |
| 4861 | + &:hover { background: var(--row-hover); color: var(--ink); border: none; } | |
| 4862 | +} | |
| 4863 | +.entry-options .user-menu-panel .quiet.quiet-danger { | |
| 4864 | + color: var(--danger); | |
| 4865 | + | |
| 4866 | + &:hover { background: var(--row-hover); color: var(--danger); border: none; } | |
| 4867 | +} | |
| 4868 | +// The Move submit sits beside its select, not under it: compact, accent-ink, | |
| 4869 | +// no full-width row there. | |
| 4870 | +.entry-options .user-menu-panel .user-menu-item-move .quiet { | |
| 4871 | + width: auto; | |
| 4872 | + flex: none; | |
| 4873 | + padding: 0 2px; | |
| 4874 | + color: var(--accent); | |
| 4875 | + | |
| 4876 | + &:hover { background: none; color: var(--accent-ink); } | |
| 4877 | +} | |
| 4878 | + | |
| 4879 | +// -- the share modal --------------------------------------------------------- | |
| 4880 | +// | |
| 4881 | +// The Proton-shaped dialog: narrower than the default 780px modal, one calm | |
| 4882 | +// column — title row, add-people row, access list, public-link section. | |
| 4883 | +.share-modal { | |
| 4884 | + width: 560px; | |
| 4885 | + padding: 18px 20px 20px; | |
| 4886 | +} | |
| 4887 | +.share-modal .viewer-head { | |
| 4888 | + margin: 0 0 12px; | |
| 4889 | +} | |
| 4890 | +.share-modal-title { | |
| 4891 | + font-size: 16px; | |
| 4892 | + display: flex; | |
| 4893 | + align-items: center; | |
| 4894 | + gap: 10px; | |
| 4895 | + min-width: 0; | |
| 4896 | +} | |
| 4897 | +.share-modal-note { | |
| 4898 | + margin: 0 0 10px; | |
| 4899 | +} | |
| 4900 | +// The add-people row and the link row: input takes the room, controls pin | |
| 4901 | +// right — one line each, like the reference design. | |
| 4902 | +.share-add { | |
| 4903 | + display: flex; | |
| 4904 | + gap: 8px; | |
| 4905 | + margin: 0 0 16px; | |
| 4906 | + | |
| 4907 | + .share-add-email { flex: 1; min-width: 0; } | |
| 4908 | +} | |
| 4909 | +.share-link-row { | |
| 4910 | + display: flex; | |
| 4911 | + gap: 8px; | |
| 4912 | + align-items: center; | |
| 4913 | + margin: 6px 0 4px; | |
| 4914 | + | |
| 4915 | + .share-link-url { flex: 1; min-width: 0; color: var(--muted); } | |
| 4916 | + .pop-row-form { flex: none; } | |
| 4917 | +} | |
| 4918 | +// A section label inside the modal: muted, small, with air above. | |
| 4919 | +.share-section { | |
| 4920 | + margin: 14px 0 6px; | |
| 4921 | + font-size: 12px; | |
| 4922 | + font-weight: 500; | |
| 4923 | + color: var(--muted); | |
| 4924 | +} | |
| 4925 | +// The owner row never carries a form; the grants' remove buttons stay quiet. | |
| 4926 | +.share-modal .member-row { | |
| 4927 | + padding: 6px 0; | |
| 4928 | + display: flex; | |
| 4929 | + align-items: center; | |
| 4930 | + gap: 8px; | |
| 4931 | +} | |
| 4932 | +.share-modal .member-row .member-name { | |
| 4933 | + flex: none; | |
| 4934 | + font-weight: 500; | |
| 4935 | +} | |
| 4936 | +.share-expiry { width: 90px; flex: none; } |