From 4e30cdcc36f0cc450310ed7c98c1fae828efbf6e Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Wed, 1 Mar 2023 23:06:08 +0330 Subject: [PATCH] feat(pwa-helper): handle nack to home event --- ui/pwa-helper/src/pwa-element.ts | 3 ++- ui/pwa-helper/src/signal/back-click-event.ts | 10 ---------- ui/pwa-helper/src/signal/back-to-home-click.ts | 11 +++++++++++ ui/pwa-helper/src/signal/browser-back-click.ts | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) delete mode 100644 ui/pwa-helper/src/signal/back-click-event.ts create mode 100644 ui/pwa-helper/src/signal/back-to-home-click.ts create mode 100644 ui/pwa-helper/src/signal/browser-back-click.ts diff --git a/ui/pwa-helper/src/pwa-element.ts b/ui/pwa-helper/src/pwa-element.ts index 1944437ae..590c3b515 100644 --- a/ui/pwa-helper/src/pwa-element.ts +++ b/ui/pwa-helper/src/pwa-element.ts @@ -18,7 +18,8 @@ import '@alwatr/ui-kit/style/token.css'; import '@alwatr/ui-kit/top-app-bar/top-app-bar.js'; import {untilNextFrame} from '@alwatr/util'; -import './signal/back-click-event.js'; +import './signal/back-to-home-click.js'; +import './signal/browser-back-click.js'; import './signal/register-service-worker-command.js'; import './signal/sw-user-notify.js'; diff --git a/ui/pwa-helper/src/signal/back-click-event.ts b/ui/pwa-helper/src/signal/back-click-event.ts deleted file mode 100644 index 10a11fe5b..000000000 --- a/ui/pwa-helper/src/signal/back-click-event.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {eventListener} from '@alwatr/signal'; - -import {logger} from '../logger.js'; - -import type {ClickSignalType} from '@alwatr/type'; - -eventListener.subscribe('back-click-event', () => { - logger.logMethod('back-click-event'); - history.back(); -}); diff --git a/ui/pwa-helper/src/signal/back-to-home-click.ts b/ui/pwa-helper/src/signal/back-to-home-click.ts new file mode 100644 index 000000000..1cb7a1da1 --- /dev/null +++ b/ui/pwa-helper/src/signal/back-to-home-click.ts @@ -0,0 +1,11 @@ +import {redirect} from '@alwatr/router'; +import {eventListener} from '@alwatr/signal'; + +import {logger} from '../logger.js'; + +import type {ClickSignalType} from '@alwatr/type'; + +eventListener.subscribe('back_to_home_click_event', () => { + logger.logMethod('back_to_home_click_event'); + redirect({sectionList: []}); +}); diff --git a/ui/pwa-helper/src/signal/browser-back-click.ts b/ui/pwa-helper/src/signal/browser-back-click.ts new file mode 100644 index 000000000..eaf4b67af --- /dev/null +++ b/ui/pwa-helper/src/signal/browser-back-click.ts @@ -0,0 +1,16 @@ +import {eventListener} from '@alwatr/signal'; + +import {logger} from '../logger.js'; + +import type {ClickSignalType} from '@alwatr/type'; + +eventListener.subscribe('browser_back_click_event', () => { + logger.logMethod('browser_back_click_event'); + history.back(); +}); + +// TODO: replace all and remove this +eventListener.subscribe('back-click-event', () => { + logger.logMethod('browser_back_click_event'); + history.back(); +});