Fixed switch and deleted unnecessary page

This commit is contained in:
Emir Karabeg
2025-01-29 23:30:42 -08:00
parent dc64f0b388
commit 04fb16ce40
5 changed files with 27 additions and 82 deletions

View File

@@ -23,9 +23,9 @@ export default function RootLayout({
<script
dangerouslySetInnerHTML={{
__html: `
if (typeof window !== 'undefined') {
window.INITIAL_TIMESTAMP = ${Date.now()};
}
document.addEventListener('DOMContentLoaded', function() {
window.INITIAL_TIMESTAMP = Date.now();
});
`,
}}
/>

View File

@@ -1,18 +1,25 @@
import { Switch as UISwitch } from '@/components/ui/switch'
import { useSubBlockValue } from '../hooks/use-sub-block-value'
import { Label } from '@/components/ui/label'
interface SwitchProps {
blockId: string
subBlockId: string
title: string
}
export function Switch({ blockId, subBlockId }: SwitchProps) {
export function Switch({ blockId, subBlockId, title }: SwitchProps) {
const [value, setValue] = useSubBlockValue(blockId, subBlockId)
return (
<UISwitch
checked={Boolean(value)}
onCheckedChange={(checked) => setValue(checked)}
/>
<div className="flex flex-col gap-2">
<Label className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
{title}
</Label>
<UISwitch
checked={Boolean(value)}
onCheckedChange={(checked) => setValue(checked)}
/>
</div>
)
}
}

View File

@@ -73,10 +73,11 @@ export function SubBlock({ blockId, config, isConnecting }: SubBlockProps) {
return <Code blockId={blockId} subBlockId={config.id} />
case 'switch':
return (
<div className="flex items-center justify-between">
<Label className="text-sm font-medium">{config.title}</Label>
<Switch blockId={blockId} subBlockId={config.id} />
</div>
<Switch
blockId={blockId}
subBlockId={config.id}
title={config.title}
/>
)
default:
return null

View File

@@ -1,66 +0,0 @@
"use client"
import { useState } from "react"
import { WorkflowBlock } from "./components/workflow-block/workflow-block"
import { BlockConfig, BlockCategory, BlockIcon } from "@/blocks/types"
import { LayoutDashboard } from "lucide-react"
const WorkflowIcon: BlockIcon = (props) => <LayoutDashboard {...props} />
interface WorkflowBlockState {
id: string
type: string
position: { x: number; y: number }
config: BlockConfig
name: string
}
export default function Page() {
const [workflows, setWorkflows] = useState<WorkflowBlockState[]>([])
const createNewWorkflow = () => {
const newWorkflow: WorkflowBlockState = {
id: `workflow-${workflows.length + 1}`,
type: "default",
position: { x: 0, y: 0 },
config: {
type: "default",
toolbar: {
title: "New Workflow",
description: "Empty workflow",
bgColor: "#808080",
icon: WorkflowIcon,
category: "basic" as BlockCategory
},
tools: {
access: []
},
workflow: {
subBlocks: [],
inputs: {},
outputs: {}
}
},
name: `New Workflow ${workflows.length + 1}`
}
setWorkflows([...workflows, newWorkflow])
}
return (
<div>
<button onClick={createNewWorkflow}>New Workflow</button>
<div>
{workflows.map((workflow) => (
<WorkflowBlock
key={workflow.id}
id={workflow.id}
type={workflow.type}
position={workflow.position}
config={workflow.config}
name={workflow.name}
/>
))}
</div>
</div>
)
}

View File

@@ -1,5 +1,8 @@
"use client"
import * as React from "react"
import * as SwitchPrimitives from "@radix-ui/react-switch"
import { cn } from "@/lib/utils"
const Switch = React.forwardRef<
@@ -8,7 +11,7 @@ const Switch = React.forwardRef<
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-blue-500 data-[state=unchecked]:bg-gray-200",
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
className
)}
{...props}
@@ -16,11 +19,11 @@ const Switch = React.forwardRef<
>
<SwitchPrimitives.Thumb
className={cn(
"pointer-events-none block h-5 w-5 rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"
"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"
)}
/>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName
export { Switch }
export { Switch }