fix(skill): use nuqs query state for fileId param

This commit is contained in:
yyh 2026-02-06 16:03:32 +08:00
parent d3b32645f4
commit 287c1bbc35
No known key found for this signature in database

View File

@ -1,6 +1,6 @@
'use client' 'use client'
import { useSearchParams } from 'next/navigation' import { parseAsString, useQueryState } from 'nuqs'
import * as React from 'react' import * as React from 'react'
import { useStore as useAppStore } from '@/app/components/app/store' import { useStore as useAppStore } from '@/app/components/app/store'
import { useStore, useWorkflowStore } from '@/app/components/workflow/store' import { useStore, useWorkflowStore } from '@/app/components/workflow/store'
@ -33,17 +33,16 @@ const ContentRouter = () => {
const SkillMain = () => { const SkillMain = () => {
const appDetail = useAppStore(s => s.appDetail) const appDetail = useAppStore(s => s.appDetail)
const appId = appDetail?.id || '' const appId = appDetail?.id || ''
const searchParams = useSearchParams() const [queryFileId] = useQueryState('fileId', parseAsString)
const storeApi = useWorkflowStore() const storeApi = useWorkflowStore()
const openedFileRef = React.useRef<string | null>(null) const openedFileRef = React.useRef<string | null>(null)
React.useEffect(() => { React.useEffect(() => {
const fileId = searchParams.get('fileId') if (!queryFileId || openedFileRef.current === queryFileId)
if (!fileId || openedFileRef.current === fileId)
return return
openedFileRef.current = fileId openedFileRef.current = queryFileId
storeApi.getState().openTab(fileId, { pinned: true }) storeApi.getState().openTab(queryFileId, { pinned: true })
}, [searchParams, storeApi]) }, [queryFileId, storeApi])
return ( return (
<div className="h-full bg-workflow-canvas-workflow-top-bar-1 pl-3 pt-[52px]"> <div className="h-full bg-workflow-canvas-workflow-top-bar-1 pl-3 pt-[52px]">