diff --git a/app/features/art/routes/art.new.tsx b/app/features/art/routes/art.new.tsx index a720d200c..a519e9b18 100644 --- a/app/features/art/routes/art.new.tsx +++ b/app/features/art/routes/art.new.tsx @@ -120,11 +120,13 @@ export const loader = async ({ request }: LoaderArgs) => { const artIdRaw = new URL(request.url).searchParams.get( NEW_ART_EXISTING_SEARCH_PARAM_KEY ); - if (!artIdRaw) return null; + if (!artIdRaw) return { art: null, tags: allArtTags() }; const artId = Number(artIdRaw); const art = findArtById(artId); - if (!art || art.authorId !== user.id) return null; + if (!art || art.authorId !== user.id) { + return { art: null, tags: allArtTags() }; + } return { art, tags: allArtTags() }; }; @@ -157,9 +159,9 @@ export default function NewArtPage() { - {data?.art ? : null} + {data.art ? : null}
-
@@ -180,7 +182,7 @@ function ImageUpload({ const data = useLoaderData(); const { t } = useTranslation(["common"]); - if (data?.art) { + if (data.art) { return ( (); - const [value, setValue] = React.useState(data?.art.description ?? ""); + const [value, setValue] = React.useState(data.art?.description ?? ""); return (
@@ -260,15 +262,17 @@ function Description() { ); } +// note: not handling edge case where a tag was added by another user while this +// user was adding a new art with the same tag -> will crash function Tags() { const data = useLoaderData(); const [creationMode, setCreationMode] = React.useState(false); const [tags, setTags] = React.useState<{ name?: string; id?: number }[]>( - data?.art.tags ?? [] + data.art?.tags ?? [] ); const [newTagValue, setNewTagValue] = React.useState(""); - const existingTags = data?.tags ?? []; + const existingTags = data.tags; const unselectedTags = existingTags.filter( (t) => !tags.some((tag) => tag.id === t.id) ); @@ -388,8 +392,8 @@ function LinkedUsers() { const [users, setUsers] = React.useState< { inputId: string; userId?: number }[] >( - (data?.art.linkedUsers ?? []).length > 0 - ? data!.art.linkedUsers.map((userId) => ({ userId, inputId: nanoid() })) + (data.art?.linkedUsers ?? []).length > 0 + ? data.art!.linkedUsers.map((userId) => ({ userId, inputId: nanoid() })) : [{ inputId: nanoid() }] ); @@ -451,7 +455,7 @@ function LinkedUsers() { function ShowcaseToggle() { const { t } = useTranslation(["art"]); const data = useLoaderData(); - const isCurrentlyShowcase = Boolean(data?.art.isShowcase); + const isCurrentlyShowcase = Boolean(data.art?.isShowcase); const [checked, setChecked] = React.useState(isCurrentlyShowcase); return (