From 4e7d453e8db374ffcf025448465fdd938649209c Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Wed, 9 Apr 2025 22:20:03 +0300 Subject: [PATCH] Removing art from user profile by user feature --- app/features/art/ArtRepository.server.ts | 15 ++++++ app/features/art/art-schemas.server.ts | 12 +++++ app/features/art/components/ArtGrid.tsx | 42 +++++++++++---- .../actions/u.$identifier.art.server.ts | 53 ++++++++++++++----- locales/en/art.json | 5 +- 5 files changed, 104 insertions(+), 23 deletions(-) create mode 100644 app/features/art/ArtRepository.server.ts diff --git a/app/features/art/ArtRepository.server.ts b/app/features/art/ArtRepository.server.ts new file mode 100644 index 000000000..15475d704 --- /dev/null +++ b/app/features/art/ArtRepository.server.ts @@ -0,0 +1,15 @@ +import { db } from "~/db/sql"; + +export function unlinkUserFromArt({ + userId, + artId, +}: { + userId: number; + artId: number; +}) { + return db + .deleteFrom("ArtUserMetadata") + .where("artId", "=", artId) + .where("userId", "=", userId) + .execute(); +} diff --git a/app/features/art/art-schemas.server.ts b/app/features/art/art-schemas.server.ts index f95143130..d6667c98b 100644 --- a/app/features/art/art-schemas.server.ts +++ b/app/features/art/art-schemas.server.ts @@ -1,5 +1,6 @@ import { z } from "zod"; import { + _action, checkboxValueToDbBoolean, dbBoolean, falsyToNull, @@ -43,5 +44,16 @@ export const editArtSchema = z.object({ }); export const deleteArtSchema = z.object({ + _action: _action("DELETE_ART"), id, }); + +export const unlinkArtSchema = z.object({ + _action: _action("UNLINK_ART"), + id, +}); + +export const userArtPageActionSchema = z.union([ + deleteArtSchema, + unlinkArtSchema, +]); diff --git a/app/features/art/components/ArtGrid.tsx b/app/features/art/components/ArtGrid.tsx index 393d37c76..35ed2197e 100644 --- a/app/features/art/components/ArtGrid.tsx +++ b/app/features/art/components/ArtGrid.tsx @@ -9,6 +9,7 @@ import { FormWithConfirm } from "~/components/FormWithConfirm"; import { Pagination } from "~/components/Pagination"; import { EditIcon } from "~/components/icons/Edit"; import { TrashIcon } from "~/components/icons/Trash"; +import { UnlinkIcon } from "~/components/icons/Unlink"; import { useIsMounted } from "~/hooks/useIsMounted"; import { usePagination } from "~/hooks/usePagination"; import { useSearchParamState } from "~/hooks/useSearchParamState"; @@ -191,8 +192,11 @@ function ImagePreview({ {t("common:actions.edit")}