From 92a5e5410d7786d5db762f8e0cc72180c0449975 Mon Sep 17 00:00:00 2001 From: Amiram_se Date: Sat, 10 Oct 2026 12:19:43 +0400 Subject: [PATCH] feat(market): shared web app manifest builder, back to parentHref through history only when it is the previous entry, backToPrevious option Co-Authored-By: Claude Opus 5.5 --- .../market/src/app/manifest/build-manifest.ts | 37 +++++++++++++ .../market/src/app/manifest/constants.ts | 18 +++++++ platforms/market/src/app/manifest/server.ts | 4 ++ platforms/market/src/app/manifest/types.ts | 8 +++ .../market/src/app/navigation/back-target.ts | 34 +++++++++--- .../components/desk-back/DeskBack.tsx | 6 ++- .../desktop-page-title/DesktopPageTitle.tsx | 4 +- .../mobile-top-bar/MobileTopBar.tsx | 6 ++- .../mobile-top-bar/components/BackButton.tsx | 7 +-- .../components/mobile-top-bar/types.ts | 5 +- .../src/app/navigation/hooks/use-back.ts | 54 ++++++++++++++----- platforms/market/src/app/navigation/index.ts | 1 + platforms/market/src/app/navigation/types.ts | 24 ++++++--- .../CreatorProfileEdit.tsx | 10 ++-- .../InvestorProfileForm.tsx | 6 +-- platforms/market/src/server.ts | 2 + 16 files changed, 181 insertions(+), 45 deletions(-) create mode 100644 platforms/market/src/app/manifest/build-manifest.ts create mode 100644 platforms/market/src/app/manifest/constants.ts create mode 100644 platforms/market/src/app/manifest/server.ts create mode 100644 platforms/market/src/app/manifest/types.ts diff --git a/platforms/market/src/app/manifest/build-manifest.ts b/platforms/market/src/app/manifest/build-manifest.ts new file mode 100644 index 0000000..76353e1 --- /dev/null +++ b/platforms/market/src/app/manifest/build-manifest.ts @@ -0,0 +1,37 @@ +import type { MetadataRoute } from 'next'; + +import { ROUTES } from '../navigation/navigation'; +import { + MANIFEST_BACKGROUND_COLOR, + MANIFEST_ICONS, + MANIFEST_THEME_COLOR, +} from './constants'; +import type { ManifestArgs } from './types'; + +/** + * The web app manifest for each app's `app/manifest.ts`. Both apps serve one origin, so they serve + * this same manifest (0053). The installed app opens on خانه, which sends a guest to login and a + * creator to their channel, so it never flashes the landing; `id` keeps the installed app's + * identity if `start_url` changes. + */ +export function buildManifest({ + name, + description, + lang, + dir, +}: ManifestArgs): MetadataRoute.Manifest { + return { + id: '/', + name, + short_name: name, + description, + lang, + dir, + start_url: ROUTES.home, + scope: '/', + display: 'standalone', + background_color: MANIFEST_BACKGROUND_COLOR, + theme_color: MANIFEST_THEME_COLOR, + icons: [...MANIFEST_ICONS], + }; +} diff --git a/platforms/market/src/app/manifest/constants.ts b/platforms/market/src/app/manifest/constants.ts new file mode 100644 index 0000000..f38c896 --- /dev/null +++ b/platforms/market/src/app/manifest/constants.ts @@ -0,0 +1,18 @@ +/** + * The light theme's `--bg-page` and `--action-primary` in island `theme.css`. The manifest can't + * read CSS variables, so a change there changes these too. + */ +export const MANIFEST_BACKGROUND_COLOR = '#f4f6f9'; +export const MANIFEST_THEME_COLOR = '#533afd'; + +/** Placeholders until the brand mark exists; each app's `apple-icon.png` covers iOS. */ +export const MANIFEST_ICONS = [ + { src: '/pwa/icon-192.png', sizes: '192x192', type: 'image/png' }, + { src: '/pwa/icon-512.png', sizes: '512x512', type: 'image/png' }, + { + src: '/pwa/icon-maskable-512.png', + sizes: '512x512', + type: 'image/png', + purpose: 'maskable', + }, +] as const; diff --git a/platforms/market/src/app/manifest/server.ts b/platforms/market/src/app/manifest/server.ts new file mode 100644 index 0000000..f834304 --- /dev/null +++ b/platforms/market/src/app/manifest/server.ts @@ -0,0 +1,4 @@ +import 'server-only'; + +export { buildManifest } from './build-manifest'; +export type { ManifestArgs } from './types'; diff --git a/platforms/market/src/app/manifest/types.ts b/platforms/market/src/app/manifest/types.ts new file mode 100644 index 0000000..d89dadd --- /dev/null +++ b/platforms/market/src/app/manifest/types.ts @@ -0,0 +1,8 @@ +/** The manifest's text, in the app's one locale. */ +export type ManifestArgs = { + /** «لومینا»: the name and the short name. */ + name: string; + description: string; + lang: string; + dir: 'rtl' | 'ltr'; +}; diff --git a/platforms/market/src/app/navigation/back-target.ts b/platforms/market/src/app/navigation/back-target.ts index b32673f..3e4bb97 100644 --- a/platforms/market/src/app/navigation/back-target.ts +++ b/platforms/market/src/app/navigation/back-target.ts @@ -13,11 +13,33 @@ export const backTargetStore = createStore<{ target: BackTarget | null }>()( ); /** - * Whether the page has a page of this site behind it in the tab's history. The Navigation API - * lists only this site's entries in a row, so a page opened from a link, a notification, another - * site or the bank has none; without it, any history counts. + * The key of the previous history entry when back should return to it (0057): `parentHref` itself, + * or, with `toPrevious`, any page of this site. The Navigation API lists only this site's entries, + * so a page opened from a link, a notification, another site or the bank has none; without the + * API there is none either, and back opens `parentHref`. */ -export function hasInAppHistory(): boolean { - const { navigation } = window as { navigation?: { canGoBack: boolean } }; - return navigation ? navigation.canGoBack : window.history.length > 1; +export function previousEntryKey( + parentHref: string, + toPrevious: boolean, +): string | undefined { + if (!('navigation' in window)) return undefined; + const current = navigation.currentEntry; + if (!current || current.index < 1) return undefined; + const previous = navigation.entries()[current.index - 1]; + if (!previous?.url) return undefined; + if (toPrevious) return previous.key; + const from = new URL(previous.url).pathname; + const to = new URL(parentHref, window.location.href).pathname; + return from === to ? previous.key : undefined; +} + +/** + * Goes back to the entry `previousEntryKey` found. By key, so a second press before the first lands + * goes to the same page, never further or out of the site. + */ +export function traverseTo(key: string): void { + const { committed, finished } = navigation.traverseTo(key); + // A newer navigation interrupts it, which is no error. + committed?.catch(() => undefined); + finished?.catch(() => undefined); } diff --git a/platforms/market/src/app/navigation/components/desk-back/DeskBack.tsx b/platforms/market/src/app/navigation/components/desk-back/DeskBack.tsx index 06c7abb..f1ef3e5 100644 --- a/platforms/market/src/app/navigation/components/desk-back/DeskBack.tsx +++ b/platforms/market/src/app/navigation/components/desk-back/DeskBack.tsx @@ -17,8 +17,9 @@ const DESK_BACK_CLASS = /** * «بازگشت» on desktop (R14): its own row at the top of a pushed page's column, above the page's * title. Every page opened from another page has it (an installed app has no browser back); tab - * roots don't. Back goes to the page behind it on this site, or the page's `parentHref` when it was - * opened on its own; a fixed `href` (an auth step, the payment result's channel) is a link. + * roots don't. It links to the page's parent and goes back through history when the parent is the + * page behind (0057); a fixed `href` (an auth step, the payment result's subscriptions) is a plain + * link. */ export function DeskBack({ label, ...options }: DeskBackProps) { const { t } = useTranslation(); @@ -41,6 +42,7 @@ export function DeskBack({ label, ...options }: DeskBackProps) { )} diff --git a/platforms/market/src/app/navigation/components/mobile-top-bar/components/BackButton.tsx b/platforms/market/src/app/navigation/components/mobile-top-bar/components/BackButton.tsx index 4568bcd..5892606 100644 --- a/platforms/market/src/app/navigation/components/mobile-top-bar/components/BackButton.tsx +++ b/platforms/market/src/app/navigation/components/mobile-top-bar/components/BackButton.tsx @@ -6,9 +6,9 @@ import { useBack } from '../../../hooks/use-back'; import type { BackButtonProps } from '../types'; /** - * The bar's back (R14): to the page behind it on this site, or the page's parent when it was - * opened on its own (a link, a notification). A fixed `href` is a link; a page that may lose work - * passes `onBack` and asks first. + * The bar's back (R14, 0057): a link to the page's parent that goes back through history when the + * parent is the page behind. A fixed `href` is a plain link; a page that may lose work passes + * `onBack` and asks first. */ export function BackButton({ label, ...options }: BackButtonProps) { const action = useBack(options); @@ -18,6 +18,7 @@ export function BackButton({ label, ...options }: BackButtonProps) { icon="chevron-right" label={label} href={action.href} + onNavigate={action.onNavigate} /> ) : (