git ssb

0+

mixmix / patchbay-scry



Tree: fdb2ee6f55290529cd2d95134844044dd149a47c

Files: fdb2ee6f55290529cd2d95134844044dd149a47c / views / show.test.js

2846 bytesRaw
1// run:
2// $ npx electro views/show.test.js
3
4const h = require('mutant/h')
5const sbot = require('scuttle-testbot')
6 .use(require('ssb-backlinks'))
7 .call()
8
9const pull = require('pull-stream')
10const scuttle = require('scuttle-poll')(sbot)
11const isPosition = require('scuttle-poll/isPosition')
12
13const Show = require('./show')
14
15// scry
16const opts = {
17 title: 'Ziva\'s first Birthday Party',
18 choices: [
19 time(2018, 9, 21, 10),
20 time(2018, 9, 21, 14),
21 time(2018, 9, 21, 16),
22 time(2018, 9, 22, 10),
23 time(2018, 9, 22, 14),
24 time(2018, 9, 22, 16)
25 ],
26 closesAt: threeDaysTime()
27}
28
29const katie = sbot.createFeed()
30const piet = sbot.createFeed()
31
32const positions = [
33 // { author: sbot, choices: [0, 1, 2, 3, 4, 5] },
34 { author: katie, choices: [0, 1, 2, 3] },
35 { author: katie, choices: [0, 3] },
36 { author: piet, choices: [3, 5] }
37]
38
39scuttle.poll.async.publishMeetingTime(opts, (err, poll) => {
40 if (err) return console.error(err)
41
42 pull(
43 pull.values(positions),
44 pull.asyncMap(({ author, choices }, cb) => {
45 const opts = {
46 type: 'position',
47 version: 'v1',
48 details: {
49 type: 'meetingTime',
50 choices
51 },
52 root: poll.key,
53 branch: poll.key
54 }
55
56 if (isPosition.meetingTime(opts)) author.publish(opts, cb)
57 else cb(new Error('not a valid meetingTime position', opts))
58 }),
59 pull.drain(
60 msg => console.log('position!'),
61 (err) => {
62 if (err) console.error(err)
63 else render(poll)
64
65 // Auto-resolve
66 // const postResolution = () => {
67 // scuttle.poll.async.publishResolution({
68 // poll: poll,
69 // choices: [3],
70 // body: 'See you all there <3'
71 // }, (err, data) => console.log('resolution:', err, data))
72 // }
73 // setTimeout(postResolution, 3e3)
74 }
75 )
76 )
77})
78
79function render (poll) {
80 const show = Show({
81 poll,
82 myFeedId: sbot.id,
83 scuttle,
84 name,
85 testing: true
86 })
87
88 document.body.appendChild(show)
89
90 // styles:
91
92 require('../lib/styles-inject')()
93 document.head.appendChild(
94 h('style', `
95 body {
96 --gradient: linear-gradient(45deg, hsla(60, 100%, 56%, .5), hsla(280, 100%, 46%, 0.3));
97 --texture: left top 0 / 3px radial-gradient(white, #de82e6) repeat ;
98 background: var(--texture), var(--gradient);
99 background-blend-mode: darken;
100
101 height: 100vh;
102 padding: 2rem;
103 }
104 `)
105 )
106}
107
108// helpers
109
110function name (feedId) {
111 const names = {
112 [sbot.id]: 'mix',
113 [piet.id]: 'piet',
114 [katie.id]: 'katie'
115 }
116
117 return names[feedId]
118}
119
120function time () {
121 return new Date(...arguments).toISOString()
122}
123
124function threeDaysTime () {
125 const now = new Date()
126 return time(now.getFullYear(), now.getMonth(), now.getDate() + 3, 14)
127}
128

Built with git-ssb-web