@@ -2,7 +2,7 @@ import Header from "@/components/welcome/header"
22import Footer from "@/components/welcome/footer" ;
33import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar" ;
44import dayjs from "dayjs" ;
5- import { useEffect , useState } from "react" ;
5+ import { useCallback , useEffect , useState } from "react" ;
66import { useSearchParams } from "react-router-dom" ;
77import { apiRequest } from "@/utils/requestUtils" ;
88import { ConstsPostKind , type DomainPlaygroundPost } from "@/api/Api" ;
@@ -167,9 +167,20 @@ const PlaygroundDetailPage = () => {
167167
168168 const fileTree = buildTree ( zipFiles ) ;
169169
170+ const fetchPost = useCallback ( async ( ) => {
171+ if ( ! postId ) {
172+ return
173+ }
174+ await apiRequest ( 'v1PlaygroundPostsDetail' , { } , [ postId ] , ( resp ) => {
175+ if ( resp . code === 0 ) {
176+ setPost ( resp . data )
177+ }
178+ } )
179+ } , [ postId ] )
180+
170181 useEffect ( ( ) => {
171182 fetchPost ( )
172- } , [ postId ] )
183+ } , [ fetchPost ] )
173184
174185 useEffect ( ( ) => {
175186 if ( post ?. task_post ?. code ) {
@@ -196,17 +207,6 @@ const PlaygroundDetailPage = () => {
196207 }
197208 } , [ zipFiles ] )
198209
199- const fetchPost = async ( ) => {
200- if ( ! postId ) {
201- return
202- }
203- await apiRequest ( 'v1PlaygroundPostsDetail' , { } , [ postId ] , ( resp ) => {
204- if ( resp . code === 0 ) {
205- setPost ( resp . data )
206- }
207- } )
208- }
209-
210210 const loadZipFile = async ( url : string ) => {
211211 setLoadingZip ( true )
212212 try {
@@ -321,7 +321,11 @@ const PlaygroundDetailPage = () => {
321321 </ div >
322322 { isExpanded && node . children . length > 0 && (
323323 < div >
324- { node . children . map ( child => renderTreeNode ( child , depth + 1 ) ) }
324+ { node . children . map ( child => (
325+ < React . Fragment key = { child . path } >
326+ { renderTreeNode ( child , depth + 1 ) }
327+ </ React . Fragment >
328+ ) ) }
325329 </ div >
326330 ) }
327331 </ div >
@@ -438,7 +442,11 @@ const PlaygroundDetailPage = () => {
438442 </ div >
439443 ) : (
440444 < div className = "flex flex-col pr-3" >
441- { fileTree . map ( node => renderTreeNode ( node , 0 ) ) }
445+ { fileTree . map ( node => (
446+ < React . Fragment key = { node . path } >
447+ { renderTreeNode ( node , 0 ) }
448+ </ React . Fragment >
449+ ) ) }
442450 </ div >
443451 ) }
444452 </ div > }
0 commit comments