From de0f06c998ac868d8ee22dcc01912add34ca6498 Mon Sep 17 00:00:00 2001 From: Jordi Enric Date: Sat, 4 May 2024 13:16:20 +0200 Subject: [PATCH] ui imprvs --- apps/web/src/pages/blogs/[blogId]/posts.tsx | 356 +++++++++++--------- 1 file changed, 191 insertions(+), 165 deletions(-) diff --git a/apps/web/src/pages/blogs/[blogId]/posts.tsx b/apps/web/src/pages/blogs/[blogId]/posts.tsx index 8023fe4..609a1f2 100644 --- a/apps/web/src/pages/blogs/[blogId]/posts.tsx +++ b/apps/web/src/pages/blogs/[blogId]/posts.tsx @@ -162,20 +162,23 @@ export default function BlogPosts() { - - -
+ + + + New post + + + } + > {posts.length === 0 && (
✏️
@@ -217,23 +220,16 @@ export default function BlogPosts() { /> ); })} -
+
- {media.isLoading && ( - <> -
- -
- - )} -
-
-

- {selectedImages.length > 0 - ? `${selectedImages.length} files selected` - : "Media"} -

+ 0 + ? `${selectedImages.length} files selected` + : "Media" + } + actions={
{selectedImages.length > 0 && ( <> @@ -300,153 +296,163 @@ export default function BlogPosts() {
-
- {media.isLoading || - (media.isRefetching && ( -
- -
- ))} - {media.data?.length === 0 ? ( - <> -
-
📷
-
- No images uploaded yet + } + > + <> + {media.isLoading && ( + <> +
+
+ + )} + + {media.isLoading || + (media.isRefetching && ( +
+ +
+ ))} + {media.data?.length === 0 ? ( + <> +
+
📷
+
+ No images uploaded yet +
+
+ + ) : ( +
+ { + setSelectedImages(imgs); + }} + selected={selectedImages} + type="multiple" + />
- - ) : ( -
- { - setSelectedImages(imgs); - }} - selected={selectedImages} - type="multiple" - /> -
- )} -
+ )} + + -
- {tags.isLoading && ( -
- -
- )} -
-

- {tags.data?.length ? `${tags.data?.length} tags` : "Tags"} -

- -
- {tags.data?.length === 0 && ( -
-
🏷️
-
- Nothing here yet + } + > + <> + {tags.isLoading && ( +
+
-
- )} - -
- {tags.data?.length && ( -
-
Tag
-
Slug
-
Posts with tag
-
+ )} + {tags.data?.length === 0 && ( +
+
🏷️
+
+ Nothing here yet +
)} - {tags.data?.map((tag) => { - return ( -
-
- - {tag.tag_name} -
- -
-

- {tag.slug} -

-
- -
{tag.post_count}
- -
- - - - - - { - setUpdateTagDialogOpen(true); - }} - > - - Edit - - { - setDeleteTagDialogOpen(true); - }} - > - - Delete - - - -
- { - const res = await updateTagMutation.mutateAsync({ - name: newTag.tag_name, - slug: newTag.slug, - id: tag.tag_id!, - }); - if (res.error) { - toast.error("Failed to update tag"); - return; - } - toast.success("Tag updated"); - }} - open={updateTagDialogOpen} - onOpenChange={setUpdateTagDialogOpen} - /> - { - const res = await deleteTagMutation.mutateAsync( - tag.tag_id! - ); - if (res.error) { - toast.error("Failed to delete tag"); - return; - } - setDeleteTagDialogOpen(false); - toast.success("Tag deleted"); - }} - /> +
+ {tags.data?.length && ( +
+
Tag
+
Slug
+
Posts with tag
+
- ); - })} -
-
+ )} + + {tags.data?.map((tag) => { + return ( +
+
+ + {tag.tag_name} +
+ +
+

+ {tag.slug} +

+
+ +
{tag.post_count}
+ +
+ + + + + + { + setUpdateTagDialogOpen(true); + }} + > + + Edit + + { + setDeleteTagDialogOpen(true); + }} + > + + Delete + + + +
+ { + const res = await updateTagMutation.mutateAsync({ + name: newTag.tag_name, + slug: newTag.slug, + id: tag.tag_id!, + }); + if (res.error) { + toast.error("Failed to update tag"); + return; + } + toast.success("Tag updated"); + }} + open={updateTagDialogOpen} + onOpenChange={setUpdateTagDialogOpen} + /> + { + const res = await deleteTagMutation.mutateAsync( + tag.tag_id! + ); + if (res.error) { + toast.error("Failed to delete tag"); + return; + } + setDeleteTagDialogOpen(false); + toast.success("Tag deleted"); + }} + /> +
+ ); + })} +
+ +
@@ -469,7 +475,7 @@ function PostItem({ return (
@@ -540,3 +546,23 @@ function PostItem({ ); } + +function TabSection({ + title, + children, + actions, +}: { + title: string; + children: React.ReactNode; + actions?: React.ReactNode; +}) { + return ( +
+
+

{title}

+ {actions} +
+ {children} +
+ ); +}