refactor(components): 重构碘搜索相关组件

- 优化 IodRelevant 组件中的加载状态和计数器动画
- 重构 PlaygroundIod 组件,使用新的 PlaygroundIodProvider 组件
- 改进 Context 提供的数据结构,使用更准确的命名
This commit is contained in:
zhaoweijie 2025-08-24 13:04:43 +08:00
parent cb6c3c225b
commit f9763778fa
2 changed files with 35 additions and 19 deletions

View File

@ -235,25 +235,28 @@ export const PlaygroundIodRelevant: React.FC<Props> = ({ className }) => {
(message) => message.id === currentMessageId (message) => message.id === currentMessageId
) )
const text = (iodSearch && iodLoading) ? '正' : '已' const loading = (iodSearch && iodLoading)
const text2 = (iodSearch && iodLoading) ? '进行' : '完成' const text = loading ? '正' : '已'
const text3 = (iodSearch && iodLoading) ? '……' : '' const text2 = loading ? '进行' : '完成'
const text3 = loading ? '……' : ''
const duration = loading ? 2.5 : 0
return [ return [
{ {
title: ( title: (
<p className="font-extrabold"> <p className="font-extrabold">
{text} {text}
<span className="text-[#f00000]"> <span className="text-[#f00000]">
<CountUp end={29} duration={2.5} separator="," /> <CountUp end={29} duration={duration} separator="," />
</span> </span>
<span className="text-[#f00000]"> <span className="text-[#f00000]">
{" "} {" "}
<CountUp end={55} duration={2.5} separator="," /> <CountUp end={55} duration={duration} separator="," />
</span> </span>
<span className="text-[#f00000]"> <span className="text-[#f00000]">
<CountUp decimals={1} end={53.7} duration={2.5} separator="," /> <CountUp decimals={1} end={53.7} duration={duration} separator="," />
</span> </span>
{text2}{text3} {text2}{text3}
@ -282,12 +285,12 @@ export const PlaygroundIodRelevant: React.FC<Props> = ({ className }) => {
<p className="font-extrabold"> <p className="font-extrabold">
{text} {text}
<span className="text-[#f00000]"> <span className="text-[#f00000]">
<CountUp end={138} duration={2.5} separator="," /> <CountUp end={138} duration={duration} separator="," />
</span> </span>
<span className="text-[#f00000]"> <span className="text-[#f00000]">
<CountUp end={18.3} decimals={1} duration={2.5} separator="," /> <CountUp end={18.3} decimals={1} duration={duration} separator="," />
</span> </span>
{text2}{text3} {text2}{text3}
@ -316,17 +319,17 @@ export const PlaygroundIodRelevant: React.FC<Props> = ({ className }) => {
<p className="font-extrabold"> <p className="font-extrabold">
{text} {text}
<span className="text-[#f00000]"> <span className="text-[#f00000]">
<CountUp end={763} duration={2.5} separator="," /> <CountUp end={763} duration={duration} separator="," />
</span> </span>
<span className="text-[#f00000]"> <span className="text-[#f00000]">
{" "} {" "}
<CountUp end={2.1} decimals={1} duration={2.5} separator="," /> <CountUp end={2.1} decimals={1} duration={duration} separator="," />
</span> </span>
<span className="text-[#f00000]"> <span className="text-[#f00000]">
{" "} {" "}
<CountUp end={2} duration={2.5} separator="," /> <CountUp end={2} duration={duration} separator="," />
</span> </span>
{text2}{text3} {text2}{text3}
</p> </p>

View File

@ -19,7 +19,7 @@ interface IodPlaygroundContextType {
setDetailHeader: React.Dispatch<React.SetStateAction<React.ReactNode>> setDetailHeader: React.Dispatch<React.SetStateAction<React.ReactNode>>
detailMain: React.ReactNode detailMain: React.ReactNode
setDetailMain: React.Dispatch<React.SetStateAction<React.ReactNode>> setDetailMain: React.Dispatch<React.SetStateAction<React.ReactNode>>
currentMessage: Message | null currentIodMessage: Message | null
} }
// 创建 Context // 创建 Context
@ -38,7 +38,9 @@ export const useIodPlaygroundContext = () => {
return context return context
} }
export const PlaygroundIod = () => { const PlaygroundIodProvider: React.FC<{ children: React.ReactNode }> = ({
children
}) => {
const { messages, iodLoading, currentMessageId, iodSearch } = const { messages, iodLoading, currentMessageId, iodSearch } =
useMessageOption() useMessageOption()
@ -46,7 +48,7 @@ export const PlaygroundIod = () => {
const [detailHeader, setDetailHeader] = useState(<></>) const [detailHeader, setDetailHeader] = useState(<></>)
const [detailMain, setDetailMain] = useState(<></>) const [detailMain, setDetailMain] = useState(<></>)
const currentMessage = useMemo<Message | null>(() => { const currentIodMessage = useMemo<Message | null>(() => {
if (iodLoading) { if (iodLoading) {
return null return null
} }
@ -73,7 +75,7 @@ export const PlaygroundIod = () => {
return ( return (
<PlaygroundContext.Provider <PlaygroundContext.Provider
value={{ value={{
currentMessage, currentIodMessage,
showPlayground, showPlayground,
setShowPlayground, setShowPlayground,
detailMain, detailMain,
@ -81,9 +83,7 @@ export const PlaygroundIod = () => {
detailHeader, detailHeader,
setDetailHeader setDetailHeader
}}> }}>
<div className="w-[36%] h-full pt-16 pr-5 pb-0"> {children}
<PlaygroundContent />
</div>
</PlaygroundContext.Provider> </PlaygroundContext.Provider>
) )
} }
@ -111,7 +111,9 @@ const PlaygroundContent = () => {
className="h-full grid grid-rows-12 gap-3"> className="h-full grid grid-rows-12 gap-3">
<div className="w-full row-span-5"> <div className="w-full row-span-5">
<PlaygroundIodRelevant <PlaygroundIodRelevant
className={classNames.replace("!bg-[rgba(240,245,255,0.3)]", "").replace("shadow-xl", "")} className={classNames
.replace("!bg-[rgba(240,245,255,0.3)]", "")
.replace("shadow-xl", "")}
/> />
</div> </div>
<div className="w-full row-span-4 grid grid-cols-2 gap-3 custom-scrollbar"> <div className="w-full row-span-4 grid grid-cols-2 gap-3 custom-scrollbar">
@ -151,3 +153,14 @@ const PlaygroundContent = () => {
</AnimatePresence> </AnimatePresence>
) )
} }
export const PlaygroundIod = () => {
return (
<div className="w-[36%] h-full pt-16 pr-5 pb-0">
<PlaygroundIodProvider>
<PlaygroundContent />
</PlaygroundIodProvider>
</div>
)
}