Commit 48808e81 by Liu

fix:用户中心隐藏收藏

parent bb6b1466
import { Button, Tooltip } from '@heroui/react'
import { useMemo, useRef, useState } from 'react'
import { useLocation } from 'react-router-dom'
import { useDebounceFn } from 'ahooks'
import type { Answer } from '@/types/chat'
import LikeIcon from '@/assets/svg/zan.svg?react'
......@@ -19,9 +18,7 @@ interface ChatAnswerOperateProps {
}
export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer }) => {
const showToast = useToast()
const location = useLocation()
const searchParams = new URLSearchParams(location.search)
// 路由未携带 from=tactics 时,兜底读取缓存的 tacticsMeta
// 兜底读取缓存的 tacticsMeta(会话从 tactics 打开的元信息)
const tacticsMetaFromStorage = useMemo(() => {
const raw = sessionStorage.getItem('tacticsMeta')
if (!raw)
......@@ -34,7 +31,22 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer })
}
}, [])
const isFromTactics = searchParams.get('from') === 'tactics' || tacticsMetaFromStorage?.from === 'tactics'
// 兜底读取缓存的 userMeta(会话从用户视角打开的元信息)
const userMetaFromStorage = useMemo(() => {
const raw = sessionStorage.getItem('userMeta')
if (!raw)
return undefined
try {
return JSON.parse(raw)
}
catch {
return undefined
}
}, [])
// 规则:当 sessionStorage 中存在 userMeta 或 tacticsMeta 时,统一隐藏收藏按钮
const shouldHideCollect = !!userMetaFromStorage || !!tacticsMetaFromStorage
const [isCollect, setIsCollect] = useState(answer.collectionFlag)
const [isLike, setIsLike] = useState(answer.feedbackStatus === '01')
const [isUnLike, setIsUnLike] = useState(answer.feedbackStatus === '02')
......@@ -153,8 +165,8 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer })
<Tooltip color="foreground" content="复制" className="capitalize">
<Button variant="light" isIconOnly aria-label="CopyIcon" onPress={handleCopy}><CopyIcon /></Button>
</Tooltip>
{/* 收藏(当路由未标记 from=tactics 时不展示) */}
{!isFromTactics && (
{/* 收藏(当路由未标记 from=tactics 且不存在 userMeta 缓存时才展示) */}
{!shouldHideCollect && (
<Tooltip color="foreground" content={isCollect ? '取消收藏' : '收藏'} className="capitalize">
<Button variant="light" isIconOnly aria-label="CollectIcon" onPress={handleCollect.run}>
{isCollect ? <CollectIconA /> : <CollectIcon />}
......
......@@ -600,7 +600,7 @@ export const TacticsChat: React.FC = () => {
const hasUserMeta = !!userMeta
if (hasUserMeta) {
const mappedNumberType = getNumberTypeWithUserMeta('A02', true)
await handleSubmitQuestion('策略分析', undefined, undefined, {
await handleSubmitQuestion(undefined, undefined, undefined, {
busiType: '02',
recordType: mappedNumberType,
includeQuestion: false,
......@@ -609,7 +609,7 @@ export const TacticsChat: React.FC = () => {
})
}
else {
await handleSubmitQuestion('策略分析', undefined, undefined, {
await handleSubmitQuestion(undefined, undefined, undefined, {
busiType: '02',
recordType: 'A01',
includeQuestion: false,
......@@ -679,7 +679,7 @@ export const TacticsChat: React.FC = () => {
if (hasUserMeta) {
const mappedNumberType = getNumberTypeWithUserMeta('A02', true)
handleSubmitQuestion(
'策略分析',
undefined,
undefined,
undefined,
{
......@@ -693,7 +693,7 @@ export const TacticsChat: React.FC = () => {
}
else {
handleSubmitQuestion(
'策略分析',
undefined,
undefined,
undefined,
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment