Files: 462c60502f8c45618c08ea0232132580d5801964 / views / show.test.js
2816 bytesRaw
1 | // run: |
2 | // $ npx electro views/show.test.js |
3 | |
4 | const h = require('mutant/h') |
5 | const sbot = require('scuttle-testbot') |
6 | .use(require('ssb-backlinks')) |
7 | .call() |
8 | |
9 | const pull = require('pull-stream') |
10 | const scuttle = require('scuttle-poll')(sbot) |
11 | const isPosition = require('scuttle-poll/isPosition') |
12 | |
13 | const Show = require('./show') |
14 | |
15 | // scry |
16 | const 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 | |
29 | const katie = sbot.createFeed() |
30 | const piet = sbot.createFeed() |
31 | |
32 | const 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 | |
39 | scuttle.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 | |
84 | function render (poll) { |
85 | const show = Show({ |
86 | poll, |
87 | myFeedId: sbot.id, |
88 | scuttle, |
89 | name |
90 | }) |
91 | |
92 | document.body.appendChild(show) |
93 | |
94 | // styles: |
95 | |
96 | require('../lib/styles-inject')() |
97 | document.head.appendChild( |
98 | h('style', ` |
99 | body { |
100 | --gradient: linear-gradient(45deg, hsla(60, 100%, 56%, .5), hsla(280, 100%, 46%, 0.3)); |
101 | --texture: left top 0 / 3px radial-gradient(white, #de82e6) repeat ; |
102 | background: var(--texture), var(--gradient); |
103 | background-blend-mode: darken; |
104 | |
105 | height: 100vh; |
106 | padding: 2rem; |
107 | } |
108 | `) |
109 | ) |
110 | } |
111 | |
112 | // helpers |
113 | |
114 | function name (feedId) { |
115 | const names = { |
116 | [sbot.id]: 'mix', |
117 | [piet.id]: 'piet', |
118 | [katie.id]: 'katie' |
119 | } |
120 | |
121 | return names[feedId] |
122 | } |
123 | |
124 | function time () { |
125 | return new Date(...arguments).toISOString() |
126 | } |
127 |
Built with git-ssb-web