Files
marco/app/templates/application.gjs
T
raucao c56917e122 WIP: Stack parent sheets behind the mobile bottom drawer
Derive the sheet stack from the URL instead of mutating it: the route
template keeps rendering the top sheet, and application.gjs renders the
service-driven parent (search results, lists index, app menu) behind it on
mobile, inert, so closing the top sheet reveals the parent at its
remembered size.

- bottom-sheet modifier: `background` arg — background instances settle
  immediately, inject no handle, take no gestures, never own the inset slot,
  and never write the remembered detent (restore-only).
- z-index: demote background sheets below the top sheet, including the app
  menu whose desktop z-index was inverted.
- outside tap on mobile pops to the parent without hideSidebar(), keeping
  the session and detent alive; desktop keeps today's close-all.
- tracked matchMedia-backed viewport service for the mobile breakpoint.
- lists index extracted into a component so it can render top or background.
- scope .sidebar-content lookups and test selectors to .sheet-top.

Known v1 limitation: popping hard-cuts to the parent route (no exit
animation). The full derived stack with independent detents for 3-level
chains is deferred.
2026-11-30 15:17:20 +04:00

149 lines
4.1 KiB
Plaintext

import Component from '@glimmer/component';
import { pageTitle } from 'ember-page-title';
import Map from '#components/map';
import AppHeader from '#components/app-header';
import Toast from '#components/toast';
import BackgroundSheets from '#components/background-sheets';
import { service } from '@ember/service';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { parentTransitionFor } from '../utils/sheet-parent';
export default class ApplicationComponent extends Component {
@service storage;
@service mapUi;
@service router;
@service viewport;
get isSidebarOpen() {
// We consider the sidebar "open" if we are in search, menu, lists, contributions or place routes AND it's visible.
// This helps the map know if it should shift the center or adjust view.
const name = this.router.currentRouteName;
return (
this.mapUi.isSidebarVisible &&
(name === 'place' ||
name === 'place.new' ||
name === 'search' ||
name === 'menu' ||
name === 'contributions' ||
name === 'activity' ||
name.startsWith('lists'))
);
}
constructor() {
super(...arguments);
console.debug('Application component constructed');
// Access the service to ensure it is instantiated
this.storage;
}
@action
toggleAppMenu() {
if (this.router.currentRouteName === 'menu') {
this.router.transitionTo('index');
} else {
this.router.transitionTo('menu');
}
}
@action
handleOutsideClick() {
const name = this.router.currentRouteName;
const isSheetRoute =
name === 'search' ||
name === 'place' ||
name === 'menu' ||
name === 'contributions' ||
name === 'activity' ||
name.startsWith('lists');
if (!isSheetRoute) return;
this.mapUi.clearSelection();
// Mobile: pop to the parent sheet and keep the session (and its remembered
// detent) alive, so the parent is revealed underneath instead of the whole
// stack being torn down. Routes with no parent fall through to close-all.
if (this.viewport.isMobile) {
const parent = parentTransitionFor(name, this.mapUi);
if (parent) {
this.transitionToParent(parent);
return;
}
}
// Desktop, or a mobile route with no parent: today's close-all.
this.mapUi.hideSidebar();
if (
name === 'menu' ||
name === 'contributions' ||
name === 'activity' ||
name.startsWith('lists')
) {
this.router.transitionTo('index');
} else if (name === 'place') {
if (this.mapUi.returnToSearch && this.mapUi.currentSearch) {
this.router.transitionTo('search', {
queryParams: this.mapUi.currentSearch,
});
} else {
this.router.transitionTo('index');
}
} else if (name === 'search' && this.mapUi.searchResults.length === 0) {
// An empty search has no markers worth keeping, so clear the route
this.router.replaceWith('index');
}
}
transitionToParent(parent) {
if (parent.model !== undefined) {
this.router.transitionTo(parent.name, parent.model);
} else if (parent.queryParams) {
this.router.transitionTo(parent.name, {
queryParams: parent.queryParams,
});
} else {
this.router.transitionTo(parent.name);
}
}
@action
refreshBookmarks() {
this.storage.notifyChange();
}
<template>
{{pageTitle "Marco"}}
<div class={{if this.mapUi.isSidebarOpening "sidebar-opening"}}>
<AppHeader @onToggleMenu={{this.toggleAppMenu}} />
<div
id="rs-widget-container"
class={{if this.storage.isWidgetOpen "visible"}}
></div>
{{#if this.storage.isWidgetOpen}}
<div
class="rs-backdrop"
role="button"
{{on "click" this.storage.closeWidget}}
></div>
{{/if}}
<Map
@isSidebarOpen={{this.isSidebarOpen}}
@onOutsideClick={{this.handleOutsideClick}}
/>
<Toast />
{{! Rendered before the outlet so the top sheet paints above it. }}
<BackgroundSheets @isMobile={{this.viewport.isMobile}} />
{{outlet}}
</div>
</template>
}