git ssb

16+

Dominic / patchbay



Commit fec69b0777e88c6df42090793aa3e1e9fdc142fd

/calender: add scry and gathering launchers

mixmix committed on 11/6/2018, 9:03:05 PM
Parent: e947432e1cdeccc80641fc333eed1e6190fb0238

Files changed

app/page/calendar.jschanged
app/page/calendar.mcsschanged
app/page/calendar.jsView
@@ -1,11 +1,8 @@
11 const nest = require('depnest')
22 const { h, Array: MutantArray, map, Struct, computed, watch, throttle, resolve } = require('mutant')
33 const Month = require('marama')
4-
54 const pull = require('pull-stream')
6-const paraMap = require('pull-paramap')
7-const { isMsg } = require('ssb-ref')
85
96 exports.gives = nest({
107 'app.page.calendar': true,
118 'app.html.menuItem': true
@@ -16,9 +13,11 @@
1613 'keys.sync.id': 'first',
1714 'message.html.render': 'first',
1815 'message.sync.unbox': 'first',
1916 'sbot.async.get': 'first',
20- 'sbot.pull.stream': 'first'
17 + 'sbot.pull.stream': 'first',
18 + 'scry.html.button': 'first',
19 + 'gathering.html.button': 'first'
2120 })
2221
2322 exports.create = (api) => {
2423 return nest({
@@ -47,10 +46,15 @@
4746
4847 watch(state.year, year => getGatherings(year, state.events, Query))
4948 watchAttending(state.attending, api)
5049
50 + const actions = [
51 + api.scry.html.button(),
52 + api.gathering.html.button()
53 + ]
54 +
5155 const page = h('CalendarPage', { title: '/calendar' }, [
52- Calendar(state),
56 + Calendar(state, actions),
5357 Events(state, api)
5458 ])
5559
5660 page.scroll = (i) => scroll(state.range, i)
@@ -95,9 +99,9 @@
9599 }
96100 }
97101
98102 function Events (state, api) {
99- return h('CalendarEvents', computed([state.events, state.range], (events, range) => {
103 + return h('CalendarEvents', { title: '' }, computed([state.events, state.range], (events, range) => {
100104 const keys = events
101105 .filter(ev => ev.date >= range.gte && ev.date < range.lt)
102106 .sort((a, b) => a.date - b.date)
103107 .map(ev => ev.data.key)
@@ -109,10 +113,10 @@
109113 pull.asyncMap((key, cb) => {
110114 api.sbot.async.get(key, (err, value) => {
111115 if (err) return cb(err)
112116
113- if (typeof value.content === 'object') cb(null, {key, value})
114- else cb(null, api.message.sync.unbox({key, value}))
117 + if (typeof value.content === 'object') cb(null, { key, value })
118 + else cb(null, api.message.sync.unbox({ key, value }))
115119 })
116120 }),
117121 pull.drain(msg => gatherings.push(msg))
118122 )
@@ -156,9 +160,8 @@
156160 })
157161 )
158162 }
159163
160-
161164 function getGatherings (year, events, Query) {
162165 // gatherings specify times with `about` messages which have a startDateTime
163166 // NOTE - this gets a window of about messages around the current year but does not gaurentee
164167 // that we got all events in this year (e.g. something booked 6 months agead would be missed)
@@ -171,9 +174,9 @@
171174 },
172175 content: {
173176 type: 'about',
174177 startDateTime: {
175- epoch: {$is: 'number'}
178 + epoch: { $is: 'number' }
176179 }
177180 }
178181 }
179182 }
@@ -200,9 +203,8 @@
200203 if (target && target.data.ts <= ts) events.delete(target)
201204 // TODO causally sorted about messages
202205 // could do this with a backlinks query, paramap'd
203206
204-
205207 events.push({ date, data: { key, ts } })
206208 })
207209 )
208210 }
@@ -211,19 +213,20 @@
211213 // Calendar takes events of format { date: Date, data: { attending: Boolean, ... } }
212214
213215 const MONTH_NAMES = [ 'Ja', 'Fe', 'Ma', 'Ap', 'Ma', 'Ju', 'Ju', 'Au', 'Se', 'Oc', 'No', 'De' ]
214216
215-function Calendar (state) {
217 +function Calendar (state, actions) {
216218 // TODO assert events is an Array of object
217219 // of form { date, data }
218220
219- return h('Calendar', [
221 + return h('Calendar', { title: '' }, [
220222 h('div.header', [
221223 h('div.year', [
222224 state.year,
223225 h('a', { 'ev-click': () => state.year.set(state.year() - 1) }, '-'),
224226 h('a', { 'ev-click': () => state.year.set(state.year() + 1) }, '+')
225- ])
227 + ]),
228 + h('div.actions', actions)
226229 ]),
227230 h('div.months', computed(throttle(state, 100), ({ today, year, events, attending, range }) => {
228231 events = events.map(ev => {
229232 ev.data.attending = attending.includes(ev.data.key)
@@ -239,9 +242,9 @@
239242 }
240243
241244 return h('div.month', [
242245 h('div.month-name', { 'ev-click': setMonthRange }, MONTH_NAMES[i]),
243- Month({ year, monthIndex: i, events, range, onSelect, styles: {weekFormat: 'columns'} })
246 + Month({ year, monthIndex: i, events, range, onSelect, styles: { weekFormat: 'columns' } })
244247 ])
245248 })
246249 }))
247250 ])
app/page/calendar.mcssView
@@ -34,8 +34,12 @@
3434 margin: 40px 0
3535 text-align: left
3636 align-content: flex-start
3737
38 + display: grid
39 + justify-content: space-between
40 + grid-auto-flow: column
41 +
3842 div.year {
3943 font-size: 40px
4044 font-weight: bold
4145
@@ -52,13 +56,16 @@
5256 cursor: pointer
5357 text-decoration: none
5458 }
5559 }
60 +
5661 }
5762
58- p.percentage {
59- font-size: 20px
60- color: #8b8b8b
63 + div.actions {
64 + display: grid
65 + justify-content: space-between
66 + grid-auto-flow: column
67 + grid-gap: 1rem
6168 }
6269 }
6370
6471 div.months {

Built with git-ssb-web