@@ -13,8 +13,10 @@ import type { OutlineManager } from '../outline/manager'
1313import { getFolderPaneForStorage , getProfilePaneFromURI , getSocialPaneFromURI , type PaneItem } from '../utils/paneUtils'
1414import { setNavbarHidden } from './navbarVisibility'
1515import { readNavigationState , type NavigationState , type NavigationView } from './state'
16- import type { NavigationSource } from './options'
16+ import type { FolderView , NavigationSource } from './options'
1717import { isWebIdUri } from '../utils/webIdUtils'
18+ import { deriveStorageView } from './chrome'
19+ import { getPodContext , isInViewerPod , type PodContext } from './podContext'
1820
1921export type NavigationIntent =
2022 /** Display what the current history entry says was displayed, for the page's own URL. */
@@ -42,6 +44,8 @@ export interface NavigationDeps {
4244 outliner : OutlineManager
4345 byName : ( name : string ) => PaneDefinition | null | undefined
4446 effects : NavigationEffects
47+ /** Whose pod a URL is in; `getPodContext` unless a test supplies its own. */
48+ podContextOf ?: ( url : string ) => Promise < PodContext >
4549}
4650
4751export interface NavigationController {
@@ -55,9 +59,28 @@ export interface NavigationController {
5559type DisplayedPane = PaneItem | PaneDefinition | null | undefined
5660
5761export function createNavigationController ( deps : NavigationDeps ) : NavigationController {
58- const { store, outliner, byName, effects } = deps
62+ const { store, outliner, byName, effects, podContextOf = getPodContext } = deps
5963 let latest = 0
6064
65+ /** The storage pane for a page that is a storage of its pod, or the server root. */
66+ async function storageAt ( subject : NamedNode ) : Promise < PaneItem | null | undefined > {
67+ if ( ! subject . uri . endsWith ( '/' ) ) return undefined
68+ const isServerRoot = subject . site ( ) . uri === subject . uri
69+ const { storagePanes, viewerStorages } = await podContextOf ( subject . uri )
70+ const isStorage = storagePanes . some ( pane => pane . subject . uri === subject . uri ) ||
71+ viewerStorages . includes ( subject . uri )
72+ return isServerRoot || isStorage ? getFolderPaneForStorage ( subject ) : undefined
73+ }
74+
75+ async function folderViewFor ( storage : string , viaAccountMenu : boolean ) : Promise < FolderView > {
76+ const context = viaAccountMenu ? undefined : await podContextOf ( storage )
77+ return deriveStorageView ( {
78+ viaAccountMenu,
79+ inViewerPod : ! ! context && isInViewerPod ( context , storage ) ,
80+ hasOwner : ! ! context ?. owner
81+ } )
82+ }
83+
6184 async function paneForView ( subject : NamedNode , view : NavigationView ) : Promise < DisplayedPane > {
6285 // These panes render a subject other than the page URL.
6386 if ( view . subject ) {
@@ -67,7 +90,8 @@ export function createNavigationController (deps: NavigationDeps): NavigationCon
6790 if ( view . kind === 'storage' ) return getFolderPaneForStorage ( paneSubject )
6891 }
6992 if ( view . pane ) return byName ( view . pane ) ?? undefined
70- return isWebIdUri ( subject ) ? getProfilePaneFromURI ( subject , byName ) : undefined
93+ // With nothing recorded, the URL decides: a WebID shows its profile, a storage its storage view
94+ return isWebIdUri ( subject ) ? getProfilePaneFromURI ( subject , byName ) : storageAt ( subject )
7195 }
7296
7397 async function paneFor ( intent : NavigationIntent , subject : NamedNode , state : NavigationState ) : Promise < DisplayedPane > {
@@ -101,7 +125,11 @@ export function createNavigationController (deps: NavigationDeps): NavigationCon
101125 return
102126 }
103127
104- outliner . GotoSubject ( subject , true , pane ?? undefined , true , undefined , undefined , { source } )
128+ const storage = pane && pane . name === 'folder' ? ( pane as PaneItem ) . subject ?. uri : undefined
129+ const folderView = storage ? await folderViewFor ( storage , source === 'accountMenu' ) : undefined
130+ if ( request !== latest ) return
131+
132+ outliner . GotoSubject ( subject , true , pane ?? undefined , true , undefined , undefined , folderView ? { source, folderView } : { source } )
105133
106134 if ( source !== 'accountMenu' ) {
107135 const { view } = readNavigationState ( )
0 commit comments