Skip to content

Commit

Permalink
Виджет подсказок
Browse files Browse the repository at this point in the history
  • Loading branch information
Sominemo committed Jul 1, 2020
1 parent b47bb3e commit b2e0b8a
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions src/app/loaders/UI/LoadWidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 () => {
Expand Down
14 changes: 7 additions & 7 deletions src/app/modules/mono/services/dashboard/templates/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
209 changes: 209 additions & 0 deletions src/app/modules/mono/services/dashboard/widgets/user/HintsWidget.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
46 changes: 45 additions & 1 deletion src/app/res/language/ru/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default {
"": "Ссылка",
choose_link: "Выберите назначение",
},
hints: {
"": "Подсказки",
will_be_soon: "Скоро здесь появятся подсказки",
},
clients: {
"": "Клиенты monobank",
sign: "Клиентов monobank",
Expand Down Expand Up @@ -87,7 +91,7 @@ export default {
menu: {
"": "меню",
app_upgraded: "приложение обновлено",
see_whats_new: "посмотрите, что нового",
see_whats_new: "нажмите, чтобы узнать, что нового",
},
auth: {
"": "Авторизация",
Expand Down Expand Up @@ -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: "нажмите, чтобы изменить",
Expand All @@ -534,6 +577,7 @@ export default {
recommendation: "рекомендация",
tip: "совет",
hint: "подсказка",
message: "сообщение",
reload: "перегрузить",
enable_accessibility: "включить специальные возможности",
skip_nav: "пропуск меню",
Expand Down
Loading

0 comments on commit b2e0b8a

Please sign in to comment.