Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions sim/app/w/marketplace/components/workflow-card.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use client'

import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
import { Eye, Star } from 'lucide-react'
import { Card, CardContent, CardFooter, CardHeader } from '@/components/ui/card'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { Workflow } from '../marketplace'
import { WorkflowPreview } from './workflow-preview'

Expand All @@ -25,6 +27,8 @@ interface WorkflowCardProps {
*/
export function WorkflowCard({ workflow, onHover }: WorkflowCardProps) {
const [isPreviewReady, setIsPreviewReady] = useState(!!workflow.workflowState)
const router = useRouter()
const { createWorkflow } = useWorkflowRegistry()

// When workflow state becomes available, update preview ready state
useEffect(() => {
Expand All @@ -44,19 +48,35 @@ export function WorkflowCard({ workflow, onHover }: WorkflowCardProps) {
}

/**
* Handle workflow card click - track views
* Handle workflow card click - track views and import workflow
*/
const handleClick = async () => {
try {
// Track view
await fetch(`/api/marketplace/workflows`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id: workflow.id }),
})

// Create a local copy of the marketplace workflow
if (workflow.workflowState) {
const newWorkflowId = createWorkflow({
name: `${workflow.name} (Copy)`,
description: workflow.description,
marketplaceId: workflow.id,
marketplaceState: workflow.workflowState,
})

// Navigate to the new workflow
router.push(`/w/${newWorkflowId}`)
} else {
console.error('Cannot import workflow: state is not available')
}
} catch (error) {
console.error('Failed to track workflow view:', error)
console.error('Failed to handle workflow click:', error)
}
}

Expand Down
5 changes: 5 additions & 0 deletions sim/app/w/marketplace/constants/categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const getCategoryByValue = (value: string): Category => {
}

export const getCategoryLabel = (value: string): string => {
// Special handling for "popular" and "recent" sections
if (value === 'popular') return 'Popular'
if (value === 'recent') return 'Recent'

// Default handling for regular categories
return getCategoryByValue(value).label
}

Expand Down
1 change: 1 addition & 0 deletions sim/db/migrations/0024_next_whizzer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "workflow" ADD COLUMN "marketplace_data" json DEFAULT 'null'::json;
Loading