diff --git a/src/pages/Categories/index.tsx b/src/pages/Categories/index.tsx index 84cb866..7f23b3c 100644 --- a/src/pages/Categories/index.tsx +++ b/src/pages/Categories/index.tsx @@ -442,37 +442,7 @@ export const CategoriesPage: BasicPage = () => { ); })} - - {modalData && modal(modalData, navigate, handleModalClose)} ); }; - -const modal = (data, navigate, onClose) => { - return ( - - {data.map((item) => { - return ( -
{ - navigate(jump(`/write/post?id=${item.id}`)); - }} - > -

{item.title}

-

点击前往编辑页

-
- ); - })} -
- ); -}; diff --git a/src/pages/Comments/Table/column.tsx b/src/pages/Comments/Table/column.tsx index 0293cf1..a41703c 100644 --- a/src/pages/Comments/Table/column.tsx +++ b/src/pages/Comments/Table/column.tsx @@ -1,9 +1,12 @@ import { + generateAnyActionsColumn, generateSelectColumn, genereateCreatedColumn, } from "@components/widgets/AnyListDataTable/anyColumn"; +import { _private } from "@states/private"; import type { ColumnDef } from "@tanstack/react-table"; import { mailAvatar } from "@utils/avatar"; +import { Edit } from "lucide-react"; export interface CommentReaction { like: number; @@ -74,4 +77,16 @@ export const commentsListColumns: ColumnDef[] = [ }, }, genereateCreatedColumn(), + generateAnyActionsColumn({ + menus: [ + { + title: "修改", + onClick: (row) => { + _private.showModal = true + _private.modalDataId = row.id + }, + icon: , + } + ], + }), ]; diff --git a/src/pages/Comments/component.tsx b/src/pages/Comments/component.tsx index 71776ed..5b66abb 100644 --- a/src/pages/Comments/component.tsx +++ b/src/pages/Comments/component.tsx @@ -15,22 +15,19 @@ import useSWR from "swr"; import useSWRMutation from "swr/mutation"; import { Select } from "@components/widgets/ThemeComponent/ThemeSelect"; import { Label } from "@components/ui/label"; +import { Dialog, DialogHeader } from "@components/ui/dialog"; +import { useSnapshot } from "valtio"; +import { _private } from "@states/private"; +import { DialogContent } from "@radix-ui/react-dialog"; interface EditModalProps { - tabsList: { + status: { name: string; status: number; }[]; - select: string[]; - setShowEditModal: (show: boolean) => void; - setSelect: React.Dispatch>; - setComments: (comments: any) => void; - // setInSideLoading: (loading: boolean) => void; - tab: number; - page: number; } -export const EditModal: React.FC = ({ +export const EditModal: React.FC = ({ tabsList, select, setShowEditModal, @@ -147,126 +144,36 @@ export const EditModal: React.FC = ({ ); }; -interface CommentsListProps { - comments: { - data: { - id: string; - author: string; - email: string; - text: string; - parent?: { - author: string; - created: string; - text: string; - }; - post: { - id: string; - title: string; - }; - created: string; - }[]; - }; - // inSideLoading: boolean; - select: string[]; - setSelect: React.Dispatch>; - jump: (path: string) => void; - mailAvatar: (email: string) => string; -} - -export const CommentsList: React.FC = ({ - comments, - // inSideLoading, - select, - setSelect, - jump, - mailAvatar, -}) => { - const header = useMemo(() => ["AUTHOR", "CONTENT", "ORIGIN", "DATE"], []); - const handleItemClick = useCallback( - (item: { id: string }) => { - if (select.includes(item.id)) { - setSelect(select.filter((i) => i !== item.id)); - } else { - setSelect([...select, item.id]); - } - }, - [select, setSelect] +export const _EditModal: React.FC = (props) => { + const { showModal, modalDataId } = useSnapshot(_private); + const { data } = useSWR(`/comments/${modalDataId}`); + const { trigger } = useSWRMutation( + `/comments/${modalDataId}`, + (key: string, { arg }: { arg: string }) => { + return apiClient(key, { + method: "PUT", + body: JSON.stringify(arg), + }); + } ); + const handleConfirm = async () => { + await trigger(data); + _private.showModal = false; + _private.modalDataId = ""; + }; + return ( - <> - {/* */} -
- - {comments?.data && - comments?.data.map((item) => { - const tableItemHeader = ["AUTHOR", "CONTENT", "ORIGIN", "DATE"]; - const tableItemStyle = { - gridTemplateColumns: "1fr 2fr 2fr 2fr", - }; - const isItemSelected = select.includes(item.id); - const className = clsx(isItemSelected && postStyles.select); - const postTitle = item.post?.title; - const createdTime = new Date(item.created).toLocaleString(); - const replyAuthor = item.parent?.author; - const replyCreatedTime = item.parent?.created.split("T")[0]; - const replyText = item.parent?.text; - return ( - handleItemClick(item)} - > - -
- {item.author} - {item.author} -
-
- - {item.text} - {item.parent && ( -
-
- {replyAuthor} 在 {replyCreatedTime} 说: -
-
{replyText}
-
- )} -
- { - jump(`/write/post?id=${item.post?.id}`); - }} - style={{ cursor: "pointer" }} - > - {postTitle} - - {createdTime} -
- ); - })} -
-
- + { + _private.showModal = e; + }} + defaultOpen={false} + > + + 编辑评论 + + ); }; diff --git a/src/pages/Comments/index.tsx b/src/pages/Comments/index.tsx index 5144cff..7b96716 100644 --- a/src/pages/Comments/index.tsx +++ b/src/pages/Comments/index.tsx @@ -17,6 +17,7 @@ import { CommentsTable } from "./Table/data-table"; import { commentsListColumns } from "./Table/column"; import { Button } from "@components/ui/button"; import { _private } from "@states/private"; +import { useSnapshot } from "valtio"; const tabsList = [ { @@ -43,26 +44,15 @@ export const CommentsPage: BasicPage = () => { const navigate = useNavigate(); const [tab, setTab] = useState(status ? Number(status) : 0); - const [select, setSelect] = useState([]); - const [showEditModal, setShowEditModal] = useState(false); - // const [inSideLoading, setInSideLoading] = useState(true); + const { showModal } = useSnapshot(_private); const { data, mutate } = useSWR(`/comments?status=${tab}&page=${page}`); useEffect(() => { navigate(jump(`/comments?status=${tab}&page=${page}`)); mutate(); - setSelect([]); }, [page, tab]); - const handleDelete = () => { - setSelect([]); - mutate((prev) => ({ - data: prev.data.filter((item) => !select.includes(item.id)), - pagination: prev.pagination, - })); - }; - const { trigger: updateStatus } = useSWRMutation( `/comments/`, ( @@ -85,16 +75,6 @@ export const CommentsPage: BasicPage = () => { } ); - const handleUpdateStatus = (status: number) => { - select.forEach((item) => { - updateStatus({ - item, - status, - }); - }); - handleDelete(); - }; - return ( <> {/* */} @@ -146,12 +126,9 @@ export const CommentsPage: BasicPage = () => { - {showEditModal && ( + {showModal && ( { mutate((prev) => ({ data: comments.data,