);
}
diff --git a/app/features/user-page/actions/u.$identifier.art.server.ts b/app/features/user-page/actions/u.$identifier.art.server.ts
index 50ea32e54..2c5ed7901 100644
--- a/app/features/user-page/actions/u.$identifier.art.server.ts
+++ b/app/features/user-page/actions/u.$identifier.art.server.ts
@@ -1,27 +1,54 @@
import type { ActionFunction } from "@remix-run/node";
-import { deleteArtSchema } from "~/features/art/art-schemas.server";
+import * as ArtRepository from "~/features/art/ArtRepository.server";
+import { userArtPageActionSchema } from "~/features/art/art-schemas.server";
import { deleteArt } from "~/features/art/queries/deleteArt.server";
import { findArtById } from "~/features/art/queries/findArtById.server";
import { requireUserId } from "~/features/auth/core/user.server";
-import { errorToastIfFalsy, parseRequestPayload } from "~/utils/remix.server";
+import { logger } from "~/utils/logger";
+import {
+ errorToastIfFalsy,
+ parseRequestPayload,
+ successToast,
+} from "~/utils/remix.server";
+import { assertUnreachable } from "~/utils/types";
export const action: ActionFunction = async ({ request }) => {
const user = await requireUserId(request);
const data = await parseRequestPayload({
request,
- schema: deleteArtSchema,
+ schema: userArtPageActionSchema,
});
- // this actually doesn't delete the image itself from the static hosting
- // but the idea is that storage is cheap anyway and if needed later
- // then we can have a routine that checks all the images still current and nukes the rest
- const artToDelete = findArtById(data.id);
- errorToastIfFalsy(
- artToDelete?.authorId === user.id,
- "Insufficient permissions",
- );
+ switch (data._action) {
+ case "DELETE_ART": {
+ // this actually doesn't delete the image itself from the static hosting
+ // but the idea is that storage is cheap anyway and if needed later
+ // then we can have a routine that checks all the images still current and nukes the rest
+ const artToDelete = findArtById(data.id);
+ errorToastIfFalsy(
+ artToDelete?.authorId === user.id,
+ "Insufficient permissions",
+ );
- deleteArt(data.id);
+ deleteArt(data.id);
- return null;
+ return successToast("Deleting art successful");
+ }
+ case "UNLINK_ART": {
+ logger.info("Unlinking art", {
+ userId: user.id,
+ artId: data.id,
+ });
+
+ await ArtRepository.unlinkUserFromArt({
+ userId: user.id,
+ artId: data.id,
+ });
+
+ return successToast("Unlinking art successful");
+ }
+ default: {
+ assertUnreachable(data);
+ }
+ }
};
diff --git a/locales/en/art.json b/locales/en/art.json
index 841a5a9c8..b6cc19752 100644
--- a/locales/en/art.json
+++ b/locales/en/art.json
@@ -24,5 +24,8 @@
"forms.tags.addNew": "Create a new one.",
"forms.tags.addNew.placeholder": "Create a new tag",
"forms.tags.searchExisting.placeholder": "Search existing tags",
- "forms.tags.maxReached": "Max tags reached"
+ "forms.tags.maxReached": "Max tags reached",
+
+ "delete.title": "Are you sure you want to delete the art?",
+ "unlink.title": "Are you sure you want to remove this art from your profile (only {{username}} can add it back)?"
}