Commit 298ca06a91c99764e114f8763b0b74d158093706
/query - basic querying learning!
mix irving committed on 7/12/2018, 11:56:47 AMParent: 7c6b563bcb3bbba64f3cebbf33a2e46ca364af95
Files changed
app/page/query.js | added |
app/page/query.mcss | added |
package-lock.json | changed |
package.json | changed |
router/sync/routes.js | changed |
app/page/query.js | |||
---|---|---|---|
@@ -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.mcss | ||
---|---|---|
@@ -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.json | ||
---|---|---|
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.json | ||
---|---|---|
@@ -50,8 +50,9 @@ | ||
50 | 50 … | "hyperfile": "^2.0.0", |
51 | 51 … | "hyperlightbox": "^1.0.0", |
52 | 52 … | "hypertabs": "^5.0.1", |
53 | 53 … | "insert-css": "^2.0.0", |
54 … | + "json5": "^1.0.1", | |
54 | 55 … | "libnested": "^1.2.1", |
55 | 56 … | "lodash": "^4.17.4", |
56 | 57 … | "micro-css": "^2.0.1", |
57 | 58 … | "mutant": "^3.22.1", |
router/sync/routes.js | ||
---|---|---|
@@ -5,20 +5,20 @@ | ||
5 | 5 … | |
6 | 6 … | exports.needs = nest({ |
7 | 7 … | 'app.page': { |
8 | 8 … | 'errors': 'first', |
9 … | + 'blob': 'first', | |
10 … | + 'channel': 'first', | |
11 … | + 'imageSearch': 'first', | |
12 … | + 'notifications': 'first', | |
9 | 13 … | 'posts': 'first', |
10 | - 'public': 'first', | |
11 | 14 … | 'private': 'first', |
12 | - 'notifications': 'first', | |
13 | 15 … | 'profile': 'first', |
16 … | + 'public': 'first', | |
17 … | + 'query': 'first', | |
14 | 18 … | 'search': 'first', |
15 | - 'imageSearch': 'first', | |
16 | - 'blob': 'first', | |
17 | - 'thread': 'first', | |
18 | - 'channel': 'first', | |
19 | - 'settings': 'first' | |
20 | - | |
19 … | + 'settings': 'first', | |
20 … | + 'thread': 'first' | |
21 | 21 … | }, |
22 | 22 … | 'keys.sync.id': 'first' |
23 | 23 … | }) |
24 | 24 … | |
@@ -28,16 +28,17 @@ | ||
28 | 28 … | const pages = api.app.page |
29 | 29 … | |
30 | 30 … | // loc = location |
31 | 31 … | const routes = [ |
32 … | + [ loc => loc.page === 'errors', pages.errors ], | |
33 … | + [ loc => loc.page === 'imageSearch', pages.imageSearch ], | |
34 … | + [ loc => loc.page === 'notifications', pages.notifications ], | |
32 | 35 … | [ loc => loc.page === 'posts', pages.posts ], |
36 … | + [ loc => loc.page === 'private', pages.private ], | |
33 | 37 … | [ 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 ], | |
37 | 38 … | [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ], |
39 … | + [ loc => loc.page === 'query', pages.query ], | |
38 | 40 … | [ loc => loc.page === 'search' && loc.query, pages.search ], |
39 | - [ loc => loc.page === 'imageSearch', pages.imageSearch ], | |
40 | 41 … | [ loc => loc.page === 'settings', pages.settings ], |
41 | 42 … | |
42 | 43 … | [ loc => isBlob(loc.blob), pages.blob ], |
43 | 44 … | [ loc => isPresent(loc.channel), pages.channel ], |
Built with git-ssb-web