From c52e037c8e817bb120d3f7a370b22d3d3d2994c3 Mon Sep 17 00:00:00 2001 From: Marek Piasecki Date: Thu, 12 Jan 2023 10:09:11 +0100 Subject: [PATCH] defining slot size --- src/index.js | 3 +-- src/router.imba | 1 + src/ui/slot-size-input.imba | 52 +++++++++++++++++++++++++++++++++++++ src/views/choose-slot.imba | 24 +++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/ui/slot-size-input.imba create mode 100644 src/views/choose-slot.imba diff --git a/src/index.js b/src/index.js index 3587164..04b6a41 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,2 @@ -import "pro-router/standalone" import "./router.imba" -import "./main.imba" \ No newline at end of file +// import "./main.imba" \ No newline at end of file diff --git a/src/router.imba b/src/router.imba index 3e13b49..31d24fc 100644 --- a/src/router.imba +++ b/src/router.imba @@ -14,6 +14,7 @@ global.H = R.init(helpers: H, views: ['day-select', 'choose-slot', 'booking-confirmation'], root: 'day-select', render: imba.commit) import "./views/day-select.imba" +import "./views/choose-slot.imba" import "./main.css" global css diff --git a/src/ui/slot-size-input.imba b/src/ui/slot-size-input.imba new file mode 100644 index 0000000..85059bb --- /dev/null +++ b/src/ui/slot-size-input.imba @@ -0,0 +1,52 @@ +import './plus-minus.imba' + +let h = + zero: do new Date(0) + max_size: do #ms ||= R.getters.size "3_0_0", 1 # 3 days + + validate: do |s| + return R.getters.size("0_0_5", 1) if s < h.zero! + return new Date(h.max_size!) if s > h.max_size! + s + + modify: do |what, n, date=R.param('size')| + date["set{what}"]( date["get{what}"]() + n ) + h.validate(date) + + change: do |what, n, date=R.param('size')| + h.save h.modify(*arguments) + + save: do |date| + R.write 'size', date + + days: do |day=R.param('size')| day.getDate! - 1 + incr_day: do h.change "Date", 1 + decr_day: do h.change "Date", -1 + incr_h: do h.change "Hours", 1 + decr_h: do h.change "Hours", -1 + incr_min: do h.change "Minutes", 5 + decr_min: do h.change "Minutes", -5 + + set_time: do |days, hour, min, date=h.zero!| + date.setHours(hour, min, 0, 0) + date.setDate(Number(days)+1) + date + + format_d: do |n| "{n}{n > 1 ? "days" : "day"}" + format_h: do |n| "{n}h" + format_min: do |n| "{n}min" + +export default h + +R.setters.size = do |v| let s = "{h.days(v)}_{v.getHours!}_{v.getMinutes!}"; s if s!= "0_0_30" +R.getters.size = do |v, skip_validation| + let size = v ? v.split('_') : [0, 0, 30] + let date = h.set_time(*size) + skip_validation ? date : h.validate(date) + +tag slot-size-input + + if h.days! > 0 + + + \ No newline at end of file diff --git a/src/views/choose-slot.imba b/src/views/choose-slot.imba new file mode 100644 index 0000000..7d6352b --- /dev/null +++ b/src/views/choose-slot.imba @@ -0,0 +1,24 @@ +import sh from "../ui/slot-size-input.imba" +import "../ui/action-button.imba" + +tag view-choose-slot + +

"How long?" + + + + + + + + "Book slot" + +tag SizeHint < action-button + prop size + "{ size }h" + + get compare + R.params.size == size_hash + + get size_hash + "0_{size}_0" \ No newline at end of file