Skip to content
Merged
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: 7 additions & 1 deletion web/src/BoardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ItemDrawer } from './ItemDrawer'
import { KanbanView } from './KanbanView'
import { ListView } from './ListView'
import { NewItemModal } from './NewItemModal'
import { celebrateTicket, ticketElement } from './celebrate'
import { AvatarStack } from './people'
import { boardRoute, href, navigate, type Filters, type Route } from './router'
import { menuPosition, TicketMenu, type OpenTicketMenu, type TicketAction, type TicketMenuPosition } from './TicketMenu'
Expand Down Expand Up @@ -118,6 +119,8 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
}
if (!canEdit || !board || actionBusy) return
setActionBusy(true)
// A List view that hides closed tickets drops the row before we can celebrate it.
const wasAt = ticketElement(item.key)?.getBoundingClientRect()
try {
const saved = await write(undefined, () => action === 'assign'
? api.update(route.context, item.key, { assignee: board.me_assignee, note: 'assigned to myself from the card menu' })
Expand All @@ -131,7 +134,10 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
timeout: 8000,
actionProps: { children: 'Undo', onPress: () => { void write(undefined, () => api.move(route.context, item.key, { status: item.status, note: 'undid deletion from the card menu' })) } },
})
} else toast.success(action === 'assign' ? `Assigned ${item.key} to you` : `Marked ${item.key} as done`)
} else {
toast.success(action === 'assign' ? `Assigned ${item.key} to you` : action === 'restore' ? `Restored ${item.key}` : `Marked ${item.key} as done`)
if (action === 'done') celebrateTicket(item.key, wasAt)
}
} finally { setActionBusy(false) }
}

