git ssb

16+

Dominic / patchbay



Commit 298ca06a91c99764e114f8763b0b74d158093706

/query - basic querying learning!

mix irving committed on 7/12/2018, 11:56:47 AM
Parent: 7c6b563bcb3bbba64f3cebbf33a2e46ca364af95

Files changed

app/page/query.jsadded
app/page/query.mcssadded
package-lock.jsonchanged
package.jsonchanged
router/sync/routes.jschanged
app/page/query.jsView
@@ -1,0 +1,79 @@
1 +const nest = require('depnest')
2 +const { h, Value, Array: MutantArray, Struct, computed, when, map } = require('mutant')
3 +const pull = require('pull-stream')
4 +const Scroller = require('mutant-scroll')
5 +const next = require('pull-next-query')
6 +const json5 = require('json5')
7 +
8 +exports.gives = nest({
9 + 'app.html.menuItem': true,
10 + 'app.page.query': true
11 +})
12 +
13 +exports.needs = nest({
14 + 'message.html.render': 'first',
15 + 'sbot.pull.stream': 'first'
16 +})
17 +
18 +exports.create = function (api) {
19 + return nest({
20 + 'app.html.menuItem': menuItem,
21 + 'app.page.query': queryPage
22 + })
23 +
24 + function menuItem () {
25 + return h('a', {
26 + style: { order: 1 },
27 + 'ev-click': () => api.app.sync.goTo({ page: 'query' })
28 + }, '/query')
29 + }
30 +
31 + function queryPage (location) {
32 + const input = Value()
33 + const error = computed(input, i => {
34 + try {
35 + var query = json5.parse(i)
36 + } catch (err) {
37 + console.error(err)
38 + return err
39 + }
40 + if (!Array.isArray(query)) return
41 + if (!query.map(q => Object.keys(q)[0]).every(q => ['$filter', '$map', '$reduce'].includes(q))) return
42 + activateQuery()
43 + })
44 + const query = Value([])
45 +
46 + const activateQuery = () => query.set(json5.parse(input()))
47 +
48 + return h('Query', [
49 + h('section.query', [
50 + h('textarea', { 'ev-input': ev => input.set(ev.target.value) }),
51 + h('button', {
52 + className: when(error, '', '-primary'),
53 + disabled: when(error, 'disabled'),
54 + 'ev-click': activateQuery
55 + }, 'Go!')
56 + ]),
57 + h('section.output', [
58 + computed(query, query => {
59 + return Scroller({
60 + streamToBottom: source(query),
61 + render: msg => h('pre', JSON.stringify(msg, null, 2))
62 + })
63 + })
64 + ])
65 + ])
66 + }
67 +
68 + function source (query) {
69 + const opts = {
70 + query,
71 + reverse: true,
72 + limit: 100
73 + }
74 +
75 + return api.sbot.pull.stream(server => {
76 + return next(server.query.read, opts, ['value', 'timestamp'])
77 + })
78 + }
79 +}
app/page/query.mcssView
@@ -1,0 +1,54 @@
1 +Query {
2 + width: 100%
3 +
4 + display: grid
5 + grid-template-columns: 28rem auto
6 + grid-gap: 1rem
7 +
8 + overflow: hidden
9 +
10 + section.query {
11 + display: grid
12 + align-content: start
13 + justify-items: end
14 + grid-gap: 1rem
15 +
16 + textarea {
17 + justify-self: stretch
18 +
19 + color: #fff
20 + font-family: monospace
21 +
22 + background: rgb(40 , 0, 40)
23 + padding: 1rem
24 + border: none
25 +
26 + min-height: 20rem
27 + }
28 +
29 + button {
30 +
31 + }
32 + }
33 +
34 + section.output {
35 + position: relative
36 +
37 + div.Scroller {
38 + position: absolute
39 + top: 0
40 + bottom: 0
41 +
42 + section { margin: 0 }
43 +
44 + section.content {
45 + pre {
46 + word-wrap: break-word
47 + white-space: pre-wrap
48 +
49 + /* margin: 0 0 3rem 0 */
50 + }
51 + }
52 + }
53 + }
54 +}
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 347432 bytes
New file size: 347982 bytes
package.jsonView
@@ -50,8 +50,9 @@
5050 "hyperfile": "^2.0.0",
5151 "hyperlightbox": "^1.0.0",
5252 "hypertabs": "^5.0.1",
5353 "insert-css": "^2.0.0",
54 + "json5": "^1.0.1",
5455 "libnested": "^1.2.1",
5556 "lodash": "^4.17.4",
5657 "micro-css": "^2.0.1",
5758 "mutant": "^3.22.1",
router/sync/routes.jsView
@@ -5,20 +5,20 @@
55
66 exports.needs = nest({
77 'app.page': {
88 'errors': 'first',
9 + 'blob': 'first',
10 + 'channel': 'first',
11 + 'imageSearch': 'first',
12 + 'notifications': 'first',
913 'posts': 'first',
10- 'public': 'first',
1114 'private': 'first',
12- 'notifications': 'first',
1315 'profile': 'first',
16 + 'public': 'first',
17 + 'query': 'first',
1418 'search': 'first',
15- 'imageSearch': 'first',
16- 'blob': 'first',
17- 'thread': 'first',
18- 'channel': 'first',
19- 'settings': 'first'
20-
19 + 'settings': 'first',
20 + 'thread': 'first'
2121 },
2222 'keys.sync.id': 'first'
2323 })
2424
@@ -28,16 +28,17 @@
2828 const pages = api.app.page
2929
3030 // loc = location
3131 const routes = [
32 + [ loc => loc.page === 'errors', pages.errors ],
33 + [ loc => loc.page === 'imageSearch', pages.imageSearch ],
34 + [ loc => loc.page === 'notifications', pages.notifications ],
3235 [ loc => loc.page === 'posts', pages.posts ],
36 + [ loc => loc.page === 'private', pages.private ],
3337 [ loc => loc.page === 'public', pages.public ],
34- [ loc => loc.page === 'private', pages.private ],
35- [ loc => loc.page === 'notifications', pages.notifications ],
36- [ loc => loc.page === 'errors', pages.errors ],
3738 [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ],
39 + [ loc => loc.page === 'query', pages.query ],
3840 [ loc => loc.page === 'search' && loc.query, pages.search ],
39- [ loc => loc.page === 'imageSearch', pages.imageSearch ],
4041 [ loc => loc.page === 'settings', pages.settings ],
4142
4243 [ loc => isBlob(loc.blob), pages.blob ],
4344 [ loc => isPresent(loc.channel), pages.channel ],

Built with git-ssb-web