shrub/pkg/arvo/app/contact-view.hoon

203 lines
4.4 KiB
Plaintext
Raw Normal View History

2019-11-19 01:41:08 +03:00
:: contact-view: sets up contact JS client and combines commands
:: into semantic actions for the UI
::
/- *group-store
2019-11-19 01:41:08 +03:00
/+ *server, *contact-json
/= index
/^ octs
/; as-octs:mimes:html
/: /===/app/contacts/index
/| /html/
/~ ~
==
/= tile-js
/^ octs
/; as-octs:mimes:html
/: /===/app/contacts/js/tile
/| /js/
/~ ~
==
/= script
/^ octs
/; as-octs:mimes:html
/: /===/app/contacts/js/index
/| /js/
/~ ~
==
/= style
/^ octs
/; as-octs:mimes:html
/: /===/app/contacts/css/index
/| /css/
/~ ~
==
/= contact-png
/^ (map knot @)
/: /===/app/contacts/img /_ /png/
::
|%
::
+$ move [bone card]
::
+$ card
$% [%http-response =http-event:http]
[%connect wire binding:eyre term]
[%quit ~]
[%peer wire dock path]
2019-11-19 01:41:08 +03:00
[%poke wire dock poke]
[%diff %json json]
2019-11-19 01:41:08 +03:00
==
::
+$ poke
$% [%launch-action [@tas path @t]]
[%contact-action contact-action]
[%group-action group-action]
2019-11-19 01:41:08 +03:00
==
--
::
|_ [bol=bowl:gall ?]
::
++ this .
::
++ prep
|= old=(unit ?)
^- (quip move _this)
?~ old
:_ this
:~ [ost.bol %peer / [our.bol %contact-store] /updates]
[ost.bol %connect / [~ /'~contacts'] %contact-view]
(launch-poke [/configs '/~contacts/js/tile.js'])
(contact-poke [%create /~/default])
(group-poke [%bundle /~/default])
(contact-poke [%add /~/default our.bol *contact])
(group-poke [%add [our.bol ~ ~] /~/default])
2019-11-19 01:41:08 +03:00
==
[~ this(+<+ u.old)]
::
++ poke-json
|= jon=json
2019-11-19 01:41:08 +03:00
^- (quip move _this)
?> (team:title our.bol src.bol)
(poke-contact-view-action (json-to-view-action jon))
::
++ poke-contact-view-action
|= act=contact-view-action
^- (quip move _this)
?> (team:title our.bol src.bol)
:_ this
?- -.act
%create
:~ (group-poke [%bundle path.act])
(contact-poke [%create path.act])
==
::
%delete
:~ (group-poke [%unbundle path.act])
(contact-poke [%delete path.act])
==
::
%add
:~ (group-poke [%add [ship.act ~ ~] path.act])
(contact-poke [%add path.act ship.act contact.act])
==
::
%remove
:~ (group-poke [%remove [ship.act ~ ~] path.act])
(contact-poke [%remove path.act ship.act])
==
==
::
++ peer-primary
|= pax=path
^- (quip move _this)
?> (team:title our.bol src.bol)
:: create inbox with 100 messages max per mailbox and send that along
:: then quit the subscription
:_ this
[ost.bol %diff %json (rolodex-to-json all-scry)]~
::
++ diff-contact-update
|= [wir=wire upd=contact-update]
^- (quip move _this)
=/ updates-json (update-to-json upd)
:_ this
%+ turn (prey:pubsub:userlib /primary bol)
|= [=bone *]
[bone %diff %json updates-json]
::
++ quit
|= wir=wire
^- (quip move _this)
:_ this
[ost.bol %peer / [our.bol %contact-store] /updates]~
2019-11-19 01:41:08 +03:00
::
++ poke-handle-http-request
%- (require-authorization:app ost.bol move this)
|= =inbound-request:eyre
^- (quip move _this)
::
=+ url=(parse-request-line url.request.inbound-request)
=/ name=@t
=+ back-path=(flop site.url)
?~ back-path
''
i.back-path
?: =(name 'tile')
[[ost.bol %http-response (js-response:app tile-js)]~ this]
?+ site.url
:_ this
[ost.bol %http-response not-found:app]~
::
:: styling
::
[%'~contacts' %css %index ~]
:_ this
[ost.bol %http-response (css-response:app style)]~
::
:: javascript
::
[%'~contacts' %js %index ~]
:_ this
[ost.bol %http-response (js-response:app script)]~
::
:: images
::
[%'~contacts' %img *]
=/ img (as-octs:mimes:html (~(got by contact-png) `@ta`name))
:_ this
[ost.bol %http-response (png-response:app img)]~
::
:: main page
::
[%'~contacts' *]
:_ this
[ost.bol %http-response (html-response:app index)]~
==
::
++ bound
|= [wir=wire success=? binding=binding:eyre]
^- (quip move _this)
[~ this]
2019-11-19 01:41:08 +03:00
::
:: +utilities
::
++ contact-poke
|= act=contact-action
^- move
[ost.bol %poke / [our.bol %contact-store] [%contact-action act]]
::
2019-11-19 01:41:08 +03:00
++ launch-poke
|= [pax=path =cord]
^- move
[ost.bol %poke / [our.bol %launch] [%launch-action [%contact-view pax cord]]]
::
++ group-poke
|= act=group-action
^- move
[ost.bol %poke / [our.bol %group-store] [%group-action act]]
::
++ all-scry
^- rolodex
.^(rolodex %gx /=contact-store/(scot %da now.bol)/all/noun)
2019-11-19 01:41:08 +03:00
--