diff --git a/src/components/nodes/Library/Playlist.tsx b/src/components/nodes/Library/Playlist.tsx index 58f2cf1..e81ab2a 100644 --- a/src/components/nodes/Library/Playlist.tsx +++ b/src/components/nodes/Library/Playlist.tsx @@ -33,14 +33,12 @@ import { import { ScrollArea } from "@/components/ui/scroll-area"; import Image from "next/image"; -import useStore from "~/app/states/store"; import { Separator } from "~/components/ui/separator"; import { CardWithHeader } from "../Primitives/Card"; import InputPrimitive from "../Primitives/Input"; import { Form, FormField, FormItem, FormLabel } from "@/components/ui/form"; -import useBasicNodeState from "~/hooks/useBasicNodeState"; import { usePlaylistState } from "~/hooks/usePlaylistState"; import Debug from "../Primitives/Debug"; import PlaylistCommand from "../Primitives/PlaylistCommand"; diff --git a/src/components/nodes/Library/SaveAsAppend.tsx b/src/components/nodes/Library/SaveAsAppend.tsx index 96856c8..ae325cd 100644 --- a/src/components/nodes/Library/SaveAsAppend.tsx +++ b/src/components/nodes/Library/SaveAsAppend.tsx @@ -24,8 +24,6 @@ import { import { ScrollArea } from "@/components/ui/scroll-area"; import Image from "next/image"; - -import * as z from "zod"; import { CardWithHeader } from "../Primitives/Card"; import { Form, FormField, FormItem, FormLabel } from "@/components/ui/form"; @@ -38,12 +36,6 @@ type PlaylistProps = { data: Workflow.Playlist; }; -const formSchema = z.object({ - playlistId: z.string().min(1, { - message: "Playlist is required.", - }), -}); - function SaveAsAppendComponent({ id, data }: PlaylistProps) { const { open, @@ -52,18 +44,11 @@ function SaveAsAppendComponent({ id, data }: PlaylistProps) { setSelectedPlaylist, search, setSearch, - state, - isValid, targetConnections, sourceConnections, form, formState, - register, - getNodeData, - updateNodeData, - session, userPlaylists, - setUserPlaylistsStore, handleSelect, } = usePlaylistState(id, data); diff --git a/src/components/nodes/Library/SaveAsNew.tsx b/src/components/nodes/Library/SaveAsNew.tsx index dfcf7d3..3ab341b 100644 --- a/src/components/nodes/Library/SaveAsNew.tsx +++ b/src/components/nodes/Library/SaveAsNew.tsx @@ -16,6 +16,7 @@ import * as z from "zod"; import { Form } from "@/components/ui/form"; import useBasicNodeState from "~/hooks/useBasicNodeState"; import Debug from "../Primitives/Debug"; + type PlaylistProps = { id: string; data: any; @@ -32,15 +33,12 @@ const formSchema = z.object({ const saveAsNewComponent: React.FC = ({ id, data }) => { const { - state, isValid, targetConnections, sourceConnections, form, - nodeData, formState, register, - getNodeData, updateNodeData, } = useBasicNodeState(id, formSchema); diff --git a/src/components/nodes/Primitives/Input.tsx b/src/components/nodes/Primitives/Input.tsx index 21436dd..61cfdad 100644 --- a/src/components/nodes/Primitives/Input.tsx +++ b/src/components/nodes/Primitives/Input.tsx @@ -33,6 +33,7 @@ type InputPrimitiveProps = { name: string; placeholder: string; description: string; + defaultValue?: any; register: UseFormRegister; selectOptions?: { label: string; diff --git a/src/components/nodes/Primitives/SourceList.tsx b/src/components/nodes/Primitives/SourceList.tsx index 334d70b..ca430fc 100644 --- a/src/components/nodes/Primitives/SourceList.tsx +++ b/src/components/nodes/Primitives/SourceList.tsx @@ -1,15 +1,23 @@ import { PlaylistItem as PlaylistItemPrimitive } from "../Primitives/PlaylistItem"; import { AlertComponent } from "./Alert"; -export function SourceList({ - state, - isValid, - operationType, -}: { +interface SourceListProps { state: any; isValid: boolean; operationType: string; -}) { +} + +export function SourceList({ state, isValid, operationType }: SourceListProps) { + if (!(state?.playlistIds && state.playlists)) { + return ( + + ); + } + return (
@@ -37,11 +45,11 @@ export function SourceList({ )}
- {state.playlists - ? state.playlists?.map((playlist) => + {state.playlists.length > 0 + ? state.playlists.map((playlist) => playlist && isValid ? ( ) : null, diff --git a/src/components/nodes/Selectors/First.tsx b/src/components/nodes/Selectors/First.tsx index 4ac7c0a..45b8bb6 100644 --- a/src/components/nodes/Selectors/First.tsx +++ b/src/components/nodes/Selectors/First.tsx @@ -1,24 +1,56 @@ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/no-explicit-any */ "use client"; +import { Form } from "@/components/ui/form"; import { Position } from "@xyflow/react"; -import NodeHandle from "../Primitives/NodeHandle"; - import React from "react"; +import * as z from "zod"; +import { Separator } from "~/components/ui/separator"; import useBasicNodeState from "~/hooks/useBasicNodeState"; import { CardWithHeader } from "../Primitives/Card"; import Debug from "../Primitives/Debug"; +import InputPrimitive from "../Primitives/Input"; +import NodeHandle from "../Primitives/NodeHandle"; import { SourceList } from "../Primitives/SourceList"; type PlaylistProps = { id: string; - data: any; + data: { count: number }; }; -const First: React.FC = ({ id, data }) => { - const { state, isValid, targetConnections, sourceConnections } = - useBasicNodeState(id); +const formSchema = z.object({ + count: z.number().int().default(1), +}); + +const LastComponent: React.FC = ({ id, data }) => { + const { + state, + isValid, + targetConnections, + sourceConnections, + form, + formState, + register, + updateNodeData, + } = useBasicNodeState(id, formSchema); + + const watch = form!.watch(); + const prevWatchRef = React.useRef(watch); + + React.useEffect(() => { + if (data && form) { + form.setValue("count", data.count); + form.trigger(); + } + }, [data, form]); + + React.useEffect(() => { + if (JSON.stringify(prevWatchRef.current) !== JSON.stringify(watch)) { + updateNodeData(id, { + count: watch.count, + }); + } + prevWatchRef.current = watch; + }, [id, watch, updateNodeData]); return ( = ({ id, data }) => { id={id} type="Selector" status={isValid === null ? "loading" : isValid ? "success" : "error"} - info="Interleaves the tracks from multiple playlists" + info="Selects the first N element(s) from a stream" > = ({ id, data }) => { position={Position.Left} style={{ background: "#555" }} /> +
+ console.info(data))}> +
+ +
+
+ + +
- = ({ id, data }) => { ); }; -export default First; +export default LastComponent; diff --git a/src/components/nodes/Selectors/Last.tsx b/src/components/nodes/Selectors/Last.tsx index 4d478b0..ed29462 100644 --- a/src/components/nodes/Selectors/Last.tsx +++ b/src/components/nodes/Selectors/Last.tsx @@ -1,24 +1,56 @@ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/no-explicit-any */ "use client"; +import { Form } from "@/components/ui/form"; import { Position } from "@xyflow/react"; -import NodeHandle from "../Primitives/NodeHandle"; - import React from "react"; +import * as z from "zod"; +import { Separator } from "~/components/ui/separator"; import useBasicNodeState from "~/hooks/useBasicNodeState"; import { CardWithHeader } from "../Primitives/Card"; import Debug from "../Primitives/Debug"; +import InputPrimitive from "../Primitives/Input"; +import NodeHandle from "../Primitives/NodeHandle"; import { SourceList } from "../Primitives/SourceList"; type PlaylistProps = { id: string; - data: any; + data: { count: number }; }; +const formSchema = z.object({ + count: z.number().int().default(1), +}); + const LastComponent: React.FC = ({ id, data }) => { - const { state, isValid, targetConnections, sourceConnections } = - useBasicNodeState(id); + const { + state, + isValid, + targetConnections, + sourceConnections, + form, + formState, + register, + updateNodeData, + } = useBasicNodeState(id, formSchema); + + const watch = form!.watch(); + const prevWatchRef = React.useRef(watch); + + React.useEffect(() => { + if (data && form) { + form.setValue("count", data.count); + form.trigger(); + } + }, [data, form]); + + React.useEffect(() => { + if (JSON.stringify(prevWatchRef.current) !== JSON.stringify(watch)) { + updateNodeData(id, { + count: watch.count, + }); + } + prevWatchRef.current = watch; + }, [id, watch, updateNodeData]); return ( = ({ id, data }) => { id={id} type="Selector" status={isValid === null ? "loading" : isValid ? "success" : "error"} - info="Selects the last element of an array" + info="Selects the last N element(s) from a stream" > = ({ id, data }) => { position={Position.Left} style={{ background: "#555" }} /> +
+ console.info(data))}> +
+ +
+
+ + +
-