git ssb

0+

mixmix / patchbay-scry



Commit fdf219a4cc6267361e534f21330817706b26fd64

catch edge cases on pickers (no past, no repeats)

mixmix committed on 8/27/2018, 6:07:16 AM
Parent: 3c22a67c2c3e7ac133fb20fee9551c42f64e5d86

Files changed

views/component/day-picker.jschanged
views/component/time-picker.jschanged
views/new.jschanged
views/component/day-picker.jsView
@@ -1,8 +1,10 @@
11 const { h, computed } = require('mutant')
22 const Marama = require('marama')
33
44 module.exports = function DayPicker (state) {
5 + const startOfToday = startOfDay()
6 +
57 return h('ScryDayPicker', [
68 h('div.month-picker', [
79 h('button', { 'ev-click': () => setMonth(-1) }, '<'),
810 MonthTitle(state.monthIndex),
@@ -26,20 +28,20 @@
2628 function setMonth (d) {
2729 state.monthIndex.set(state.monthIndex() + d)
2830 }
2931
30- function onSelect ({ gte, lt, events: days }) {
31- if (!days.length) addEmptyEvent()
32 + function onSelect ({ gte, lt, events: dayEvents }) {
33 + if (gte < startOfToday) return
34 +
35 + if (!dayEvents.length) addEmptyEvent()
3236 else clearDay()
3337
34- state.pristine.set(false)
35-
3638 function addEmptyEvent () {
3739 state.days.push(Event(gte))
3840 }
3941 function clearDay () {
40- const filteredEvents = state.days().filter(e => !days.includes(e))
41- state.days.set(filteredEvents)
42 + const prunedEvents = state.days().filter(e => !dayEvents.includes(e))
43 + state.days.set(prunedEvents)
4244 }
4345 }
4446 }
4547
@@ -62,4 +64,8 @@
6264 date,
6365 data: {attending: true}
6466 }
6567 }
68 +
69 +function startOfDay (d = new Date()) {
70 + return new Date(d.getFullYear(), d.getMonth(), d.getDate())
71 +}
views/component/time-picker.jsView
@@ -27,12 +27,9 @@
2727 when(active,
2828 h('div.dropdown', options.map((time, i) => {
2929 return h('div',
3030 {
31- 'ev-click': () => {
32- times.push(Event(time))
33- active.set(false)
34- },
31 + 'ev-click': () => select(time),
3532 className: i === 32 ? DAY_START_SELECTOR : ''
3633 },
3734 printTime(time)
3835 )
@@ -42,8 +39,16 @@
4239 ])
4340
4441 return el
4542
43 + function select (time) {
44 + if (!times.find(t => t.date === time)) {
45 + // time not yet selected
46 + times.push(Event(time))
47 + }
48 + active.set(false)
49 + }
50 +
4651 function activate () {
4752 active.set(true)
4853
4954 const target = el.querySelector('.' + DAY_START_SELECTOR)
views/new.jsView
@@ -2,26 +2,21 @@
22 const DayPicker = require('./component/day-picker.js')
33 const TimePicker = require('./component/time-picker.js')
44
55 module.exports = function ScryNew (opts) {
6- const {
7- // i18n
8- } = opts
6 + // const {
7 + // i18n
8 + // } = opts
99
1010 const state = Struct({
11- pristine: true,
1211 monthIndex: new Date().getMonth(),
1312 days: MutantArray([]),
1413 times: MutantArray([])
1514 })
1615
1716 return h('ScryNew', [
1817 DayPicker(state),
19- when(state.pristine,
20- h('div.time-picker-pristine', [
21- h('label', 'Dates and Times'),
22- h('div.instruction', 'Select one or multiple dates')
23- ]),
18 + when(computed(state.days, d => Boolean(d.length)),
2419 h('div.time-picker', [
2520 h('label', computed(state.days, days => `Same times for all dates (${days.length})`)),
2621 TimePicker(state),
2722 h('div.timezone', [
@@ -30,8 +25,12 @@
3025 getTimezone(),
3126 h('span', ['(UTC ', getTimezoneOffset(), ')'])
3227 ])
3328 ])
29 + ]),
30 + h('div.time-picker-pristine', [
31 + h('label', 'Dates and Times'),
32 + h('div.instruction', 'Select one or multiple dates')
3433 ])
3534 )
3635 ])
3736 }

Built with git-ssb-web