mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-24 18:22:29 +00:00
webapp: add "Edit on Canvas" lightbox button -> PageDraw
Open any image output in the image editor straight from the lightbox, matching the existing Make Video / Recreate handoffs. Mirrors the Tauri app handleEditFromGallery flow: RESET the lib store, seed the image as base (and into history), then route to /edit-image. Gated to images (hidden for video/3D), so it shows on create-image, library, and task-queue lightboxes via the shared LightboxDetails.
This commit is contained in:
@@ -75,6 +75,7 @@ export interface LightboxDetailsProps {
|
||||
onClose?: () => void;
|
||||
onRecreate?: () => void;
|
||||
onMakeVideo?: () => void;
|
||||
onEditOnCanvas?: () => void;
|
||||
onDelete?: () => void;
|
||||
showDownloadAppCta?: boolean;
|
||||
}
|
||||
@@ -90,6 +91,7 @@ export function LightboxDetails({
|
||||
onClose,
|
||||
onRecreate,
|
||||
onMakeVideo,
|
||||
onEditOnCanvas,
|
||||
onDelete,
|
||||
showDownloadAppCta,
|
||||
}: LightboxDetailsProps) {
|
||||
@@ -474,6 +476,16 @@ export function LightboxDetails({
|
||||
Make Video
|
||||
</Button>
|
||||
)}
|
||||
{onEditOnCanvas && (
|
||||
<Button
|
||||
icon={faPencil}
|
||||
className="w-full border border-ui-panel-border bg-ui-controls/40 hover:bg-ui-controls/60 text-white"
|
||||
variant="secondary"
|
||||
onClick={onEditOnCanvas}
|
||||
>
|
||||
Edit on Canvas
|
||||
</Button>
|
||||
)}
|
||||
{onRecreate && promptData.hasToken && (
|
||||
<Button
|
||||
icon={faArrowRotateRight}
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
type PromptData,
|
||||
} from "./shared";
|
||||
import { LightboxDetails } from "./LightboxDetails";
|
||||
import { applyEditOnCanvasFromImage } from "../../pages/pagedraw/edit-on-canvas";
|
||||
import {
|
||||
applyMakeVideoFromImage,
|
||||
applyRecreateFromMediaToken,
|
||||
@@ -334,6 +335,13 @@ export function Lightbox({
|
||||
applyMakeVideoFromImage(selectedMediaToken, selectedImageUrl, navigate);
|
||||
}, [selectedMediaToken, selectedImageUrl, canMakeVideo, navigate, onClose]);
|
||||
|
||||
const canEditOnCanvas = !isVideo && !is3D;
|
||||
const handleEditOnCanvas = useCallback(() => {
|
||||
if (!selectedMediaToken || !selectedImageUrl || !canEditOnCanvas) return;
|
||||
onClose();
|
||||
applyEditOnCanvasFromImage(selectedMediaToken, selectedImageUrl, navigate);
|
||||
}, [selectedMediaToken, selectedImageUrl, canEditOnCanvas, navigate, onClose]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
@@ -505,6 +513,11 @@ export function Lightbox({
|
||||
? handleMakeVideo
|
||||
: undefined
|
||||
}
|
||||
onEditOnCanvas={
|
||||
canEditOnCanvas && selectedMediaToken && selectedImageUrl
|
||||
? handleEditOnCanvas
|
||||
: undefined
|
||||
}
|
||||
onDelete={
|
||||
selectedMediaToken
|
||||
? () => setConfirmDeleteOpen(true)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// "Edit on Canvas" handoff: open an existing image in the PageDraw editor.
|
||||
//
|
||||
// Mirrors the Tauri app's handleEditFromGallery — RESET the editor, seed the
|
||||
// chosen image as the base (and into history), then route to /edit-image.
|
||||
// Seeding the lib's store before navigating means the editor mounts straight
|
||||
// into the image, same store-based handoff the create-image/create-video
|
||||
// "Recreate" and "Make Video" buttons use (see lib/recreate.ts).
|
||||
|
||||
import type { NavigateFunction } from "react-router-dom";
|
||||
import { useSceneStore } from "@storyteller/ui-pagedraw";
|
||||
|
||||
export function applyEditOnCanvasFromImage(
|
||||
mediaToken: string,
|
||||
mediaUrl: string,
|
||||
navigate: NavigateFunction,
|
||||
): void {
|
||||
const store = useSceneStore.getState();
|
||||
const baseImage = {
|
||||
url: mediaUrl,
|
||||
mediaToken,
|
||||
fullImageUrl: mediaUrl,
|
||||
};
|
||||
store.RESET();
|
||||
store.addHistoryImageBundle({ images: [baseImage] });
|
||||
store.setBaseImageInfo(baseImage);
|
||||
navigate("/edit-image");
|
||||
}
|
||||
Reference in New Issue
Block a user