feat: ability to edit mii descriptions
I forgot
This commit is contained in:
parent
75ed926b39
commit
2d82be8453
2 changed files with 21 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ const uploadsDirectory = path.join(process.cwd(), "public", "mii");
|
|||
const editSchema = z.object({
|
||||
name: nameSchema.optional(),
|
||||
tags: tagsSchema.optional(),
|
||||
description: z.string().trim().max(256).optional(),
|
||||
image1: z.union([z.instanceof(File), z.any()]).optional(),
|
||||
image2: z.union([z.instanceof(File), z.any()]).optional(),
|
||||
image3: z.union([z.instanceof(File), z.any()]).optional(),
|
||||
|
|
@ -62,13 +63,14 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
|
|||
const parsed = editSchema.safeParse({
|
||||
name: formData.get("name") ?? undefined,
|
||||
tags: rawTags,
|
||||
description: formData.get("description") ?? undefined,
|
||||
image1: formData.get("image1"),
|
||||
image2: formData.get("image2"),
|
||||
image3: formData.get("image3"),
|
||||
});
|
||||
|
||||
if (!parsed.success) return rateLimit.sendResponse({ error: parsed.error.errors[0].message }, 400);
|
||||
const { name, tags, image1, image2, image3 } = parsed.data;
|
||||
const { name, tags, description, image1, image2, image3 } = parsed.data;
|
||||
|
||||
// Validate image files
|
||||
const images: File[] = [];
|
||||
|
|
@ -88,6 +90,7 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
|
|||
const updateData: Partial<Mii> = {};
|
||||
if (name !== undefined) updateData.name = profanity.censor(name); // Censor potential inappropriate words
|
||||
if (tags !== undefined) updateData.tags = tags.map((t) => profanity.censor(t)); // Same here
|
||||
if (description !== undefined) updateData.description = profanity.censor(description);
|
||||
if (images.length > 0) updateData.imageCount = images.length;
|
||||
|
||||
if (Object.keys(updateData).length == 0) return rateLimit.sendResponse({ error: "Nothing was changed" }, 400);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export default function EditForm({ mii, likes }: Props) {
|
|||
|
||||
const [name, setName] = useState(mii.name);
|
||||
const [tags, setTags] = useState(mii.tags);
|
||||
const [description, setDescription] = useState(mii.description);
|
||||
const hasFilesChanged = useRef(false);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
|
|
@ -64,6 +65,8 @@ export default function EditForm({ mii, likes }: Props) {
|
|||
const formData = new FormData();
|
||||
if (name != mii.name) formData.append("name", name);
|
||||
if (tags != mii.tags) formData.append("tags", JSON.stringify(tags));
|
||||
if (description != mii.description) formData.append("description", description);
|
||||
|
||||
if (hasFilesChanged.current) {
|
||||
files.forEach((file, index) => {
|
||||
// image1, image2, etc.
|
||||
|
|
@ -172,6 +175,20 @@ export default function EditForm({ mii, likes }: Props) {
|
|||
<TagSelector tags={tags} setTags={setTags} />
|
||||
</div>
|
||||
|
||||
<div className="w-full grid grid-cols-3 items-start">
|
||||
<label htmlFor="reason-note" className="font-semibold py-2">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
maxLength={256}
|
||||
placeholder="(optional) Type a description..."
|
||||
className="pill input !rounded-xl resize-none col-span-2"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Separator */}
|
||||
<div className="flex items-center gap-4 text-zinc-500 text-sm font-medium mt-8 mb-2">
|
||||
<hr className="flex-grow border-zinc-300" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue