MOBILE-3833 core: Fix empty split views updates

main
Noel De Martin 2022-01-12 14:02:37 +01:00
parent ce7880afc3
commit 4cdcb23d97
2 changed files with 37 additions and 11 deletions

View File

@ -123,7 +123,13 @@ export class CoreListItemsManager<
* *
* @param item Item. * @param item Item.
*/ */
async select(item: Item): Promise<void> { async select(item: Item | null): Promise<void> {
if (!item) {
await this.navigateToIndex({ reset: this.resetNavigation() });
return;
}
await this.navigateToItem(item, { reset: this.resetNavigation() }); await this.navigateToItem(item, { reset: this.resetNavigation() });
} }
@ -174,17 +180,9 @@ export class CoreListItemsManager<
protected updateSelectedItem(route: ActivatedRouteSnapshot | null = null): void { protected updateSelectedItem(route: ActivatedRouteSnapshot | null = null): void {
super.updateSelectedItem(route); super.updateSelectedItem(route);
if (CoreScreen.isMobile || this.selectedItem !== null || !this.splitView || this.splitView.isNested) { const selectDefault = CoreScreen.isTablet && this.selectedItem === null && this.splitView && !this.splitView.isNested;
return;
}
const defaultItem = this.getDefaultItem(); this.select(selectDefault ? this.getDefaultItem() : this.selectedItem);
if (!defaultItem) {
return;
}
this.select(defaultItem);
} }
/** /**

View File

@ -119,6 +119,34 @@ export abstract class CoreRoutedItemsManager<
await CoreNavigator.navigate(pathPrefix + itemPath, { params, ...options }); await CoreNavigator.navigate(pathPrefix + itemPath, { params, ...options });
} }
/**
* Navigate to the index page.
*
* @param options Navigation options.
*/
protected async navigateToIndex(
options: Pick<CoreNavigationOptions, 'reset' | 'replace' | 'animationDirection'> = {},
): Promise<void> {
// Get current route in the page.
const route = this.getCurrentPageRoute();
if (route === null) {
return;
}
// If the current page is already the index, do nothing.
const selectedItemPath = this.getSelectedItemPath(route.snapshot);
if (selectedItemPath === null) {
return;
}
// Navigate to index.
const indexPath = selectedItemPath ? selectedItemPath.split('/').fill('../').join('') : '';
await CoreNavigator.navigate(indexPath, options);
}
/** /**
* @inheritdoc * @inheritdoc
*/ */