From 40536c79d81e6f5669f131b106e85cc231cfe4d4 Mon Sep 17 00:00:00 2001 From: Raditya Harya Date: Fri, 26 Apr 2024 17:45:15 +0700 Subject: [PATCH] fix command components --- src/app/workflow/Builder.tsx | 2 +- src/components/nodes/Library/Playlist.tsx | 97 ++++++++++--------- src/components/ui/command.tsx | 2 +- src/styles/globals.css | 110 ++++++++++++---------- 4 files changed, 116 insertions(+), 95 deletions(-) diff --git a/src/app/workflow/Builder.tsx b/src/app/workflow/Builder.tsx index 31f6674..d853f94 100644 --- a/src/app/workflow/Builder.tsx +++ b/src/app/workflow/Builder.tsx @@ -190,7 +190,7 @@ function Builder({ - + {workflowIsLoading || sessionStore === null ? ( ) : ( diff --git a/src/components/nodes/Library/Playlist.tsx b/src/components/nodes/Library/Playlist.tsx index 11dd55b..db2f950 100644 --- a/src/components/nodes/Library/Playlist.tsx +++ b/src/components/nodes/Library/Playlist.tsx @@ -15,6 +15,7 @@ import { CommandGroup, CommandInput, CommandItem, + CommandList, } from "@/components/ui/command"; import { Popover, @@ -76,7 +77,7 @@ const PlaylistItem = ({ }) => ( @@ -145,14 +146,24 @@ const PlaylistComponent: React.FC = ({ id, data }) => { `/api/user/${session.user.providerAccountId}/playlists?q=${search}`, ); const data = await response.json(); - setUserPlaylistsStore(data as any[]); + const newPlaylists = userPlaylists.concat(data); + let dedupedPlaylists = newPlaylists.reduce((acc, current) => { + const x = acc.find(item => item.playlistId === current.playlistId); + if (!x) { + return acc.concat([current]); + } else { + return acc; + } + }, []); + + setUserPlaylistsStore(dedupedPlaylists); } catch (err) { console.error(err); } } }; - const userPlaylists = async () => { + const userPlaylistsFetch = async () => { try { const response = await fetch( `/api/user/${session.user.providerAccountId}/playlists`, @@ -170,7 +181,7 @@ const PlaylistComponent: React.FC = ({ id, data }) => { console.error(err); }); } else { - userPlaylists().catch((err) => { + userPlaylistsFetch().catch((err) => { console.error(err); }); } @@ -261,46 +272,48 @@ const PlaylistComponent: React.FC = ({ id, data }) => { /> No playlist found. - - {userPlaylists.length > 0 - ? userPlaylists.map((playlist) => ( - handleSelect(playlist)} - /> - )) - : Array.from({ length: 3 }).map((_, index) => ( - - key={`loading-${index}`} - value="loading" - onSelect={() => { - setSelectedPlaylist({ - playlistId: "loading", - name: "loading", - description: "loading", - image: "", - owner: "loading", - total: 0, - }); - setOpen(false); - }} - > -
-
-
-
- loading... -
-
- loading... + + + {userPlaylists.length > 0 + ? userPlaylists.map((playlist) => ( + handleSelect(playlist)} + /> + )) + : Array.from({ length: 3 }).map((_, index) => ( + + key={`loading-${index}`} + value="loading" + onSelect={() => { + setSelectedPlaylist({ + playlistId: "loading", + name: "loading", + description: "loading", + image: "", + owner: "loading", + total: 0, + }); + setOpen(false); + }} + > +
+
+
+
+ loading... +
+
+ loading... +
-
- - ))} - + + ))} + + diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx index f43019b..86fb2da 100644 --- a/src/components/ui/command.tsx +++ b/src/components/ui/command.tsx @@ -117,7 +117,7 @@ const CommandItem = React.forwardRef<