Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(热点): 1. 处理爆款标题国际化。 2. 修复爆款标题label在“全部”切换日期不会刷新数据的bug
gaoSir2693dccbb22e
diff --git a/@types/resources.d.ts b/@types/resources.d.tsindex 1202b823..c6d8bdd3 100644--- a/@types/resources.d.ts+++ b/@types/resources.d.ts@@ -742,7 +742,9 @@ interface Resources {"last3days": "近3天","last7days": "近7天","last15days": "近15天",- "last30days": "近30天"+ "last30days": "近30天",+ "backToAll": "返回全部",+ "last90days": "近90天"},"income": {"title": "我的收入",diff --git a/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx b/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsxindex 3875d689..ae749aa1 100644--- a/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx+++ b/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx@@ -7,43 +7,7 @@ import { Table, type TableProps, Typography } from "antd";import hotEventStyles from "../../HotEvent/hotEvent.module.scss";import hotContentStyles from "../../HotContent/hotContent.module.scss";import { describeNumber } from "@/utils";--const columns: TableProps<ViralTitle>["columns"] = [- {- title: "排名",- width: 50,- render: (text, data, ind) => (- <>- {ind <= 2 ? (- <div- className={hotContentStyles.rankingTopthree}- style={{ width: "20px", height: "20px", lineHeight: "20px" }}- >- {ind + 1}- </div>- ) : (- <p style={{ width: "20px", textAlign: "center" }}>{ind + 1}</p>- )}- </>- ),- },- {- title: "爆款标题",- render: (text, data, ind) => (- <div className="hotTitleItem-title">- <Typography.Paragraph copyable={{ text: data.title }}>- {data.title}- </Typography.Paragraph>- </div>- ),- },- {- title: "互动量",- width: 100,- align: "center",- render: (text, data, ind) => <>{describeNumber(data.engagement)}</>,- },-];+import { useTransClient } from "@/app/i18n/client";export const HotTitleItem = ({data,@@ -61,6 +25,44 @@ export const HotTitleItem = ({style?: CSSProperties;headRightElement?: React.ReactNode;}) => {+ const { t } = useTransClient("hot-content");+ const columns: TableProps<ViralTitle>["columns"] = [+ {+ title: t("rank"),+ width: 50,+ render: (text, data, ind) => (+ <>+ {ind <= 2 ? (+ <div+ className={hotContentStyles.rankingTopthree}+ style={{ width: "20px", height: "20px", lineHeight: "20px" }}+ >+ {ind + 1}+ </div>+ ) : (+ <p style={{ width: "20px", textAlign: "center" }}>{ind + 1}</p>+ )}+ </>+ ),+ },+ {+ title: t("viralTitles"),+ render: (text, data, ind) => (+ <div className="hotTitleItem-title">+ <Typography.Paragraph copyable={{ text: data.title }}>+ {data.title}+ </Typography.Paragraph>+ </div>+ ),+ },+ {+ title: t("engagement"),+ width: 100,+ align: "center",+ render: (text, data, ind) => <>{describeNumber(data.engagement)}</>,+ },+ ];+return (<div className={styles.hotTitleItem + " hotTitleItem"} style={style}><div className="hotTitleItem-head">diff --git a/src/app/[lng]/hotContent/components/HotTitle/index.tsx b/src/app/[lng]/hotContent/components/HotTitle/index.tsxindex 25d82a6f..1a6b0715 100644--- a/src/app/[lng]/hotContent/components/HotTitle/index.tsx+++ b/src/app/[lng]/hotContent/components/HotTitle/index.tsx@@ -44,7 +44,11 @@ const HotTitle = memo(const labelAll = useRef<string>(t("all"));// 当前选中的标签const [labelValue, setLabelValue] = useState(labelAll.current);- const allDates = useRef(["近7天", "近30天", "近90天"]);+ const allDates = useRef<string[]>([+ t("last7days"),+ t("last30days"),+ t("last90days"),+ ]);// 当前选择的日期范围const [currDate, setCurrDate] = useState(allDates.current[0]);const [loading, setLoading] = useState(false);@@ -73,41 +77,59 @@ const HotTitle = memo(};}, [labelData, rankingData, twoMenuKey, currentRankCategory]);+ const dateValue = useMemo(() => {+ return currDate === t("last7days")+ ? "近7天"+ : currDate === t("last30days")+ ? "近30天"+ : currDate === t("last90days")+ ? "近90天"+ : "";+ }, [currDate]);+// 获取所有爆款数据const getAllData = useCallback(async () => {+ if (labelValue !== labelAll.current) return;+setLoading(true);const res = await platformApi.findTopByPlatformAndCategories(selectedLabelInfo.platId,- currDate,+ dateValue,);setLoading(false);setAllHotTitleData(res?.data);- }, [currDate, selectedLabelInfo.platId]);+ }, [dateValue, selectedLabelInfo.platId]);// 获取爆款数据详情const getDetailData = useCallback(async () => {if (labelValue === labelAll.current) return;+setLoading(true);const res = await platformApi.findByPlatformAndCategory(selectedLabelInfo.platId,{- category: labelValue === labelAll.current ? "全部" : labelValue,+ category: labelValue === labelAll.current ? t("all") : labelValue,page: 1,- timeType: currDate,+ timeType: dateValue,pageSize: 50,},);setHotTitleData(res?.data.items || []);setLoading(false);- }, [labelValue, currDate, selectedLabelInfo.ranking.id]);+ }, [+ labelValue,+ dateValue,+ selectedLabelInfo.ranking.id,+ selectedLabelInfo.platId,+ ]);useEffect(() => {getAllData();- }, [twoMenuKey]);+ }, [twoMenuKey, dateValue]);useEffect(() => {getDetailData();- }, [labelValue, currDate]);+ }, [labelValue, dateValue]);return (<div className={styles.hotTitle}>@@ -145,7 +167,7 @@ const HotTitle = memo(onBottomLinkClick={() => {setLabelValue(v.category);}}- bottomLinkText="查看更多"+ bottomLinkText={t("viewMore")}/>);})}@@ -166,7 +188,7 @@ const HotTitle = memo(setLabelValue(labelAll.current);}}>- 返回全部+ {t("backToAll")}</a></>}@@ -179,7 +201,7 @@ const HotTitle = memo(onBottomLinkClick={() => {setLabelValue(labelAll.current);}}- bottomLinkText="收起"+ bottomLinkText={t("collapse")}/></div></Spin>diff --git a/src/app/i18n/locales/en/hot-content.json b/src/app/i18n/locales/en/hot-content.jsonindex 6aad72dc..ca82c129 100644--- a/src/app/i18n/locales/en/hot-content.json+++ b/src/app/i18n/locales/en/hot-content.json@@ -54,5 +54,7 @@"last3days": "Last 3 days","last7days": "Last 7 days","last15days": "Last 15 days",- "last30days": "Last 30 days"+ "last30days": "Last 30 days",+ "backToAll": "Back to All",+ "last90days": "Last 90 days"}diff --git a/src/app/i18n/locales/zh-CN/hot-content.json b/src/app/i18n/locales/zh-CN/hot-content.jsonindex 5b94ac48..ae41ffc2 100644--- a/src/app/i18n/locales/zh-CN/hot-content.json+++ b/src/app/i18n/locales/zh-CN/hot-content.json@@ -54,5 +54,7 @@"last3days": "近3天","last7days": "近7天","last15days": "近15天",- "last30days": "近30天"+ "last30days": "近30天",+ "backToAll": "返回全部",+ "last90days": "近90天"}