From c281ed8a3c6487c4584a2a83b5f36015a4d1125e Mon Sep 17 00:00:00 2001 From: besscroft Date: Wed, 17 Apr 2024 00:08:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/image-update/route.ts | 9 ++ components/admin/list/ImageEditSheet.tsx | 116 +++++++++++++++++++++++ components/admin/list/ImageView.tsx | 87 +++++++++++++++++ components/admin/list/ListProps.tsx | 18 +++- components/admin/tag/TagEditSheet.tsx | 1 + components/ui/Sheet.tsx | 4 +- server/lib/operate.ts | 26 +++++ stores/buttonStores.ts | 29 +++--- 8 files changed, 273 insertions(+), 17 deletions(-) create mode 100644 app/api/v1/image-update/route.ts create mode 100644 components/admin/list/ImageEditSheet.tsx create mode 100644 components/admin/list/ImageView.tsx diff --git a/app/api/v1/image-update/route.ts b/app/api/v1/image-update/route.ts new file mode 100644 index 0000000..09fca0e --- /dev/null +++ b/app/api/v1/image-update/route.ts @@ -0,0 +1,9 @@ +import 'server-only' +import { updateImage } from '~/server/lib/operate' +import { NextRequest } from 'next/server' + +export async function PUT(req: NextRequest) { + const image = await req.json() + const data = await updateImage(image); + return Response.json(data) +} \ No newline at end of file diff --git a/components/admin/list/ImageEditSheet.tsx b/components/admin/list/ImageEditSheet.tsx new file mode 100644 index 0000000..b3cee7b --- /dev/null +++ b/components/admin/list/ImageEditSheet.tsx @@ -0,0 +1,116 @@ +'use client' + +import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '~/components/ui/Sheet' +import { useButtonStore } from '~/app/providers/button-store-Providers' +import { HandleListProps, ImageType } from '~/types' +import { usePageSWRHydrated } from '~/hooks/usePageSWRHydrated' +import { Button, cn, Input, Switch, Textarea } from '@nextui-org/react' +import React, { useState } from 'react' +import { toast } from 'sonner' + +export default function ImageEditSheet(props : Readonly) { + const { pageNum, ...restProps } = props + const { mutate } = usePageSWRHydrated(restProps, pageNum) + const { imageEdit, image, setImageEdit, setImageEditData } = useButtonStore( + (state) => state, + ) + const [loading, setLoading] = useState(false) + + async function submit() { + try { + setLoading(true) + const res = await fetch('/api/v1/image-update', { + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(image), + method: 'PUT', + }).then(response => response.json()) + toast.success('更新成功!') + setImageEditData({} as ImageType) + setImageEdit(false) + await mutate() + } catch (e) { + toast.error('更新失败!') + } finally { + setLoading(false) + } + } + + return ( + { + if (!open) { + setImageEdit(false) + setImageEditData({} as ImageType) + } + }} + > + + + 编辑标签 + +