|
@@ -1,55 +1,46 @@
|
|
|
"use client";
|
|
|
-import { GlobalNoticeRep, updateGlobalNoticeApi, updateUserNoticeApi } from "@/api/home";
|
|
|
+import { GlobalNoticeRep } from "@/api/home";
|
|
|
import Box from "@/components/Box";
|
|
|
import Empty from "@/components/Empty";
|
|
|
import { timeFormat } from "@/utils/methods";
|
|
|
import { Badge, Collapse } from "antd-mobile";
|
|
|
import { useLocale } from "next-intl";
|
|
|
-import { useState } from "react";
|
|
|
import style from "./style.module.scss";
|
|
|
interface Props {
|
|
|
data: GlobalNoticeRep[];
|
|
|
type: "system" | "user";
|
|
|
+ handler: (active: string, key: Props["type"]) => void;
|
|
|
}
|
|
|
const SystemMessage = (props: Props) => {
|
|
|
- const { data, type } = props;
|
|
|
+ const { data, type, handler } = props;
|
|
|
const locale = useLocale();
|
|
|
- const [noticesData, setNoticesData] = useState<GlobalNoticeRep[]>(data);
|
|
|
|
|
|
- const collapseChange = (active: string | null) => {
|
|
|
+ const collapseChange = async (active: string | null) => {
|
|
|
if (!active) return;
|
|
|
- const isRead = noticesData.find((item) => item.id === +active)?.is_read;
|
|
|
- if (isRead) return;
|
|
|
- const newNotices = noticesData.map((item) => {
|
|
|
- if (item.id === +active && !item.is_read) {
|
|
|
- return { ...item, is_read: true };
|
|
|
- } else {
|
|
|
- return item;
|
|
|
- }
|
|
|
- });
|
|
|
- if (type === "system") {
|
|
|
- updateGlobalNoticeApi(+active).then((r) => {});
|
|
|
- } else {
|
|
|
- updateUserNoticeApi(+active);
|
|
|
- }
|
|
|
- setNoticesData(newNotices);
|
|
|
+ handler && handler(active, type);
|
|
|
};
|
|
|
- if (!noticesData.length) return <Empty />;
|
|
|
+ if (!data.length) return <Empty />;
|
|
|
return (
|
|
|
<div className={style.messageCollapse}>
|
|
|
<Collapse accordion onChange={collapseChange}>
|
|
|
- {noticesData.map((notice, index) => (
|
|
|
+ {data.map((notice, index) => (
|
|
|
<Collapse.Panel
|
|
|
key={`${notice.id}`}
|
|
|
+ arrowIcon={
|
|
|
+ <div>
|
|
|
+ <Badge
|
|
|
+ className={`mr-[0.1rem] h-[0.06rem] w-[0.06rem]`}
|
|
|
+ style={{ "--color": "#ff311b" }}
|
|
|
+ content={!notice.is_read ? Badge.dot : ""}
|
|
|
+ ></Badge>
|
|
|
+
|
|
|
+ <span className={"iconfont icon-zhankai"} />
|
|
|
+ </div>
|
|
|
+ }
|
|
|
title={
|
|
|
<section>
|
|
|
<header className={"flex items-center"}>
|
|
|
<h6 className={""}>{notice.content?.title}</h6>
|
|
|
- <Badge
|
|
|
- className={`ml-[0.1rem] h-[0.06rem] w-[0.06rem]`}
|
|
|
- style={{ "--color": "#ff311b" }}
|
|
|
- content={!notice.is_read ? Badge.dot : ""}
|
|
|
- ></Badge>
|
|
|
</header>
|
|
|
<p className={"text-[12px] text-[#64676d]"}>
|
|
|
{notice.send_time
|