@@ -36,7 +36,10 @@ import { captureEvent } from '@/lib/posthog/client'
3636import { persistImportedWorkflow } from '@/lib/workflows/operations/import-export'
3737import { RESOURCE_HEADER_CLASSES } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs/resource-tab-controls'
3838import { resolveWorkspaceResourceRef } from '@/app/workspace/[workspaceId]/home/resolve-resource-ref'
39- import { resolveResourceEventPresentation } from '@/app/workspace/[workspaceId]/home/resource-view-policy'
39+ import {
40+ resolveResourceEventPresentation ,
41+ resolveResourceSelectionUpdate ,
42+ } from '@/app/workspace/[workspaceId]/home/resource-view-policy'
4043import { resourceParam , resourceUrlKeys } from '@/app/workspace/[workspaceId]/home/search-params'
4144import { useFolders } from '@/hooks/queries/folders'
4245import { useMarkMothershipChatRead } from '@/hooks/queries/mothership-chats'
@@ -103,6 +106,8 @@ export function Home({ chatId, userName, userId }: HomeProps) {
103106 ...resourceParam . parser ,
104107 ...resourceUrlKeys ,
105108 } )
109+ const activeResourceParamRef = useRef ( activeResourceParam )
110+ activeResourceParamRef . current = activeResourceParam
106111 /**
107112 * Strips any leftover URL fragment on selection change, preserving the old
108113 * effect's `url.hash = ''` (the only hash usage on this surface) without a
@@ -115,11 +120,13 @@ export function Home({ chatId, userName, userId }: HomeProps) {
115120 */
116121 const setActiveResourceUrl = useCallback < Dispatch < SetStateAction < string | null > > > (
117122 ( action ) => {
123+ const nextResourceId = resolveResourceSelectionUpdate ( activeResourceParamRef . current , action )
124+ activeResourceParamRef . current = nextResourceId
118125 if ( typeof window !== 'undefined' && window . location . hash ) {
119126 const { pathname, search } = window . location
120127 window . history . replaceState ( window . history . state , '' , `${ pathname } ${ search } ` )
121128 }
122- void setResourceParam ( action )
129+ void setResourceParam ( nextResourceId )
123130 } ,
124131 [ setResourceParam ]
125132 )
@@ -213,8 +220,6 @@ export function Home({ chatId, userName, userId }: HomeProps) {
213220 } , [ ] )
214221 const resourceCollapseOwnedByUserRef = useRef ( false )
215222 const resourceSelectionOwnedByUserRef = useRef ( false )
216- const activeResourceParamRef = useRef ( activeResourceParam )
217- activeResourceParamRef . current = activeResourceParam
218223
219224 function handleResourceEvent ( resourceId : string , options ?: ResourceEventOptions ) {
220225 const activeResourceId = activeResourceParamRef . current
0 commit comments