From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- src/jet/intents/error-page-intent-controller.ts | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/jet/intents/error-page-intent-controller.ts (limited to 'src/jet/intents/error-page-intent-controller.ts') diff --git a/src/jet/intents/error-page-intent-controller.ts b/src/jet/intents/error-page-intent-controller.ts new file mode 100644 index 0000000..59ac1fd --- /dev/null +++ b/src/jet/intents/error-page-intent-controller.ts @@ -0,0 +1,52 @@ +import type { Intent, IntentController } from '@jet/environment/dispatching'; +import type { Opt } from '@jet/environment/types/optional'; +import type { AppStoreObjectGraph } from '@jet-app/app-store/foundation/runtime/app-store-object-graph'; +import { withActiveIntent } from '@jet-app/app-store/foundation/dependencies/active-intent'; +import { injectWebNavigation } from '@jet-app/app-store/common/web-navigation/inject-web-navigation'; + +import { ErrorPage } from '~/jet/models/error-page'; +import type { Page } from '~/jet/models/page'; +import { getRejectedIntent } from '~/jet/utils/error-metadata'; +import { isWithPlatform } from '~/jet/utils/with-platform'; + +interface ErrorPageIntent extends Intent { + $kind: 'ErrorPageIntent'; + error: Opt; +} + +export function makeErrorPageIntent( + options: Omit, +): ErrorPageIntent { + return { + ...options, + $kind: 'ErrorPageIntent', + }; +} + +export const ErrorPageIntentController: IntentController = { + $intentKind: 'ErrorPageIntent', + + async perform( + intent, + objectGraphWithoutActiveIntent: AppStoreObjectGraph, + ): Promise { + const { error } = intent; + const rejectedIntent = error ? getRejectedIntent(error) : null; + const platform = + (rejectedIntent && isWithPlatform(rejectedIntent) + ? rejectedIntent.platform + : null) ?? 'iphone'; + + return await withActiveIntent( + objectGraphWithoutActiveIntent, + { ...intent, platform }, + async (objectGraph) => { + const page = new ErrorPage({ error: intent.error }); + + injectWebNavigation(objectGraph, page, platform); + + return page; + }, + ); + }, +}; -- cgit v1.2.3