mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(app): enlarge image attachment thumbnails to 3:2 (#64215)
This commit is contained in:
committed by
GitHub
Unverified
parent
fd95bf0d21
commit
26f2522e60
@@ -862,7 +862,7 @@ function ComposerAttachments(props: {
|
||||
const missing = () => url.state === "errored" || (url.state === "ready" && !url())
|
||||
|
||||
return (
|
||||
<div class="relative group shrink-0">
|
||||
<div class="relative group shrink-0 self-start">
|
||||
<Tooltip
|
||||
value={attachment.type === "path" ? attachment.path : attachment.filename}
|
||||
placement="top"
|
||||
@@ -876,12 +876,12 @@ function ComposerAttachments(props: {
|
||||
</AttachmentCard>
|
||||
}
|
||||
>
|
||||
<Show when={src()} fallback={<div class="w-[58px] h-[46px]" />}>
|
||||
<Show when={src()} fallback={<div class="w-[78px] h-[52px]" />}>
|
||||
{(value) => (
|
||||
<img
|
||||
src={value()}
|
||||
alt={attachment.filename}
|
||||
class="w-[58px] h-[46px] rounded-[6px] object-cover"
|
||||
class="w-[78px] h-[52px] rounded-[6px] object-cover"
|
||||
onClick={(event) => props.onAttachmentClick?.(attachment, event.currentTarget)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -547,8 +547,12 @@ story("a stored image that fails to load shows a failed tile that retries", asyn
|
||||
await expect(failed.getByRole("img", { name: "Unable to load image." })).toBeVisible()
|
||||
await expect(failed).not.toHaveAttribute("data-placeholder")
|
||||
|
||||
const tileSize = { width: 132, height: 88 }
|
||||
expect(await failed.boundingBox()).toMatchObject(tileSize)
|
||||
|
||||
await failed.click()
|
||||
await expect(timeline.getByAltText("flaky.svg")).toBeVisible()
|
||||
expect(await failed.boundingBox()).toMatchObject(tileSize)
|
||||
})
|
||||
|
||||
story("shows note selectors and keeps annotation subtitles with or without comments", async ({ mount, page }) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import type { PromptFileAttachment } from "@opencode/client/promise"
|
||||
import { attached, imageAttachmentPlaceholderStyle, MIN_IMAGE_PLACEHOLDER_PX, typeLabel } from "./message-file"
|
||||
import { attached, typeLabel } from "./message-file"
|
||||
|
||||
function file(source: PromptFileAttachment["source"], mention = false): PromptFileAttachment {
|
||||
const item: PromptFileAttachment = {
|
||||
@@ -32,19 +32,4 @@ describe("message-file", () => {
|
||||
expect(typeLabel(".gitignore", "text/plain", "File")).toBe("File")
|
||||
expect(typeLabel("/repo/.env", "text/plain", "File")).toBe("File")
|
||||
})
|
||||
|
||||
test("keeps a sane minimum placeholder size on 401/error when width and height are missing", () => {
|
||||
expect(imageAttachmentPlaceholderStyle({ loaded: false })).toEqual({
|
||||
"min-width": `${MIN_IMAGE_PLACEHOLDER_PX}px`,
|
||||
"min-height": `${MIN_IMAGE_PLACEHOLDER_PX}px`,
|
||||
})
|
||||
expect(imageAttachmentPlaceholderStyle({ width: 800, height: 600, loaded: false })).toEqual({
|
||||
"aspect-ratio": "800 / 600",
|
||||
"min-width": `${MIN_IMAGE_PLACEHOLDER_PX}px`,
|
||||
"min-height": `${MIN_IMAGE_PLACEHOLDER_PX}px`,
|
||||
})
|
||||
expect(imageAttachmentPlaceholderStyle({ width: 800, height: 600, loaded: true })).toEqual({
|
||||
"aspect-ratio": "800 / 600",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,31 +1,6 @@
|
||||
import { getFilename } from "@opencode/util/path"
|
||||
import type { PromptAttachment } from "@opencode/client/promise"
|
||||
|
||||
export const MIN_IMAGE_PLACEHOLDER_PX = 96
|
||||
|
||||
export function imageAttachmentPlaceholderStyle(input: {
|
||||
readonly width?: number
|
||||
readonly height?: number
|
||||
readonly loaded: boolean
|
||||
}) {
|
||||
if (input.width && input.height && input.loaded) return { "aspect-ratio": `${input.width} / ${input.height}` }
|
||||
|
||||
if (input.width && input.height) {
|
||||
return {
|
||||
"aspect-ratio": `${input.width} / ${input.height}`,
|
||||
"min-width": `${Math.min(input.width, MIN_IMAGE_PLACEHOLDER_PX)}px`,
|
||||
"min-height": `${Math.min(input.height, MIN_IMAGE_PLACEHOLDER_PX)}px`,
|
||||
}
|
||||
}
|
||||
|
||||
return input.loaded
|
||||
? undefined
|
||||
: {
|
||||
"min-width": `${MIN_IMAGE_PLACEHOLDER_PX}px`,
|
||||
"min-height": `${MIN_IMAGE_PLACEHOLDER_PX}px`,
|
||||
}
|
||||
}
|
||||
|
||||
export function attached(file: PromptAttachment) {
|
||||
if (file.mention) return false
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@
|
||||
|
||||
&[data-type="image"] {
|
||||
position: relative;
|
||||
width: 58px;
|
||||
height: 46px;
|
||||
height: 88px;
|
||||
aspect-ratio: 3 / 2;
|
||||
border: none;
|
||||
|
||||
/* inset box-shadows do not paint over <img> content, so the hairline is an overlay */
|
||||
|
||||
@@ -60,7 +60,7 @@ import type {
|
||||
import type { SessionUserActions, SessionUserAttachmentReference, SessionUserComment } from "../actions"
|
||||
import { agentLabel } from "./agent-label"
|
||||
import { isInterruptedError } from "../timeline/turn-phase-machine"
|
||||
import { attached, imageAttachmentPlaceholderStyle, typeLabel } from "../components/message-file"
|
||||
import { attached, typeLabel } from "../components/message-file"
|
||||
import {
|
||||
DISPOSED_ATTACHMENT_MEDIA_EVENT,
|
||||
INITIAL_ATTACHMENT_MEDIA_STATE,
|
||||
@@ -578,13 +578,6 @@ export function CurrentUserMessageDisplay(props: {
|
||||
return "height" in current ? current.height : undefined
|
||||
}
|
||||
|
||||
const placeholderStyle = () =>
|
||||
imageAttachmentPlaceholderStyle({
|
||||
width: width(),
|
||||
height: height(),
|
||||
loaded: mediaView().status === "ready",
|
||||
})
|
||||
|
||||
return (
|
||||
<Show
|
||||
when={!image()}
|
||||
@@ -596,7 +589,6 @@ export function CurrentUserMessageDisplay(props: {
|
||||
data-placeholder={mediaView().placeholder ? "true" : undefined}
|
||||
data-width={width()}
|
||||
data-height={height()}
|
||||
style={placeholderStyle()}
|
||||
onClick={(event) => {
|
||||
const src = mediaView().src
|
||||
const origin = event.currentTarget
|
||||
|
||||
Reference in New Issue
Block a user