mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-22 18:45:19 +02:00
commit
b2c809b1bb
1 changed files with 37 additions and 12 deletions
|
|
@ -11,7 +11,7 @@ import { Button } from "@/components/ui/button";
|
||||||
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
||||||
import { TextareaWithSend } from "@/app/components/ui/textarea-with-send";
|
import { TextareaWithSend } from "@/app/components/ui/textarea-with-send";
|
||||||
import { Workflow } from '../../lib/types/workflow_types';
|
import { Workflow } from '../../lib/types/workflow_types';
|
||||||
import { loadSharedWorkflow } from '@/app/actions/shared-workflow.actions';
|
import { loadSharedWorkflow, createSharedWorkflowFromJson } from '@/app/actions/shared-workflow.actions';
|
||||||
import { PictureImg } from '@/components/ui/picture-img';
|
import { PictureImg } from '@/components/ui/picture-img';
|
||||||
import { Tabs, Tab } from "@/components/ui/tabs";
|
import { Tabs, Tab } from "@/components/ui/tabs";
|
||||||
import { Project } from "@/src/entities/models/project";
|
import { Project } from "@/src/entities/models/project";
|
||||||
|
|
@ -220,18 +220,43 @@ export function BuildAssistantSection() {
|
||||||
// Handle template share (for both library and community)
|
// Handle template share (for both library and community)
|
||||||
const handleTemplateShare = async (template: any) => {
|
const handleTemplateShare = async (template: any) => {
|
||||||
try {
|
try {
|
||||||
// Fetch workflow for the template and create a shared snapshot
|
// Robust copy helper: tries async clipboard first, then falls back to execCommand
|
||||||
const data = await getAssistantTemplate(template.id);
|
const copyTextToClipboard = async (text: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// fall through to fallback
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.value = text;
|
||||||
|
textarea.setAttribute('readonly', '');
|
||||||
|
textarea.style.position = 'fixed';
|
||||||
|
textarea.style.opacity = '0';
|
||||||
|
textarea.style.left = '-9999px';
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.focus();
|
||||||
|
textarea.select();
|
||||||
|
const successful = document.execCommand('copy');
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
return successful;
|
||||||
|
} catch (_e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const shareResp = await fetch('/api/shared-workflow', {
|
// Fetch workflow for the template and create a shared snapshot via server action
|
||||||
method: 'POST',
|
const data = await getAssistantTemplate(template.id);
|
||||||
headers: { 'content-type': 'application/json' },
|
const { id } = await createSharedWorkflowFromJson(JSON.stringify(data.workflow));
|
||||||
body: JSON.stringify({ workflow: data.workflow }),
|
const url = `${window.location.origin}/projects?shared=${id}`;
|
||||||
});
|
const copied = await copyTextToClipboard(url);
|
||||||
if (!shareResp.ok) throw new Error('Failed to create shared workflow');
|
if (!copied) {
|
||||||
const shareData = await shareResp.json();
|
throw new Error('Clipboard write failed');
|
||||||
const url = `${window.location.origin}/projects?shared=${shareData.id}`;
|
}
|
||||||
await navigator.clipboard.writeText(url);
|
// Optional debug log
|
||||||
console.log('URL copied to clipboard');
|
console.log('URL copied to clipboard');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to copy shared URL:', err);
|
console.error('Failed to copy shared URL:', err);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue