contacts: added "url" avatar support and finished "octet" avatar

fetching support
This commit is contained in:
Logan Allen 2020-04-21 15:29:47 -04:00
parent dbc172af29
commit 2f7e8fd811
4 changed files with 96 additions and 40 deletions

View File

@ -5,18 +5,20 @@
+$ card card:agent:gall
+$ versioned-state
$% state-zero
state-one
==
::
+$ state-zero
$: %0
=rolodex
rolodex=rolodex-0
==
+$ diff
$% [%contact-update contact-update]
+$ state-one
$: %1
=rolodex
==
--
::
=| state-zero
=| state-one
=* state -
%- agent:dbug
^- agent:gall
@ -30,8 +32,26 @@
++ on-init on-init:def
++ on-save !>(state)
++ on-load
|= old=vase
`this(state !<(state-zero old))
|= old-vase=vase
=/ old !<(versioned-state old-vase)
?: ?=(%1 -.old)
[~ this(state old)]
=/ new-rolodex=^rolodex
%- ~(run by rolodex.old)
|= cons=contacts-0
^- contacts
%- ~(run by cons)
|= con=contact-0
^- contact
:* nickname.con
email.con
phone.con
website.con
notes.con
color.con
~
==
[~ this(state [%1 new-rolodex])]
::
++ on-poke
|= [=mark =vase]

View File

@ -15,38 +15,34 @@
|= [pax=^path =contacts]
^- [cord json]
:- (spat pax)
(contacts-to-json contacts)
(contacts-to-json pax contacts)
::
++ contacts-to-json
|= con=contacts
|= [=path con=contacts]
^- json
=, enjs:format
%- pairs
%- pairs:enjs:format
%+ turn ~(tap by con)
|= [shp=^ship =contact]
|= [=ship =contact]
^- [cord json]
:- (crip (slag 1 (scow %p shp)))
(contact-to-json contact)
[(crip (slag 1 (scow %p ship))) (contact-to-json path ship contact)]
::
++ contact-to-json
|= con=contact
|= [=path =ship con=contact]
^- json
=, enjs:format
%- pairs
%- pairs:enjs:format
:~ [%nickname s+nickname.con]
[%email s+email.con]
[%phone s+phone.con]
[%website s+website.con]
[%notes s+notes.con]
[%color s+(scot %ux color.con)]
[%avatar s+'TODO']
[%avatar (avatar-to-json path ship avatar.con)]
==
::
++ edit-to-json
|= edit=edit-field
|= [=path =ship edit=edit-field]
^- json
=, enjs:format
%+ frond -.edit
%+ frond:enjs:format -.edit
?- -.edit
%nickname s+nickname.edit
%email s+email.edit
@ -54,7 +50,27 @@
%website s+website.edit
%notes s+notes.edit
%color s+(scot %ux color.edit)
%avatar s+'TODO'
%avatar (avatar-to-json path ship avatar.edit)
==
::
++ avatar-to-json
|= [=path =ship avat=(unit avatar)]
^- json
?~ avat ~
?- -.u.avat
%octt
:- %s
%- crip
%- zing
:~ "/~groups/img"
(trip (spat path))
"/"
(trip (scot %p ship))
"."
(trip file-extension.u.avat)
==
::
%url s+url.u.avat
==
::
++ update-to-json
@ -73,7 +89,7 @@
%- pairs
:~ [%path (path path.upd)]
[%ship (ship ship.upd)]
[%contact (contact-to-json contact.upd)]
[%contact (contact-to-json path.upd ship.upd contact.upd)]
==
?: ?=(%remove -.upd)
:- %remove
@ -86,7 +102,7 @@
%- pairs
:~ [%path (path path.upd)]
[%ship (ship ship.upd)]
[%edit-field (edit-to-json edit-field.upd)]
[%edit-field (edit-to-json path.upd ship.upd edit-field.upd)]
==
[*@t *^json]
==
@ -179,10 +195,24 @@
==
::
++ avat
%- ot:dejs:format
:~ [%content-type so:dejs:format]
[%octs octet]
==
|= jon=json
^- avatar
=< (parse-json jon)
|%
++ parse-json
%- of:dejs:format
:~ [%octt octt]
[%url url]
==
::
++ octt
%- ot:dejs:format
:~ [%file-extension so:dejs:format]
[%octs octet]
==
::
++ url so:dejs:format
--
::
++ cont
%- ot:dejs:format

View File

@ -1,10 +1,26 @@
/- *identity
|%
+$ rolodex (map path contacts)
+$ rolodex-0 (map path contacts-0)
+$ rolodex (map path contacts)
::
+$ contacts (map ship contact)
+$ contacts-0 (map ship contact-0)
+$ contacts (map ship contact)
::
+$ avatar [content-type=@t octs=[p=@ud q=@t]]
+$ avatar-0 [content-type=@t octs=[p=@ud q=@t]]
+$ avatar
$% [%octt [file-extension=@t octs=[p=@ud q=@t]]]
[%url url=@t]
==
::
+$ contact-0
$: nickname=@t
email=@t
phone=@t
website=@t
notes=@t
color=@ux
avatar=(unit avatar-0)
==
::
+$ contact
$: nickname=@t

View File

@ -379,15 +379,6 @@ export class ContactCard extends Component {
);
}
let removeImage = hasAvatar ? (
<div>
<button className="f9 black pointer db"
onClick={() => this.setField("removeAvatar")}>
Remove photo
</button>
</div>
) : "";
let avatar = (hasAvatar)
? <img className="dib h-auto" width={128} src={props.contact.avatar} />
: <Sigil
@ -401,7 +392,6 @@ export class ContactCard extends Component {
<div className="w-100 mw6 tc">
{avatar}
{sigilColor}
{removeImage}
<div className="w-100 pt8 pb8 lh-copy tl">
<p className="f9 gray2">Ship Name</p>
<p className="f8 mono">~{props.ship}</p>