Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b89ba0651b | ||
|
|
406d486e06 | ||
|
|
100a978bc5 | ||
|
|
926042276d | ||
|
|
5a5afe7f8f | ||
|
|
d1e85c4e8f |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/desktop",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist-electron/main.cjs",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "t3",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/web",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -147,7 +147,10 @@ import { ExpandedImageDialog } from "./chat/ExpandedImageDialog";
|
||||
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
|
||||
import { MessagesTimeline } from "./chat/MessagesTimeline";
|
||||
import { ChatHeader } from "./chat/ChatHeader";
|
||||
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
|
||||
import {
|
||||
getExpandedImagePreviewIdentityKey,
|
||||
type ExpandedImagePreview,
|
||||
} from "./chat/ExpandedImagePreview";
|
||||
import { NoActiveThreadState } from "./NoActiveThreadState";
|
||||
import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
|
||||
import { ProviderStatusBanner } from "./chat/ProviderStatusBanner";
|
||||
@@ -3773,7 +3776,11 @@ export default function ChatView(props: ChatViewProps) {
|
||||
) : null}
|
||||
|
||||
{expandedImage && (
|
||||
<ExpandedImageDialog preview={expandedImage} onClose={closeExpandedImage} />
|
||||
<ExpandedImageDialog
|
||||
key={getExpandedImagePreviewIdentityKey(expandedImage)}
|
||||
preview={expandedImage}
|
||||
onClose={closeExpandedImage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { memo, useCallback, useEffect, useState } from "react";
|
||||
import { memo, useCallback, useEffect, useEffectEvent, useState } from "react";
|
||||
import { ChevronLeftIcon, ChevronRightIcon, XIcon } from "lucide-react";
|
||||
import { Button } from "../ui/button";
|
||||
import type { ExpandedImagePreview } from "./ExpandedImagePreview";
|
||||
@@ -8,52 +8,65 @@ interface ExpandedImageDialogProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview: initialPreview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [preview, setPreview] = useState(initialPreview);
|
||||
|
||||
// Sync when the parent hands us a new preview reference.
|
||||
useEffect(() => {
|
||||
setPreview(initialPreview);
|
||||
}, [initialPreview]);
|
||||
|
||||
const navigateImage = useCallback((direction: -1 | 1) => {
|
||||
setPreview((existing) => {
|
||||
if (existing.images.length <= 1) return existing;
|
||||
const nextIndex =
|
||||
(existing.index + direction + existing.images.length) % existing.images.length;
|
||||
if (nextIndex === existing.index) return existing;
|
||||
return { ...existing, index: nextIndex };
|
||||
});
|
||||
}, []);
|
||||
function useExpandedImageDialogKeyboardShortcuts(input: {
|
||||
readonly imageCount: number;
|
||||
readonly onClose: () => void;
|
||||
readonly onNavigate: (direction: -1 | 1) => void;
|
||||
}) {
|
||||
const close = useEffectEvent(input.onClose);
|
||||
const navigate = useEffectEvent(input.onNavigate);
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onClose();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (preview.images.length <= 1) return;
|
||||
if (input.imageCount <= 1) return;
|
||||
if (event.key === "ArrowLeft") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
navigateImage(-1);
|
||||
navigate(-1);
|
||||
return;
|
||||
}
|
||||
if (event.key !== "ArrowRight") return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
navigateImage(1);
|
||||
navigate(1);
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [navigateImage, onClose, preview.images.length]);
|
||||
}, [close, input.imageCount, navigate]);
|
||||
}
|
||||
|
||||
const item = preview.images[preview.index];
|
||||
export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
preview,
|
||||
onClose,
|
||||
}: ExpandedImageDialogProps) {
|
||||
const [navigationOffset, setNavigationOffset] = useState(0);
|
||||
const imageCount = preview.images.length;
|
||||
const activeIndex =
|
||||
imageCount > 0 ? (preview.index + navigationOffset + imageCount) % imageCount : preview.index;
|
||||
|
||||
const navigateImage = useCallback(
|
||||
(direction: -1 | 1) => {
|
||||
setNavigationOffset((offset) => {
|
||||
if (imageCount <= 1) return offset;
|
||||
return offset + direction;
|
||||
});
|
||||
},
|
||||
[imageCount],
|
||||
);
|
||||
|
||||
useExpandedImageDialogKeyboardShortcuts({
|
||||
imageCount,
|
||||
onClose,
|
||||
onNavigate: navigateImage,
|
||||
});
|
||||
|
||||
const item = preview.images[activeIndex];
|
||||
if (!item) return null;
|
||||
|
||||
return (
|
||||
@@ -69,7 +82,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
aria-label="Close image preview"
|
||||
onClick={onClose}
|
||||
/>
|
||||
{preview.images.length > 1 && (
|
||||
{imageCount > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
@@ -100,10 +113,10 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
|
||||
/>
|
||||
<p className="mt-2 max-w-[92vw] truncate text-center text-xs text-muted-foreground/80">
|
||||
{item.name}
|
||||
{preview.images.length > 1 ? ` (${preview.index + 1}/${preview.images.length})` : ""}
|
||||
{imageCount > 1 ? ` (${activeIndex + 1}/${imageCount})` : ""}
|
||||
</p>
|
||||
</div>
|
||||
{preview.images.length > 1 && (
|
||||
{imageCount > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
|
||||
@@ -8,6 +8,14 @@ export interface ExpandedImagePreview {
|
||||
index: number;
|
||||
}
|
||||
|
||||
export function getExpandedImagePreviewIdentityKey(preview: ExpandedImagePreview): string {
|
||||
const selectedImage = preview.images[preview.index];
|
||||
const selectedImageKey = selectedImage
|
||||
? `${selectedImage.name.length}:${selectedImage.name}:${selectedImage.src.length}:${selectedImage.src}`
|
||||
: "missing";
|
||||
return `${preview.images.length}:${preview.index}:${selectedImageKey}`;
|
||||
}
|
||||
|
||||
export function buildExpandedImagePreview(
|
||||
images: ReadonlyArray<{ id: string; name: string; previewUrl?: string }>,
|
||||
selectedImageId: string,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/contracts",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"private": true,
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
Reference in new issue
Block a user