summaryrefslogtreecommitdiff
path: root/src/jet/intents/error-page-intent-controller.ts
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /src/jet/intents/error-page-intent-controller.ts
init commit
Diffstat (limited to 'src/jet/intents/error-page-intent-controller.ts')
-rw-r--r--src/jet/intents/error-page-intent-controller.ts52
1 files changed, 52 insertions, 0 deletions
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<Page> {
+ $kind: 'ErrorPageIntent';
+ error: Opt<Error>;
+}
+
+export function makeErrorPageIntent(
+ options: Omit<ErrorPageIntent, '$kind'>,
+): ErrorPageIntent {
+ return {
+ ...options,
+ $kind: 'ErrorPageIntent',
+ };
+}
+
+export const ErrorPageIntentController: IntentController<ErrorPageIntent> = {
+ $intentKind: 'ErrorPageIntent',
+
+ async perform(
+ intent,
+ objectGraphWithoutActiveIntent: AppStoreObjectGraph,
+ ): Promise<Page> {
+ 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;
+ },
+ );
+ },
+};