mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
25 lines
859 B
TypeScript
25 lines
859 B
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { requireUser } from "~/features/auth/core/user.server";
|
|
import * as ArtRepository from "../ArtRepository.server";
|
|
import { NEW_ART_EXISTING_SEARCH_PARAM_KEY } from "../art-constants";
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
const user = await requireUser(request);
|
|
|
|
const artIdRaw = new URL(request.url).searchParams.get(
|
|
NEW_ART_EXISTING_SEARCH_PARAM_KEY,
|
|
);
|
|
if (!artIdRaw) return { art: null, tags: await ArtRepository.findAllTags() };
|
|
const artId = Number(artIdRaw);
|
|
|
|
const userArts = await ArtRepository.findArtsByUserId(user.id, {
|
|
includeTagged: false,
|
|
});
|
|
const art = userArts.find((a) => a.id === artId);
|
|
if (!art) {
|
|
return { art: null, tags: await ArtRepository.findAllTags() };
|
|
}
|
|
|
|
return { art, tags: await ArtRepository.findAllTags() };
|
|
};
|