Skip to content
Open
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
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
108 changes: 101 additions & 7 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 Down Expand Up @@ -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<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]);
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 +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.
Expand All @@ -322,9 +358,25 @@
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
>
{/if}
</div>
{/if}
</div>
{/if}

Expand Down Expand Up @@ -680,6 +732,7 @@
box-shadow: var(--wp-shadow-lift);
}
.cover {
position: relative;
width: 100%;
max-height: 260px;
overflow: hidden;
Expand All @@ -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;
Expand Down