git ssb

0+

mixmix / patchbay-scry



Tree: 6071577daff8cc01e7241b5799fb112902aec545

Files: 6071577daff8cc01e7241b5799fb112902aec545 / views / show.test.js

2835 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, 10, 21, 10),
20 time(2018, 10, 21, 14),
21 time(2018, 10, 21, 16),
22 time(2018, 10, 22, 10),
23 time(2018, 10, 22, 14),
24 time(2018, 10, 22, 16)
25 ],
26 closesAt: time(2018, 10, 1)
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('yep'),
61 (err) => {
62 if (err) console.error(err)
63 else render(poll)
64
65 // // confirm positions were published
66 // pull(
67 // sbot.backlinks.read({
68 // query: [{
69 // $filter: { dest: poll.key }
70 // }, {
71 // $map: {
72 // author: ['value', 'author'],
73 // details: ['value', 'content', 'details']
74 // }
75 // }]
76 // }),
77 // pull.drain(m => console.log(JSON.stringify(m, null, 2)))
78 // )
79 }
80 )
81 )
82})
83
84function render (poll) {
85 const show = Show({
86 poll,
87 myFeedId: sbot.id,
88 scuttle,
89 name,
90 testing: true
91 })
92
93 document.body.appendChild(show)
94
95 // styles:
96
97 require('../lib/styles-inject')()
98 document.head.appendChild(
99 h('style', `
100 body {
101 --gradient: linear-gradient(45deg, hsla(60, 100%, 56%, .5), hsla(280, 100%, 46%, 0.3));
102 --texture: left top 0 / 3px radial-gradient(white, #de82e6) repeat ;
103 background: var(--texture), var(--gradient);
104 background-blend-mode: darken;
105
106 height: 100vh;
107 padding: 2rem;
108 }
109 `)
110 )
111}
112
113// helpers
114
115function name (feedId) {
116 const names = {
117 [sbot.id]: 'mix',
118 [piet.id]: 'piet',
119 [katie.id]: 'katie'
120 }
121
122 return names[feedId]
123}
124
125function time () {
126 return new Date(...arguments).toISOString()
127}
128

Built with git-ssb-web