From 24fad10f362319a004cf26e718a4d9d3546539df Mon Sep 17 00:00:00 2001 From: Yasin Silavi Date: Wed, 26 Jul 2023 10:27:40 +0330 Subject: [PATCH 1/4] Format alert module --- src/components/alert.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/alert.js b/src/components/alert.js index 6e654e9f3..16b2c826b 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -1,23 +1,25 @@ -import { appRouter } from './router/appRouter'; -import browser from '../scripts/browser'; -import dialog from './dialog/dialog'; -import globalize from '../scripts/globalize'; +import { appRouter } from "./router/appRouter"; +import browser from "../scripts/browser"; +import dialog from "./dialog/dialog"; +import globalize from "../scripts/globalize"; function useNativeAlert() { // webOS seems to block modals // Tizen 2.x seems to block modals - return !browser.web0s - && !(browser.tizenVersion && browser.tizenVersion < 3) - && browser.tv - && window.alert; + return ( + !browser.web0s && + !(browser.tizenVersion && browser.tizenVersion < 3) && + browser.tv && + window.alert + ); } export default async function (text, title) { let options; - if (typeof text === 'string') { + if (typeof text === "string") { options = { title: title, - text: text + text: text, }; } else { options = text; @@ -26,15 +28,15 @@ export default async function (text, title) { await appRouter.ready(); if (useNativeAlert()) { - alert((options.text || '').replaceAll('
', '\n')); + alert((options.text || "").replaceAll("
", "\n")); return Promise.resolve(); } else { const items = []; items.push({ - name: globalize.translate('ButtonGotIt'), - id: 'ok', - type: 'submit' + name: globalize.translate("ButtonGotIt"), + id: "ok", + type: "submit", }); options.buttons = items; From 0a878bfbcddb6e01a9f447d640b861873e18589f Mon Sep 17 00:00:00 2001 From: Yasin Silavi Date: Wed, 26 Jul 2023 10:28:14 +0330 Subject: [PATCH 2/4] Refactor alert module --- src/components/alert.js | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/components/alert.js b/src/components/alert.js index 16b2c826b..46d9ea4d6 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -3,43 +3,34 @@ import browser from "../scripts/browser"; import dialog from "./dialog/dialog"; import globalize from "../scripts/globalize"; -function useNativeAlert() { - // webOS seems to block modals - // Tizen 2.x seems to block modals - return ( +export default async function (text, title) { + // Modals seem to be blocked on Web OS and Tizen 2.x + const canUseNativeAlert = !!( !browser.web0s && !(browser.tizenVersion && browser.tizenVersion < 3) && browser.tv && window.alert ); -} -export default async function (text, title) { - let options; - if (typeof text === "string") { - options = { - title: title, - text: text, - }; - } else { - options = text; - } + let options = typeof text === "string" ? { title, text } : text; await appRouter.ready(); - if (useNativeAlert()) { + if (canUseNativeAlert) { alert((options.text || "").replaceAll("
", "\n")); - return Promise.resolve(); - } else { - const items = []; - items.push({ + return Promise.resolve(); + } + + const items = [ + { name: globalize.translate("ButtonGotIt"), id: "ok", type: "submit", - }); + }, + ]; - options.buttons = items; - return dialog.show(options); - } + options.buttons = items; + + return dialog.show(options); } From 6664b6ec62fac3ab89374c3ae2431b714f795cf1 Mon Sep 17 00:00:00 2001 From: Yasin Silavi Date: Sun, 10 Sep 2023 23:20:20 +0330 Subject: [PATCH 3/4] style: use singlequote for strings --- src/components/alert.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/alert.js b/src/components/alert.js index 46d9ea4d6..de3c7c444 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -1,33 +1,33 @@ -import { appRouter } from "./router/appRouter"; -import browser from "../scripts/browser"; -import dialog from "./dialog/dialog"; -import globalize from "../scripts/globalize"; +import { appRouter } from './router/appRouter'; +import browser from '../scripts/browser'; +import dialog from './dialog/dialog'; +import globalize from '../scripts/globalize'; export default async function (text, title) { // Modals seem to be blocked on Web OS and Tizen 2.x const canUseNativeAlert = !!( - !browser.web0s && - !(browser.tizenVersion && browser.tizenVersion < 3) && - browser.tv && - window.alert + !browser.web0s + && !(browser.tizenVersion && browser.tizenVersion < 3) + && browser.tv + && window.alert ); - let options = typeof text === "string" ? { title, text } : text; + const options = typeof text === 'string' ? { title, text } : text; await appRouter.ready(); if (canUseNativeAlert) { - alert((options.text || "").replaceAll("
", "\n")); + alert((options.text || '').replaceAll('
', '\n')); return Promise.resolve(); } const items = [ { - name: globalize.translate("ButtonGotIt"), - id: "ok", - type: "submit", - }, + name: globalize.translate('ButtonGotIt'), + id: 'ok', + type: 'submit' + } ]; options.buttons = items; From 082d9e55c62578dea3b06e2db50d89ef64fbf483 Mon Sep 17 00:00:00 2001 From: Yasin Silavi Date: Tue, 12 Sep 2023 22:04:18 +0330 Subject: [PATCH 4/4] refactor: remove useless assignment --- src/components/alert.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/alert.js b/src/components/alert.js index de3c7c444..ebeed3d8f 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -22,7 +22,7 @@ export default async function (text, title) { return Promise.resolve(); } - const items = [ + options.buttons = [ { name: globalize.translate('ButtonGotIt'), id: 'ok', @@ -30,7 +30,5 @@ export default async function (text, title) { } ]; - options.buttons = items; - return dialog.show(options); }