Files
bubble/src/renderer/src/components/Lightbox.tsx
T
trav 8c84feaa91 v0.2.0: bubble for Android 0.2.0 — chat search, swipe for unread, faster chat opening
Desktop:
- Search lists chats whose own name matches first, so a named group
  isn't pushed out of the top 8 by chats that merely include a member.

Android (Rabbit R1) app, 0.2.0:
- Pull the chat list past its top for a search box (name, person,
  number, then group members; archived chats too; Back clears it).
- Swipe right to left marks a chat unread / read over a magenta band;
  left to right still archives (SwipeActions replaces SwipeArchive).
- Google Voice chats don't offer voice notes in the paperclip bubble.
- Chats open with their newest 60 messages, then the full history;
  marking read (and the Google Voice network call) waits until they're
  on screen. Cached pictures show at once, and one slow download no
  longer blocks the other images. Fixed a contacts reload race.
- Sandbox data gains filler chats, a named group and a 4,000-message chat.

Also: the Android app, Google Voice support, media, export, emoji and
the other work since the first commit, and a CLAUDE.md carrying the
privacy rule.
2026-11-06 02:19:56 -08:00

60 lines
2.3 KiB
TypeScript

import { useEffect, useState } from 'react'
import { ContextMenu, type MenuItem } from './ContextMenu'
import { CloseIcon, DownloadIcon } from './Icons'
import { mediaSrc } from './MessageBubble'
// Copy an attachment to the clipboard as a PNG (so GIF/WebP/HEIC work too).
async function copyImage(id: number, index: number): Promise<void> {
const { mime, data } = await window.api.readMedia(id, index)
const bitmap = await createImageBitmap(new Blob([data], { type: mime }))
try {
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height)
canvas.getContext('2d')!.drawImage(bitmap, 0, 0)
const png = await canvas.convertToBlob({ type: 'image/png' })
await window.api.copyImage(new Uint8Array(await png.arrayBuffer()))
} finally {
bitmap.close()
}
}
// Right-click on an image, in the chat or the lightbox.
export const imageMenuItems = (id: number, index: number): MenuItem[] => [
{ label: 'Copy image', onSelect: () => void copyImage(id, index).catch(() => undefined) },
{ label: 'Save image…', onSelect: () => void window.api.saveMedia(id, index).catch(() => undefined) }
]
export function Lightbox({ id, index, onClose }: { id: number; index: number; onClose: () => void }) {
const [menu, setMenu] = useState<{ x: number; y: number }>()
useEffect(() => {
const onKey = (e: KeyboardEvent): void => {
if (e.key === 'Escape' && !menu) onClose()
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose, menu])
return (
<div className="lightbox" onMouseDown={(e) => e.target === e.currentTarget && onClose()}>
<div className="lightbox-bar">
<button className="icon-btn" title="Save…" onClick={() => void window.api.saveMedia(id, index)}>
<DownloadIcon />
</button>
<button className="icon-btn" title="Close (Esc)" onClick={onClose}>
<CloseIcon size={20} />
</button>
</div>
<img
src={mediaSrc(id, index)}
alt=""
draggable={false}
onContextMenu={(e) => {
e.preventDefault()
setMenu({ x: e.clientX, y: e.clientY })
}}
/>
{menu && <ContextMenu x={menu.x} y={menu.y} items={imageMenuItems(id, index)} onClose={() => setMenu(undefined)} />}
</div>
)
}