From 042123db44a08b3882c333a02164e97979bd04ff Mon Sep 17 00:00:00 2001 From: Filip <34747899+neriousy@users.noreply.github.com> Date: Fri, 6 Nov 2026 21:32:51 +0000 Subject: [PATCH] feat(app): load a session's older media as the panel scrolls --- packages/gui-plugins/src/media/i18n/en.ts | 6 +- packages/gui-plugins/src/media/media.css | 24 ++++++-- packages/gui-plugins/src/media/panel.tsx | 71 +++++++++++++++++------ 3 files changed, 76 insertions(+), 25 deletions(-) diff --git a/packages/gui-plugins/src/media/i18n/en.ts b/packages/gui-plugins/src/media/i18n/en.ts index 351976ccf9b..536a86e5221 100644 --- a/packages/gui-plugins/src/media/i18n/en.ts +++ b/packages/gui-plugins/src/media/i18n/en.ts @@ -35,6 +35,8 @@ export default { "media.image": "Image", "day.today": "Today", "day.yesterday": "Yesterday", - "load.more": "Load earlier messages", - "load.loading": "Loading…", + "count.more": "{{count}}+", + "history.loading": "Looking through earlier messages…", + "history.failed": "Couldn't load earlier messages", + "history.retry": "Try again", } diff --git a/packages/gui-plugins/src/media/media.css b/packages/gui-plugins/src/media/media.css index b21cc845964..fbc38c8392e 100644 --- a/packages/gui-plugins/src/media/media.css +++ b/packages/gui-plugins/src/media/media.css @@ -318,16 +318,28 @@ text-wrap: balance; } - [data-slot="media-panel-more"] { - display: block; - margin: 12px auto 4px; - padding: 4px 10px; + [data-slot="media-panel-end"] { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + min-height: 1px; + padding-block: 16px 8px; + color: var(--v2-text-text-faint); + font-size: 12px; + + &:empty { + padding: 0; + } + } + + [data-slot="media-panel-retry"] { + padding: 2px 8px; border-radius: 6px; color: var(--v2-text-text-muted); - font-size: 12px; cursor: default; - &:not(:disabled):hover { + &:hover { background-color: var(--v2-overlay-simple-overlay-hover); color: var(--v2-text-text-base); } diff --git a/packages/gui-plugins/src/media/panel.tsx b/packages/gui-plugins/src/media/panel.tsx index 6399b425c3e..61ec1daad60 100644 --- a/packages/gui-plugins/src/media/panel.tsx +++ b/packages/gui-plugins/src/media/panel.tsx @@ -2,11 +2,12 @@ import { createMemo, createSignal, For, mapArray, Match, onCleanup, Show, Switch import { useDialog } from "@opencode/ui/context/dialog" import { FileIcon } from "@opencode/ui/file-icon" import { Icon } from "@opencode/ui/icon" +import { Loader } from "@opencode/ui/loader" import { ImagePreview } from "@opencode/ui/image-preview" import { SegmentedControl, SegmentedControlItem } from "@opencode/ui/segmented-control" import { Select } from "@opencode/ui/select" import { SiteIcon } from "@opencode/session-ui/sources/site-icon" -import { createLatest, usePlugin, type MountedSession } from "@opencode/plugin/gui" +import { createKeyed, createLatest, usePlugin, type MountedSession } from "@opencode/plugin/gui" import { Browser } from "@opencode/plugin/gui/browser" import type Media from "./index" import { combineMedia, messageMedia, type FileItem, type LinkItem, type MediaItem, type Sender } from "./collect" @@ -51,6 +52,40 @@ export default function MediaPanel(props: { session: MountedSession }) { return ctx.t(`empty.${kind()}`) } + // The app keeps only a session's recent messages, so older items arrive as the panel pages in history. Paging runs + // whenever the end of the list is on screen: as the user scrolls down, and again after each page while a short or + // empty list still leaves the end visible. Every tab reads the same messages, so a page fills all three. + const [end, setEnd] = createSignal(false) + const [failed, setFailed] = createSignal(false) + // Counts settled page requests. A request can add nothing, for example when it joins the timeline's own load, so + // each settle is a new chance to page while the end is still on screen. + const [settled, setSettled] = createSignal(0) + const more = () => messages().more(props.session.id) + const loading = () => messages().loading(props.session.id) + + const page = () => { + setFailed(false) + void messages() + .loadMore(props.session.id) + .then( + () => setSettled((count) => count + 1), + () => setFailed(true), + ) + } + + // Syncs with the server: one page at a time while the end is visible, so it stops once a page pushes the end off + // screen, the history ends, or a load fails. + createKeyed(() => end() && more() && !loading() && !failed() && `${props.session.id}:${settled()}`, page) + + const observeEnd = (element: HTMLElement) => { + const observer = new IntersectionObserver((entries) => setEnd(entries.some((entry) => entry.isIntersecting)), { + rootMargin: "300px", + }) + + observer.observe(element) + onCleanup(() => observer.disconnect()) + } + const openURL = (url: string) => { const pane = ctx.use(Browser)() @@ -101,7 +136,9 @@ export default function MediaPanel(props: { session: MountedSession }) { {ctx.t(`kind.${value}`)} - {count(value)} + + {more() ? ctx.t("count.more", { count: count(value) }) : count(value)} + )} @@ -142,24 +179,24 @@ export default function MediaPanel(props: { session: MountedSession }) { {(item) => } - + {empty()} - - - void messages() - .loadMore(props.session.id) - .catch(() => {}) - } - > - {ctx.t(messages().loading(props.session.id) ? "load.loading" : "load.more")} - - + + + + {ctx.t("history.failed")} + + {ctx.t("history.retry")} + + + + + {ctx.t("history.loading")} + + + )