Expand Down
19 changes: 16 additions & 3 deletions web/src/ItemDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button, Drawer, Input, Label, Spinner, TextArea, TextField } from '@her
import { useCallback, useEffect, useRef, useState } from 'react'
import { api, PRIORITIES, STATUS_LABEL, UNASSIGNED, WORK_ORDER, type Board, type HistoryEntry, type Item, type Priority, type Status } from './api'
import { ago, ClaimBadge, StatusChip } from './bits'
import { celebrate } from './celebrate'
import { AssignToMe, ChoiceSelect, LabelPicker } from './fields'
import { renderMarkdown } from './md'
import { TicketThread } from './TicketThread'
Expand Down Expand Up @@ -47,16 +48,26 @@ export function ItemDrawer({ context, itemKey, board, canEdit, onClose, onChange
try {
await send()
await Promise.all([refresh(), onChanged()])
return true
} catch (err) {
onError(err)
await refresh()
return false
} finally {
setSaving(false)
}
}

const update = (fields: Parameters<typeof api.update>[2]) => save(() => api.update(context, item!.key, fields))
const moveTo = (status: Status) => status !== item?.status && save(() => api.move(context, item!.key, { status }))
const update = async (fields: Parameters<typeof api.update>[2]) => { await save(() => api.update(context, item!.key, fields)) }
const statusField = useRef<HTMLDivElement>(null)
const shownKey = useRef(itemKey)
shownKey.current = itemKey
const moveTo = async (status: Status) => {
if (!item || status === item.status) return
const { key, state } = item
const saved = await save(() => api.move(context, key, { status }))
if (saved && status === 'done' && state === 'open' && shownKey.current === key) celebrate(statusField.current)
}

return (
<Drawer>
Expand Down Expand Up @@ -93,7 +104,9 @@ export function ItemDrawer({ context, itemKey, board, canEdit, onClose, onChange
<div className="grid grid-cols-2 gap-3">
{canEdit ? (
<>
<ChoiceSelect label="Status" value={item.status} options={WORK_ORDER} render={(s) => STATUS_LABEL[s]} onChange={(s) => void moveTo(s)} isDisabled={saving} />
<div ref={statusField} className="rounded-xl">
<ChoiceSelect label="Status" value={item.status} options={WORK_ORDER} render={(s) => STATUS_LABEL[s]} onChange={(s) => void moveTo(s)} isDisabled={saving} />
</div>
<ChoiceSelect label="Priority" value={item.priority} options={PRIORITIES} render={(p) => p} onChange={(p: Priority) => void update({ priority: p })} isDisabled={saving} />
<div className="flex items-end gap-2">
<ChoiceSelect
Expand Down
7 changes: 5 additions & 2 deletions web/src/KanbanView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DragDropProvider, DragOverlay, useDraggable, useDroppable } from '@dnd-
import { useEffect, useMemo, useRef, useState } from 'react'
import { BOARD_COLUMNS, STATUS_LABEL, type Item, type Status } from './api'
import { ClaimBadge, ExternalBadge, Labels, PriorityChip } from './bits'
import { celebrateTicket } from './celebrate'
import { PersonAvatar } from './people'
import { isMenuKey, type OpenTicketMenu } from './TicketMenu'

Expand All @@ -17,7 +18,7 @@ interface Props {
onMenu: OpenTicketMenu
onOpen: (key: string) => void
/** `order` = the target column's keys after the drop; the neighbour anchors the rank. */
onMove: (key: string, status: Status, order: string[], neighbour: { above?: string; below?: string }) => void
onMove: (key: string, status: Status, order: string[], neighbour: { above?: string; below?: string }) => Promise<Item | undefined>
}

const ALL_COLUMNS: Status[] = [...BOARD_COLUMNS, 'archived']
Expand Down Expand Up @@ -72,7 +73,8 @@ export function KanbanView({ items, canEdit, showArchived, onOpen, onMove, onMen
if (from === to && columns[from].join() === order.join()) return
setColumns({ ...columns, [from]: columns[from].filter((k) => k !== key), [to]: order })
const neighbour = order[index + 1] ? { above: order[index + 1] } : order[index - 1] ? { below: order[index - 1] } : {}
onMove(key, to, order, neighbour)
const saving = onMove(key, to, order, neighbour)
if (to === 'done' && from !== 'done' && from !== 'archived') void saving.then((saved) => saved && celebrateTicket(key))
}}
>
<div className="grid auto-cols-[minmax(260px,1fr)] grid-flow-col gap-3 overflow-x-auto pb-4">
Expand Down Expand Up @@ -118,6 +120,7 @@ function Card({ item, status, canEdit, isActive, onOpen, onMenu }: { onMenu: Ope
{drop.isDropTarget && !isActive && <div className="pointer-events-none absolute -top-[5px] right-1 left-1 h-[3px] rounded-full bg-accent" />}
<div
ref={drag.ref}
data-ticket-key={item.key}
role="button"
tabIndex={0}
aria-haspopup="menu"
Expand Down
78 changes: 78 additions & 0 deletions web/src/celebrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* A small, quiet "done" moment: the ticket glows once and a handful of
* confetti flecks drift up from it. Plain DOM + Web Animations, no library.
*/

const COLORS = ['var(--accent)', 'oklch(0.72 0.14 150)', 'oklch(0.8 0.12 85)', 'oklch(0.7 0.1 250)']
const PIECES = 14

const reducedMotion = () => window.matchMedia?.('(prefers-reduced-motion: reduce)').matches

/** Pass the element to glow it too, or just where it was if it has already left the page. */
export function celebrate(target: Element | DOMRect | null | undefined) {
if (!target || reducedMotion() || typeof document.body.animate !== 'function') return
const rect = target instanceof Element ? target.getBoundingClientRect() : target
if (rect.width === 0 && rect.height === 0) return

if (target instanceof Element)
target.animate(
[
{ boxShadow: '0 0 0 0 color-mix(in oklch, var(--success, oklch(0.72 0.14 150)) 0%, transparent)', scale: '1' },
{ boxShadow: '0 0 0 4px color-mix(in oklch, var(--success, oklch(0.72 0.14 150)) 35%, transparent)', scale: '1.015', offset: 0.35 },
{ boxShadow: '0 0 0 10px color-mix(in oklch, var(--success, oklch(0.72 0.14 150)) 0%, transparent)', scale: '1' },
],
{ duration: 700, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' },
)

const layer = document.createElement('div')
layer.setAttribute('aria-hidden', 'true')
Object.assign(layer.style, { position: 'fixed', inset: '0', pointerEvents: 'none', zIndex: '2147483647', overflow: 'hidden' })
document.body.appendChild(layer)

const originX = rect.left + rect.width / 2
const originY = rect.top + Math.min(rect.height / 2, 24)
let remaining = PIECES

for (let i = 0; i < PIECES; i++) {
const piece = document.createElement('span')
const w = 4 + Math.random() * 3
const round = Math.random() < 0.4
Object.assign(piece.style, {
position: 'absolute',
left: `${originX}px`,
top: `${originY}px`,
width: `${w}px`,
height: `${round ? w : w * 1.8}px`,
borderRadius: round ? '999px' : '1.5px',
background: COLORS[i % COLORS.length],
})
layer.appendChild(piece)

const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI * 0.9
const dist = 40 + Math.random() * 50
const dx = Math.cos(angle) * dist + (Math.random() - 0.5) * rect.width * 0.3
const dy = Math.sin(angle) * dist
const spin = (Math.random() - 0.5) * 540

piece
.animate(
[
{ transform: 'translate(-50%, -50%) scale(0.6) rotate(0deg)', opacity: 0 },
{ transform: `translate(calc(-50% + ${dx * 0.6}px), calc(-50% + ${dy * 0.6}px)) scale(1) rotate(${spin * 0.5}deg)`, opacity: 1, offset: 0.3 },
{ transform: `translate(calc(-50% + ${dx}px), calc(-50% + ${dy + 36}px)) scale(0.9) rotate(${spin}deg)`, opacity: 0 },
],
{ duration: 900 + Math.random() * 400, delay: Math.random() * 60, easing: 'cubic-bezier(0.2, 0.7, 0.3, 1)', fill: 'forwards' },
)
.finished.catch(() => {})
.finally(() => {
if (--remaining === 0) layer.remove()
})
}
}

export const ticketElement = (key: string) => document.querySelector(`[data-ticket-key="${CSS.escape(key)}"]`)

/** Waits two frames so the card has rendered in its new column; `fallback` covers a row that is no longer shown. */
export function celebrateTicket(key: string, fallback?: DOMRect) {
requestAnimationFrame(() => requestAnimationFrame(() => celebrate(ticketElement(key) ?? fallback)))
}
Loading