diff --git a/package.json b/package.json index 5127c10..0f92edd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mono-pwa", - "version": "4.0.0-dev.12+20", + "version": "4.0.0-dev.12+21", "description": "monobank PWA", "main": "index.html", "config": { diff --git a/src/app/loaders/UI/LoadWidgets.js b/src/app/loaders/UI/LoadWidgets.js index 2bd7d55..6e0f1b3 100644 --- a/src/app/loaders/UI/LoadWidgets.js +++ b/src/app/loaders/UI/LoadWidgets.js @@ -5,6 +5,7 @@ import DefaultTemplate from "@App/modules/mono/services/dashboard/templates/defa import LiteralActions from "@App/modules/mono/services/dashboard/cards/funcs/LiteralActions" import Navigation from "@Core/Services/navigation" import ClientsWidget from "@App/modules/mono/services/dashboard/widgets/user/ClientsWidget" +import HintsWidget from "@App/modules/mono/services/dashboard/widgets/user/HintsWidget" DashboardCore.registerWidget({ id: "Nav", @@ -24,6 +25,12 @@ DashboardCore.registerWidget({ user: false, }) +DashboardCore.registerWidget({ + id: "Hints", + builder: HintsWidget, + user: true, +}) + DashboardCore.defaultLayout = DefaultTemplate LiteralActions.add("first_hello_replace", async () => { diff --git a/src/app/modules/mono/services/dashboard/templates/default.js b/src/app/modules/mono/services/dashboard/templates/default.js index c5474a5..ff29a79 100644 --- a/src/app/modules/mono/services/dashboard/templates/default.js +++ b/src/app/modules/mono/services/dashboard/templates/default.js @@ -55,15 +55,15 @@ export default function defaultDashboardTemplate() { }, { item: "Nav", - data: { link: { module: "settings" } }, - y: 2, - x: 4, + data: { link: { module: "statement" } }, + y: 1, + x: 5, }, { - item: "ClientsCount", - data: { type: "simple" }, - y: 3, - x: 1, + item: "Hints", + data: { }, + y: 2, + x: 4, }, ] return template diff --git a/src/app/modules/mono/services/dashboard/widgets/user/HintsWidget.js b/src/app/modules/mono/services/dashboard/widgets/user/HintsWidget.js new file mode 100644 index 0000000..cb52a9f --- /dev/null +++ b/src/app/modules/mono/services/dashboard/widgets/user/HintsWidget.js @@ -0,0 +1,209 @@ +import Block from "@Environment/Library/DOM/elements/block" +import DOM from "@DOMPath/DOM/Classes/dom" +import { $$ } from "@Core/Services/Language/handler" +import { Icon } from "@Environment/Library/DOM/object" +import Toast from "@Environment/Library/DOM/elements/toast" +import LanguageCore from "@Core/Services/Language/core" +import PWA from "@App/modules/main/PWA" +import SettingsStorage from "@Core/Services/Settings/SettingsStorage" +import randomFromArray from "@Core/Tools/objects/randomFromArray" +import Help from "@App/modules/main/Help" +import SetupError from "../../setup/SetupError" +import SetupFramework from "../../setup/SetupFramework" + +export default class HintsWidget { + static tipsList = [ + { + name: "pushes", + icon: "notifications", + article: "dummy", + }, + { + name: "updates", + icon: "new_releases", + article: "dummy", + }, + { + name: "change_order", + icon: "credit_card", + article: "dummy", + }, + { + name: "offline_statement", + icon: "offline_pin", + article: "dummy", + }, + { + name: "convert_currencies", + icon: "swap_horiz", + article: "dummy", + }, + { + name: "find_currencies", + icon: "search", + article: "dummy", + }, + { + name: "partner_sections", + icon: "filter_list", + article: "dummy", + }, + ] + + static greetings() { + const hour = new Date().getHours() + if (hour >= 0 && hour <= 5) return $$("greeting/night") + if (hour >= 6 && hour <= 11) return $$("greeting/morning") + if (hour >= 11 && hour <= 18) return $$("greeting/afternoon") + if (hour >= 19 && hour <= 23) return $$("greeting/evening") + return $$("greeting/generic") + } + + static async hint(disabled) { + if (!disabled.changelog) { + const lastChangelog = { + version: PWA.version, + get link() { + return PWA.changelog || `https://sominemo.com/mono/help/release/${LanguageCore.language.info.code}/${this.version}` + }, + } + const lastSeen = await SettingsStorage.getFlag("changelog_seen") + if (lastSeen !== lastChangelog.version) { + return { + icon: "new_releases", + title: $$("menu/app_upgraded"), + content: $$("menu/see_whats_new"), + type: $$("message"), + handler() { + window.open(lastChangelog.link, "_blank") + SettingsStorage.setFlag("changelog_seen", lastChangelog.version) + }, + } + } + } + + if (!disabled.tips) { + const tip = randomFromArray(this.tipsList) + return { + icon: tip.icon, + title: $$(`hints/list/${tip.name}/title`), + content: $$(`hints/list/${tip.name}/info`), + type: $$("tip"), + handler() { + Help.open(tip.article) + }, + } + } + + return { + icon: "emoji_objects", + title: this.greetings(), + content: $$("dashboard/hints/will_be_soon"), + type: "", + } + } + + constructor({ data: { disabled = {} } = {} }) { + const self = this.constructor + const colors = { main: "#ffc107", light: "#ffe082" } + + return new Block({ + data: [], + colors, + icon: "emoji_objects", + name: $$("dashboard/hints"), + size: { x: 2, y: 1 }, + async render() { + const hint = await self.hint(disabled) + return { + content: [ + new DOM({ + new: "div", + style: { + display: "flex", + alignItems: "center", + padding: ".5em", + }, + content: [ + new Icon(hint.icon, { fontSize: "3em", color: colors.main }), + new DOM({ + new: "div", + style: { + display: "flex", + flexDirection: "column", + textAlign: "initial", + marginLeft: ".5em", + flexGrow: "1", + fontSize: "1.1em", + }, + content: [ + new DOM({ + new: "div", + content: hint.title, + }), + new DOM({ + new: "div", + content: hint.content, + style: { + fontSize: ".7em", + opacity: ".6", + }, + }), + ], + }), + ], + }), + new DOM({ + new: "div", + content: hint.type, + style: { + position: "absolute", + right: "0", + bottom: "0", + margin: "1em", + textTransform: "uppercase", + fontSize: ".5em", + color: colors.main, + }, + }), + ], + style: { + display: "flex", + justifyContent: "center", + alignItems: "center", + textAlign: "center", + ...(typeof hint.handler === "function" ? { cursor: "pointer" } : {}), + flexDirection: "column", + }, + shadow: colors.main, + events: [ + { + event: "click", + handler() { + if (typeof hint.handler === "function") hint.handler() + }, + }, + ], + } + }, + }) + } + + static icon = "emoji_objects" + + static name = $$("dashboard/hints") + + static setup({ checkFit }) { + return new SetupFramework({ + name: this.name, + func: (data, state) => { + if (!checkFit(2, 1)) { + Toast.add($$("dashboard/cant_fit")) + throw new SetupError("This widget doesn't fit") + } + + return {} + }, + }, checkFit) + } +} diff --git a/src/app/res/language/ru/strings.js b/src/app/res/language/ru/strings.js index 9736b37..0f77941 100644 --- a/src/app/res/language/ru/strings.js +++ b/src/app/res/language/ru/strings.js @@ -39,6 +39,10 @@ export default { "": "Ссылка", choose_link: "Выберите назначение", }, + hints: { + "": "Подсказки", + will_be_soon: "Скоро здесь появятся подсказки", + }, clients: { "": "Клиенты monobank", sign: "Клиентов monobank", @@ -87,7 +91,7 @@ export default { menu: { "": "меню", app_upgraded: "приложение обновлено", - see_whats_new: "посмотрите, что нового", + see_whats_new: "нажмите, чтобы узнать, что нового", }, auth: { "": "Авторизация", @@ -513,6 +517,45 @@ export default { }, }, }, + hints: { + list: { + pushes: { + title: "Следите за операциями", + info: "Больше про меню \"Уведомления\"", + }, + updates: { + title: "Следите за новостями", + info: "Получайте оповещения об обновлениях в mono PWA", + }, + change_order: { + title: "Меняйте порядок карт", + info: "Больше о меню \"Мои карты\"", + }, + offline_statement: { + title: "Выписка без сети", + info: "Загружайте историю наперёд", + }, + convert_currencies: { + title: "Конвертируйте валюты", + info: "Благодаря функции в меню \"Курсы валют\"", + }, + find_currencies: { + title: "Ищите валюты", + info: "Узнайте о скрытых возможностях меню \"Курсы валют\"", + }, + partner_sections: { + title: "Категории в списке партнёров", + info: "Ищите желаемого продавца быстрее", + }, + }, + }, + greeting: { + morning: "доброе утро!", + afternoon: "добрый день!", + evening: "добрый вечер!", + night: "доброй ночи!", + generic: "здравствуйте!", + }, unexpected_error: "ой!", select_option: "выберите из списка", tap_to_change: "нажмите, чтобы изменить", @@ -534,6 +577,7 @@ export default { recommendation: "рекомендация", tip: "совет", hint: "подсказка", + message: "сообщение", reload: "перегрузить", enable_accessibility: "включить специальные возможности", skip_nav: "пропуск меню", diff --git a/src/app/res/language/uk/strings.js b/src/app/res/language/uk/strings.js index 3061ba9..d3095ba 100644 --- a/src/app/res/language/uk/strings.js +++ b/src/app/res/language/uk/strings.js @@ -39,6 +39,10 @@ export default { "": "Посилання", choose_link: "Оберіть призначення", }, + hints: { + "": "Підказки", + will_be_soon: "Незабаром тут з'являться підказки", + }, clients: { "": "Клієнти monobank", sign: "Клієнтів monobank", @@ -87,7 +91,7 @@ export default { menu: { "": "меню", app_upgraded: "застосунок оновлено", - see_whats_new: "подивіться, що нового", + see_whats_new: "натисніть, щоб дізнатись, що нового", }, auth: { "": "Авторизація", @@ -514,6 +518,45 @@ export default { }, }, }, + hints: { + list: { + pushes: { + title: "Слідкуйте за операціями", + info: "Більше про меню \"Сповіщення\"", + }, + updates: { + title: "Слідкуйте за новинами", + info: "Отримуйте сповіщення про оновлення у mono PWA", + }, + change_order: { + title: "Змінюйте порядок карток", + info: "Дізнайтесь про меню \"Мої картки\"", + }, + offline_statement: { + title: "Виписка без мережі", + info: "Завантажуйте історію наперед", + }, + convert_currencies: { + title: "Конвертуйте валюти", + info: "Завдяки функції у меню \"Курси валют\"", + }, + find_currencies: { + title: "Шукайте валюти", + info: "Дізнайтесь про приховані можливості меню \"Курси валют\"", + }, + partner_sections: { + title: "Категорії у списку партнерів", + info: "Шукайте бажаного продавця швидше", + }, + }, + }, + greeting: { + morning: "доброго ранку!", + afternoon: "добрий день!", + evening: "добрий вечір!", + night: "доброї ночі!", + generic: "вітаємо!", + }, unexpected_error: "ой!", select_option: "оберіть зі списку", tap_to_change: "натисніть, щоб змінити", @@ -535,6 +578,7 @@ export default { recommendation: "рекомендація", tip: "порада", hint: "підказка", + message: "повідомлення", reload: "перезавантажити", enable_accessibility: "включити спеціальні можливості", skip_nav: "минути меню",