Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/desktop/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })}`,
Expand Down
32 changes: 28 additions & 4 deletions apps/desktop/src/lib/components/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,10 +85,12 @@
}, step);
return () => clearInterval(iv);
});
// First image attachment becomes a compact card cover, like Trello.
let cover = $derived<Attachment | undefined>(
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<Attachment[]>(
ticket.attachments.filter((a) => mediaKind(a.mime, a.name) === 'image')
);
let cover = $derived<Attachment | undefined>(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 <email>` — so fall back
// to matching the address inside the angle brackets (else the avatar/name/kind
Expand Down Expand Up @@ -154,6 +156,11 @@
alt={cover.name}
loading="lazy"
/>
{#if images.length > 1}
<span class="cover-count" title="{images.length} images - open the ticket to see them all"
><Images size={12} /> {images.length}</span
>
{/if}
</div>
{/if}

Expand Down Expand Up @@ -344,6 +351,7 @@
}
}
.cover {
position: relative;
margin: -12px -12px 0;
max-height: 120px;
overflow: hidden;
Expand All @@ -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;
Expand Down
142 changes: 134 additions & 8 deletions apps/desktop/src/lib/components/TicketModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -26,7 +36,8 @@
markSelfChange,
applyTicket,
attachFile,
attachPath
attachPath,
makeCover
} from '$lib/stores/board';
import {
formatDate,
Expand Down Expand Up @@ -54,10 +65,37 @@
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<Attachment | undefined>(
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<Attachment[]>(
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<string | null>(null);
$effect(() => {
void ticketId;
shownPath = null;
});
let shownAt = $derived(Math.max(0, images.findIndex((a) => a.path === shownPath)));
let shown = $derived<Attachment | undefined>(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;
}

// Comments and activity events, interleaved and sorted newest-first - the
// Trello-style timeline in the right pane.
Expand Down Expand Up @@ -302,6 +340,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.
Expand All @@ -322,9 +371,32 @@
transition:scale={{ duration: dur, start: 0.97, opacity: 0 }}
>
<!-- cover -->
{#if cover}
{#if shown}
<div class="cover">
<img src={mediaUrl(cover.path, proj())} alt={cover.name} />
<img src={mediaUrl(shown.path, proj())} alt={shown.name} />
{#if images.length > 1}
<button class="cover-nav prev" aria-label="Previous image" onclick={() => stepImage(-1)}
><ChevronLeft size={20} /></button
>
<button class="cover-nav next" aria-label="Next image" onclick={() => stepImage(1)}
><ChevronRight size={20} /></button
>
<div class="cover-bar">
<span class="cover-tag" aria-live="polite">{shownAt + 1} / {images.length}</span>
{#if shownAt === 0}
<span class="cover-tag" title="The image this ticket's card shows on the board"
>Cover</span
>
{:else if !readOnly}
<button
class="cover-tag make"
title="Show this image on the ticket's card on the board"
disabled={makingCover}
onclick={makeShownCover}>Make cover</button
>
{/if}
</div>
{/if}
</div>
{/if}

Expand Down Expand Up @@ -680,6 +752,7 @@
box-shadow: var(--wp-shadow-lift);
}
.cover {
position: relative;
width: 100%;
max-height: 260px;
overflow: hidden;
Expand All @@ -692,6 +765,59 @@
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;
}
.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;
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/lib/stores/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,18 @@ export async function attachPath(id: string, path: string): Promise<void> {
}
}

/** 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<void> {
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<void> {
try {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/pages/docs/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
{
Expand Down
7 changes: 7 additions & 0 deletions crates/wipe-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...`
Expand Down
14 changes: 14 additions & 0 deletions crates/wipe-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
3 changes: 2 additions & 1 deletion crates/wipe-cli/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/wipe-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading