import { type ActionType, ProList } from "@ant-design/pro-components"; import { Avatar, Button, Space, Switch, Tag, Typography } from "antd"; import { ReloadOutlined } from "@ant-design/icons"; import { get, put } from "../../request"; import type { INotificationListResponse, INotificationPutResponse, INotificationRequest, } from "../../api/notification"; import type { IUser } from "../auth/User"; import TimeShow from "../general/TimeShow"; import { useEffect, useRef, useState } from "react"; import Marked from "../general/Marked"; import type { IChannel } from "../channel/Channel"; const { Text } = Typography; interface INotification { id: string; from: IUser; to: IUser; channel: IChannel; url?: string; title?: string; book_title?: string; content?: string; content_type: string; res_type: string; res_id: string; status: string; deleted_at?: string; created_at: string; updated_at: string; } interface IWidget { onChange?: Function; } const NotificationListWidget = ({ onChange }: IWidget) => { const ref = useRef(null); const [activeKey, setActiveKey] = useState("inbox"); const [mute, setMute] = useState(false); useEffect(() => { const mute = localStorage.getItem("notification/mute"); if (mute && mute === "true") { setMute(true); } else { setMute(false); } }, []); const putStatus = (id: string, status: string) => { const url = `/v2/notification/${id}`; console.info("api request", url); put(url, { status: status, }).then((json) => { console.info("api response", json); if (json.ok) { ref.current?.reload(); if (typeof onChange !== "undefined") { onChange(json.data.unread); } } }); }; return ( rowKey="id" actionRef={ref} onItem={(record: INotification, _index: number) => { return { onClick: (_event) => { // 点击行 if (record.status === "unread") { putStatus(record.id, "read"); } }, }; }} toolBarRender={() => { return [ <> {"免打扰"} { setMute(checked); if (checked) { localStorage.setItem("notification/mute", "true"); } else { localStorage.setItem("notification/mute", "false"); } }} /> ,