From a4ded545a326076c20129c17e4b767a71f412377 Mon Sep 17 00:00:00 2001 From: bchbib <1023915+bchbib@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:12:59 +0100 Subject: [PATCH 1/2] feat(ui): step through a ticket's images in its header, show the count on the card A ticket with several images showed only the first one: on its card and as the header of the ticket view. The others sat in the attachment list at the bottom of the ticket and were easy to miss; on the board nothing said they were there. - Card: when a ticket holds more than one image, its cover carries a small badge with the number of images. - Ticket view: with more than one image the header is a small gallery. Previous / next buttons on the image, or the left and right arrow keys, step through the images and wrap around; a counter shows the position and the first image is marked "Cover" (the one the card shows). - The arrow keys are left alone while typing in a field, while the full-screen preview is open and when a modifier is held. Frontend only; tickets with one image or none look as before. Co-Authored-By: Claude Fable 5.2 --- apps/desktop/src/lib/components/Card.svelte | 32 +++++- .../src/lib/components/TicketModal.svelte | 108 ++++++++++++++++-- 2 files changed, 129 insertions(+), 11 deletions(-) diff --git a/apps/desktop/src/lib/components/Card.svelte b/apps/desktop/src/lib/components/Card.svelte index ce8ab0c..3a46584 100644 --- a/apps/desktop/src/lib/components/Card.svelte +++ b/apps/desktop/src/lib/components/Card.svelte @@ -2,7 +2,7 @@ import { onMount } from 'svelte'; import { get } from 'svelte/store'; import { browser } from '$app/environment'; - import { MessageSquare, Paperclip, CheckSquare, ShieldCheck } from 'lucide-svelte'; + import { MessageSquare, Paperclip, CheckSquare, ShieldCheck, Images } from 'lucide-svelte'; import Chip from './ui/Chip.svelte'; import Avatar from './Avatar.svelte'; import CardMenu from './CardMenu.svelte'; @@ -85,10 +85,12 @@ }, step); return () => clearInterval(iv); }); - // First image attachment becomes a compact card cover, like Trello. - let cover = $derived( - ticket.attachments.find((a) => mediaKind(a.mime, a.name) === 'image') + // First image attachment becomes a compact card cover, like Trello. When the + // ticket holds more images than the one shown, the cover says how many. + let images = $derived( + ticket.attachments.filter((a) => mediaKind(a.mime, a.name) === 'image') ); + let cover = $derived(images[0]); // Resolve an assignee to its identity. Identities are keyed by bare email, but // assignees are often stored as the full git form `Name ` — so fall back // to matching the address inside the angle brackets (else the avatar/name/kind @@ -154,6 +156,11 @@ alt={cover.name} loading="lazy" /> + {#if images.length > 1} + {images.length} + {/if} {/if} @@ -344,6 +351,7 @@ } } .cover { + position: relative; margin: -12px -12px 0; max-height: 120px; overflow: hidden; @@ -356,6 +364,22 @@ max-height: 120px; object-fit: cover; } + .cover-count { + position: absolute; + right: 8px; + bottom: 8px; + display: inline-flex; + align-items: center; + gap: 4px; + padding: 2px 7px; + border-radius: var(--wp-r-pill); + background: color-mix(in srgb, var(--wp-card) 78%, transparent); + backdrop-filter: blur(4px); + color: var(--wp-text); + font-size: 11px; + font-family: var(--wp-font-mono); + line-height: 16px; + } .prio { width: 8px; height: 8px; diff --git a/apps/desktop/src/lib/components/TicketModal.svelte b/apps/desktop/src/lib/components/TicketModal.svelte index 8a7de54..9462d49 100644 --- a/apps/desktop/src/lib/components/TicketModal.svelte +++ b/apps/desktop/src/lib/components/TicketModal.svelte @@ -2,7 +2,17 @@ import { fade, scale, fly } from 'svelte/transition'; import { browser } from '$app/environment'; import { get } from 'svelte/store'; - import { X, Pencil, Send, Flag, Check, CheckSquare, ShieldCheck } from 'lucide-svelte'; + import { + X, + Pencil, + Send, + Flag, + Check, + CheckSquare, + ShieldCheck, + ChevronLeft, + ChevronRight + } from 'lucide-svelte'; import Chip from './ui/Chip.svelte'; import Avatar from './Avatar.svelte'; import Markdown from './Markdown.svelte'; @@ -15,7 +25,7 @@ import MdToolbar from './MdToolbar.svelte'; import { mdkeys, mdlists } from '$lib/md'; import { mention } from '$lib/mention'; - import { openLightbox } from '$lib/stores/lightbox'; + import { lightbox, openLightbox } from '$lib/stores/lightbox'; import { api, mediaUrl } from '$lib/api'; import { board, @@ -54,10 +64,25 @@ let currentList = $derived($board?.lists.find((l) => l.tickets.some((t) => t.id === ticketId))); let readOnly = $derived($rewinding); - // First image attachment becomes the modal cover. - let cover = $derived( - ticket?.attachments.find((a) => mediaKind(a.mime, a.name) === 'image') + // The ticket's images, in attachment order. The first is the cover: the one + // its card shows on the board, and the one the header opens on. With more than + // one, the header is a small gallery - the buttons on the image, or the left + // and right arrow keys, step through them (and wrap around). + let images = $derived( + ticket?.attachments.filter((a) => mediaKind(a.mime, a.name) === 'image') ?? [] ); + // Remembered by path, so the image in view stays put when attachments change. + let shownPath = $state(null); + $effect(() => { + void ticketId; + shownPath = null; + }); + let shownAt = $derived(Math.max(0, images.findIndex((a) => a.path === shownPath))); + let shown = $derived(images[shownAt]); + function stepImage(by: -1 | 1) { + if (images.length < 2) return; + shownPath = images[(shownAt + by + images.length) % images.length].path; + } // Comments and activity events, interleaved and sorted newest-first - the // Trello-style timeline in the right pane. @@ -302,6 +327,17 @@ }); } function onKey(e: KeyboardEvent) { + if ((e.key === 'ArrowLeft' || e.key === 'ArrowRight') && ticketId && images.length > 1) { + // The arrows belong to whatever is being typed in, to an open full-screen + // preview, and to shortcuts with a modifier - only otherwise to the gallery. + if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return; + if (get(lightbox)) return; + const el = e.target instanceof HTMLElement ? e.target : null; + if (el?.isContentEditable || el?.closest('input, textarea, select')) return; + e.preventDefault(); + stepImage(e.key === 'ArrowLeft' ? -1 : 1); + return; + } if (e.key !== 'Escape' || !ticketId) return; // An inner control (open popover, a checklist-item edit input) that handled the // Escape marks it defaultPrevented - don't also close the whole modal then. @@ -322,9 +358,25 @@ transition:scale={{ duration: dur, start: 0.97, opacity: 0 }} > - {#if cover} + {#if shown}
- {cover.name} + {shown.name} + {#if images.length > 1} + + +
+ {shownAt + 1} / {images.length} + {#if shownAt === 0} + Cover + {/if} +
+ {/if}
{/if} @@ -680,6 +732,7 @@ box-shadow: var(--wp-shadow-lift); } .cover { + position: relative; width: 100%; max-height: 260px; overflow: hidden; @@ -692,6 +745,47 @@ max-height: 260px; object-fit: cover; } + .cover-nav { + position: absolute; + top: 50%; + transform: translateY(-50%); + display: inline-flex; + padding: 8px; + border-radius: var(--wp-r-pill); + border: none; + background: color-mix(in srgb, var(--wp-card) 70%, transparent); + backdrop-filter: blur(4px); + color: var(--wp-text-muted); + cursor: pointer; + } + .cover-nav.prev { + left: 12px; + } + .cover-nav.next { + right: 12px; + } + .cover-nav:hover { + background: var(--wp-elevated); + color: var(--wp-text); + } + .cover-bar { + position: absolute; + left: 12px; + bottom: 12px; + display: flex; + align-items: center; + gap: 6px; + } + .cover-tag { + padding: 3px 9px; + border-radius: var(--wp-r-pill); + background: color-mix(in srgb, var(--wp-card) 78%, transparent); + backdrop-filter: blur(4px); + color: var(--wp-text); + font-size: 11px; + font-family: var(--wp-font-mono); + line-height: 16px; + } .close { position: absolute; top: 12px; From 10e63cc8fc6e6430d1fd300135ec65b073ccf69f Mon Sep 17 00:00:00 2001 From: bchbib <1023915+bchbib@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:16:14 +0100 Subject: [PATCH 2/2] feat: make any of a ticket's images its cover The cover - the image a ticket's card shows on the board - was always the first image attached. To show another one you had to detach and re-attach files in the right order. The cover stays "the first image among the attachments", so choosing one moves that attachment to the front of the list; the others keep their order and the ticket file gets no new field. - core: ops::set_cover (logs a `cover` activity; a no-op when the attachment is already first), with a test. - daemon: POST /api/tickets/{id}/attachments/cover { path }. - cli: wipe media cover . - board UI: stepping to another image in the ticket header shows a "Make cover" button in place of the "Cover" mark; the activity feed says "made the cover". Builds on the header gallery (feat/ticket-image-gallery). NOT COMPILED: written without a Rust toolchain. The Rust part is unbuilt and untested; the UI part is type-checked (svelte-check). Co-Authored-By: Claude Fable 5.2 --- apps/desktop/src/lib/api.ts | 8 +++ .../src/lib/components/TicketModal.svelte | 34 +++++++++- apps/desktop/src/lib/stores/board.ts | 12 ++++ apps/desktop/src/lib/types.ts | 2 +- apps/desktop/src/lib/utils.ts | 2 + apps/web/src/pages/docs/data.ts | 5 ++ crates/wipe-cli/src/args.rs | 7 +++ crates/wipe-cli/src/commands.rs | 14 +++++ crates/wipe-cli/src/ids.rs | 3 +- crates/wipe-core/src/model.rs | 2 +- crates/wipe-core/src/ops.rs | 62 +++++++++++++++++++ crates/wipe-daemon/src/api.rs | 17 ++++- crates/wipe-daemon/src/lib.rs | 1 + 13 files changed, 164 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/lib/api.ts b/apps/desktop/src/lib/api.ts index f092f9b..87f1b17 100644 --- a/apps/desktop/src/lib/api.ts +++ b/apps/desktop/src/lib/api.ts @@ -528,6 +528,14 @@ export const api = { ); }, + /** Make the attachment at `path` the ticket's cover (it moves to the front). */ + setCover(id: string, path: string, project?: string): Promise<{ ok: boolean }> { + return req<{ ok: boolean }>( + `/api/tickets/${encodeURIComponent(id)}/attachments/cover${qs({ project })}`, + { method: 'POST', body: JSON.stringify({ path }) } + ); + }, + deleteAttachment(id: string, path: string, project?: string): Promise<{ ok: boolean }> { return req<{ ok: boolean }>( `/api/tickets/${encodeURIComponent(id)}/attachments${qs({ project })}`, diff --git a/apps/desktop/src/lib/components/TicketModal.svelte b/apps/desktop/src/lib/components/TicketModal.svelte index 9462d49..2b1aa89 100644 --- a/apps/desktop/src/lib/components/TicketModal.svelte +++ b/apps/desktop/src/lib/components/TicketModal.svelte @@ -36,7 +36,8 @@ markSelfChange, applyTicket, attachFile, - attachPath + attachPath, + makeCover } from '$lib/stores/board'; import { formatDate, @@ -79,6 +80,18 @@ }); let shownAt = $derived(Math.max(0, images.findIndex((a) => a.path === shownPath))); let shown = $derived(images[shownAt]); + // The image in view becomes the cover; it stays in view (now as number one). + let makingCover = $state(false); + async function makeShownCover() { + if (!ticket || !shown || shownAt === 0 || makingCover) return; + makingCover = true; + shownPath = shown.path; + try { + await makeCover(ticket.id, shown.path); + } finally { + makingCover = false; + } + } function stepImage(by: -1 | 1) { if (images.length < 2) return; shownPath = images[(shownAt + by + images.length) % images.length].path; @@ -374,6 +387,13 @@ Cover + {:else if !readOnly} + {/if} {/if} @@ -786,6 +806,18 @@ font-family: var(--wp-font-mono); line-height: 16px; } + .cover-tag.make { + border: 1px solid color-mix(in srgb, var(--wp-accent) 55%, transparent); + cursor: pointer; + } + .cover-tag.make:hover:not(:disabled) { + background: var(--wp-elevated); + border-color: var(--wp-accent); + } + .cover-tag.make:disabled { + opacity: 0.6; + cursor: default; + } .close { position: absolute; top: 12px; diff --git a/apps/desktop/src/lib/stores/board.ts b/apps/desktop/src/lib/stores/board.ts index e36e471..672d72c 100644 --- a/apps/desktop/src/lib/stores/board.ts +++ b/apps/desktop/src/lib/stores/board.ts @@ -481,6 +481,18 @@ export async function attachPath(id: string, path: string): Promise { } } +/** Make one of a ticket's images its cover - the one its card shows - then + * refresh so the board and the ticket view follow. */ +export async function makeCover(id: string, path: string): Promise { + markSelfChange(id); + try { + await api.setCover(id, path, project()); + await loadBoard(); + } catch (e) { + boardError.set(e instanceof Error ? e.message : String(e)); + } +} + /** Load the trash (soft-deleted tickets) for the current project. */ export async function loadTrash(): Promise { try { diff --git a/apps/desktop/src/lib/types.ts b/apps/desktop/src/lib/types.ts index a28bff2..0dc53fb 100644 --- a/apps/desktop/src/lib/types.ts +++ b/apps/desktop/src/lib/types.ts @@ -14,7 +14,7 @@ export interface Activity { actor: string; /** * One of: created, moved, renamed, edited, priority, label-added, - * label-removed, assigned, unassigned, attached, detached. + * label-removed, assigned, unassigned, attached, detached, cover. */ kind: string; detail?: string; diff --git a/apps/desktop/src/lib/utils.ts b/apps/desktop/src/lib/utils.ts index 76cc71b..9ce5df8 100644 --- a/apps/desktop/src/lib/utils.ts +++ b/apps/desktop/src/lib/utils.ts @@ -123,6 +123,8 @@ export function activityPhrase( return `attached ${detail}`; case 'detached': return `removed attachment ${detail}`; + case 'cover': + return `made ${detail} the cover`; case 'checked': return `checked off ${detail.replace(/^\S+\s/, '')}`; case 'unchecked': diff --git a/apps/web/src/pages/docs/data.ts b/apps/web/src/pages/docs/data.ts index 74df044..9de760f 100644 --- a/apps/web/src/pages/docs/data.ts +++ b/apps/web/src/pages/docs/data.ts @@ -363,6 +363,11 @@ export const CLI_GROUPS: CliGroup[] = [ description: "List a ticket's attachments.", example: "wipe media list T-1", }, + { + command: "wipe media cover", + description: "Make an attachment the ticket's cover: the image its card shows on the board.", + example: "wipe media cover T-1 design.png", + }, ], }, { diff --git a/crates/wipe-cli/src/args.rs b/crates/wipe-cli/src/args.rs index 684b6dc..b9be944 100644 --- a/crates/wipe-cli/src/args.rs +++ b/crates/wipe-cli/src/args.rs @@ -1088,6 +1088,13 @@ pub enum MediaCmd { /// Attachment file name. name: String, }, + /// Make an attachment the ticket's cover: the image its card shows on the board. + Cover { + /// Ticket ID. + ticket: String, + /// Attachment file name (or its path, when two share a name). + name: String, + }, } /// `wipe forum ...` diff --git a/crates/wipe-cli/src/commands.rs b/crates/wipe-cli/src/commands.rs index c39bf65..bec35ed 100644 --- a/crates/wipe-cli/src/commands.rs +++ b/crates/wipe-cli/src/commands.rs @@ -1785,6 +1785,20 @@ pub fn media(out: &Out, cmd: MediaCmd) -> Result<()> { json!({ "ok": true, "ticket": ticket }), ); } + MediaCmd::Cover { ticket, name } => { + let t = s.load_ticket(&ticket)?; + let path = t + .attachments + .iter() + .find(|a| a.name == name || a.path == name) + .map(|a| a.path.clone()) + .ok_or_else(|| anyhow!("no attachment `{name}` on {ticket}"))?; + ops::set_cover(&s, &ticket, &path, &identity::resolve(None)?, Utc::now())?; + out.ok( + format!("{name} is now the cover of {ticket}"), + json!({ "ok": true, "ticket": ticket }), + ); + } } Ok(()) } diff --git a/crates/wipe-cli/src/ids.rs b/crates/wipe-cli/src/ids.rs index 385b811..be626b9 100644 --- a/crates/wipe-cli/src/ids.rs +++ b/crates/wipe-cli/src/ids.rs @@ -77,7 +77,8 @@ pub fn canonicalize(cmd: &mut Command) { Command::Media( MediaCmd::Add { ticket, .. } | MediaCmd::List { ticket } - | MediaCmd::Remove { ticket, .. }, + | MediaCmd::Remove { ticket, .. } + | MediaCmd::Cover { ticket, .. }, ) => fix(s, ticket), Command::Commit(a) => { if let Some(t) = &mut a.target { diff --git a/crates/wipe-core/src/model.rs b/crates/wipe-core/src/model.rs index 300ba32..358c0fe 100644 --- a/crates/wipe-core/src/model.rs +++ b/crates/wipe-core/src/model.rs @@ -472,7 +472,7 @@ pub struct Activity { pub actor: String, /// Event kind: one of `created`, `moved`, `renamed`, `edited`, `priority`, /// `label-added`, `label-removed`, `assigned`, `unassigned`, `attached`, - /// `detached`. + /// `detached`, `cover`. pub kind: String, /// Event-specific detail (destination list, label, assignee, attachment /// name, priority value). Empty when the `kind` alone says everything. diff --git a/crates/wipe-core/src/ops.rs b/crates/wipe-core/src/ops.rs index a65f774..6bb22e5 100644 --- a/crates/wipe-core/src/ops.rs +++ b/crates/wipe-core/src/ops.rs @@ -1224,6 +1224,36 @@ pub fn remove_attachment( Ok(()) } +/// Make the attachment at `path` the ticket's cover: the image its card shows on +/// the board and its ticket view opens on. The cover is the first image among a +/// ticket's attachments, so this moves the attachment to the front of the list +/// and keeps the others in their order - no extra field in the ticket file. +/// Nothing changes (and nothing is logged) when it is already first. +pub fn set_cover( + store: &Store, + ticket_id: &str, + path: &str, + actor: &str, + now: DateTime, +) -> Result<()> { + let mut ticket = store.load_ticket(ticket_id)?; + let at = ticket + .attachments + .iter() + .position(|a| a.path == path) + .ok_or_else(|| Error::msg(format!("no attachment `{path}` on {ticket_id}")))?; + if at == 0 { + return Ok(()); + } + let attachment = ticket.attachments.remove(at); + let name = attachment.name.clone(); + ticket.attachments.insert(0, attachment); + ticket.log_activity(actor, "cover", name, now); + ticket.updated = now; + store.save_ticket(&ticket)?; + Ok(()) +} + /// Sanitize a file name to a safe, stable form for on-disk storage. fn sanitize(name: &str) -> String { let base = std::path::Path::new(name) @@ -1500,6 +1530,38 @@ mod tests { assert!(b.path.starts_with(".wipe/media/") && root.join(&b.path).exists()); } + #[test] + fn set_cover_moves_an_attachment_to_the_front() { + let (_d, s) = project(); + let id = new_ticket(&s, "A", None, "t").id; + let add = |name: &str, bytes: &[u8]| { + add_attachment(&s, &id, name, bytes, "image/png", "t", now()).unwrap() + }; + add("a.png", b"AAA"); + add("b.png", b"BBB"); + let c = add("c.png", b"CCC"); + let names = || -> Vec { + let t = s.load_ticket(&id).unwrap(); + t.attachments.iter().map(|a| a.name.clone()).collect() + }; + let logged = || { + let t = s.load_ticket(&id).unwrap(); + t.activity.iter().filter(|e| e.kind == "cover").count() + }; + assert_eq!(names(), ["a.png", "b.png", "c.png"]); + + // The chosen one comes first; the others keep their order. + set_cover(&s, &id, &c.path, "t", now()).unwrap(); + assert_eq!(names(), ["c.png", "a.png", "b.png"]); + assert_eq!(logged(), 1); + // Already the cover: nothing moves, nothing is logged. + set_cover(&s, &id, &c.path, "t", now()).unwrap(); + assert_eq!(names(), ["c.png", "a.png", "b.png"]); + assert_eq!(logged(), 1); + // Not an attachment of this ticket. + assert!(set_cover(&s, &id, ".wipe/media/none.png", "t", now()).is_err()); + } + #[test] fn agents_belong_to_a_person_and_ids_stay_unique() { let (_d, s) = project(); diff --git a/crates/wipe-daemon/src/api.rs b/crates/wipe-daemon/src/api.rs index 944d2cc..6585554 100644 --- a/crates/wipe-daemon/src/api.rs +++ b/crates/wipe-daemon/src/api.rs @@ -1220,7 +1220,7 @@ pub async fn attach_path( Ok(Json(serde_json::to_value(att)?)) } -/// Body for detaching an attachment. +/// Body naming one of a ticket's attachments (to detach it, or make it the cover). #[derive(Debug, Deserialize)] pub struct DetachBody { project: Option, @@ -1243,6 +1243,21 @@ pub async fn delete_attachment( Ok(Json(json!({ "ok": true }))) } +/// `POST /api/tickets/{id}/attachments/cover` - make the attachment at a +/// repo-relative path the ticket's cover (it moves to the front of the list). +pub async fn set_cover( + State(state): State, + Path(id): Path, + Query(pq): Query, + Json(b): Json, +) -> ApiResult { + let store = store_for(&state, pq.project.or(b.project))?; + let actor = resolve_actor(&state, &store, b.actor); + ops::set_cover(&store, &id, &b.path, &actor, Utc::now())?; + notify(&state); + Ok(Json(json!({ "ok": true }))) +} + /// `GET /api/media/{*path}` - serve an attachment for preview/download. pub async fn serve_media( State(state): State, diff --git a/crates/wipe-daemon/src/lib.rs b/crates/wipe-daemon/src/lib.rs index b374bfe..e3e88ff 100644 --- a/crates/wipe-daemon/src/lib.rs +++ b/crates/wipe-daemon/src/lib.rs @@ -137,6 +137,7 @@ fn router(state: AppState) -> Router { post(api::upload_attachment).delete(api::delete_attachment), ) .route("/api/tickets/{id}/attachments/path", post(api::attach_path)) + .route("/api/tickets/{id}/attachments/cover", post(api::set_cover)) .route("/api/media/{*path}", get(api::serve_media)) .route("/api/local-file", get(api::local_file)) .route("/api/forum", get(api::forum_list).post(api::forum_create))