contacts + interface: hooked up isPublic to interface

This commit is contained in:
Logan Allen 2021-01-28 14:45:28 -06:00
parent 520a7c2d7c
commit 8ac1a9768d
10 changed files with 86 additions and 34 deletions

View File

@ -53,7 +53,7 @@
|^
=/ cards=(list card)
?+ path (on-watch:def path)
[%all ~] (give [%initial rolodex])
[%all ~] (give [%initial rolodex is-public])
[%updates ~] ~
::
[%our ~]
@ -99,11 +99,11 @@
==
::
++ handle-initial
|= rolo=rolodex:store
|= [rolo=rolodex:store is-public=?]
^- (quip card _state)
=. rolodex (~(uni by rolodex) rolo)
:_ state(rolodex rolodex)
(send-diff [%initial rolodex] %.n)
:_ state(rolodex rolodex, is-public is-public)
(send-diff [%initial rolodex is-public] %.n)
::
++ handle-add
|= [=ship =contact:store]

View File

@ -20,7 +20,11 @@
^- [cord json]
?- -.upd
%initial
[%initial (rolo rolodex.upd)]
:- %initial
%- pairs
:~ [%rolodex (rolo rolodex.upd)]
[%is-public b+is-public.upd]
==
::
%add
:- %add
@ -118,7 +122,11 @@
[%set-public bo]
==
::
++ initial (op ;~(pfix sig fed:ag) cont)
++ initial
%- ot
:~ [%rolodex (op ;~(pfix sig fed:ag) cont)]
[%is-public bo]
==
::
++ add-contact
%- ot

View File

@ -29,7 +29,7 @@
==
::
+$ update
$% [%initial =rolodex]
$% [%initial =rolodex is-public=?]
[%add =ship =contact]
[%remove =ship]
[%edit =ship =edit-field]

View File

@ -32,6 +32,12 @@ export default class ContactsApi extends BaseApi<StoreState> {
});
}
setPublic(setPublic: any) {
return this.storeAction({
'set-public': setPublic
});
}
private storeAction(action: any): Promise<any> {
return this.action('contact-store', 'contact-update', action)
}

View File

@ -13,6 +13,7 @@ export const ContactReducer = (json, state) => {
add(data, state);
remove(data, state);
edit(data, state);
setPublic(data, state);
console.log(state.contacts);
}
};
@ -20,7 +21,8 @@ export const ContactReducer = (json, state) => {
const initial = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'initial', false);
if (data) {
state.contacts = data;
state.contacts = data.rolodex;
state.isContactPublic = data['is-public'];
}
};
@ -55,3 +57,10 @@ const edit = (json: ContactUpdate, state: S) => {
state.contacts[ship][edit[0]] = data['edit-field'][edit[0]];
}
};
const setPublic = (json: ContactUpdate, state: S) => {
const data = _.get(json, 'set-public', false);
state.isContactPublic = data;
};

View File

@ -74,6 +74,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
},
credentials: null
},
isContactPublic: false,
contacts: {},
notifications: new BigIntOrderedMap<Timebox>(),
archivedNotifications: new BigIntOrderedMap<Timebox>(),

View File

@ -4,6 +4,7 @@ import * as Yup from "yup";
import {
ManagedForm as Form,
ManagedTextInputField as Input,
ManagedCheckboxField as Checkbox,
Center,
Col,
Box,
@ -37,13 +38,17 @@ const emptyContact = {
avatar: null,
cover: null,
groups: [],
'last-updated': 0
'last-updated': 0,
isPublic: false
};
export function EditProfile(props: any) {
const { contact, ship, api } = props;
const { contact, ship, api, isPublic } = props;
const history = useHistory();
if (contact) {
contact.isPublic = isPublic;
}
const onSubmit = async (values: any, actions: any) => {
console.log(values);
@ -52,14 +57,25 @@ export function EditProfile(props: any) {
console.log(key);
const newValue = key !== "color" ? values[key] : uxToHex(values[key]);
if (newValue !== contact[key] && key !== "groups" && key !== "last-updated") {
return acc.then(() =>
api.contacts.edit(ship, { [key]: newValue })
);
if (newValue !== contact[key]) {
if (key === "isPublic") {
return acc.then(() =>
api.contacts.setPublic(newValue)
);
} else if (
key !== "groups" &&
key !== "last-updated" &&
key !== "isPublic"
) {
return acc.then(() =>
api.contacts.edit(ship, { [key]: newValue })
);
}
}
return acc;
}, Promise.resolve());
actions.setStatus({ success: null });
//actions.setStatus({ success: null });
history.push(`/~profile/${ship}`);
} catch (e) {
console.error(e);
actions.setStatus({ error: e.message });
@ -79,14 +95,16 @@ export function EditProfile(props: any) {
<Text mb={2}>Description</Text>
<MarkdownField id="bio" mb={3} s3={props.s3} />
</Col>
<ColorInput id="color" label="Sigil Color" mb={3} />
<Row mb={3} width="100%">
<Col pr={2} width="40%">
<ColorInput id="color" label="Sigil Color" />
<Col pr={2} width="50%">
<ImageInput id="cover" label="Cover Image" s3={props.s3} />
</Col>
<Col pl={2} width="60%">
<ImageInput id="avatar" label="Profile Picture" s3={props.s3} />
<Col pl={2} width="50%">
<ImageInput id="avatar" label="Profile Image" s3={props.s3} />
</Col>
</Row>
<Checkbox mb={3} id="isPublic" label="Public Profile" />
<AsyncButton primary loadingText="Updating..." border>
Submit
</AsyncButton>

View File

@ -21,7 +21,7 @@ export function Profile(props: any) {
if (!props.ship) {
return null;
}
const { contact, isEdit, ship } = props;
const { contact, isPublic, isEdit, ship } = props;
const hexColor = contact?.color ? `#${uxToHex(contact.color)}` : "#000000";
const cover = (contact?.cover)
? <BaseImage src={contact.cover} width='100%' height='100%' style={{ objectFit: 'cover' }} />
@ -55,9 +55,14 @@ export function Profile(props: any) {
</Center>
</Row>
{ isEdit ? (
<EditProfile ship={ship} contact={contact} s3={props.s3} api={props.api} />
<EditProfile
ship={ship}
contact={contact}
s3={props.s3}
api={props.api}
isPublic={isPublic}/>
) : (
<ViewProfile ship={ship} contact={contact} />
<ViewProfile ship={ship} contact={contact} isPublic={isPublic} />
) }
</Box>
</Center>

View File

@ -15,7 +15,7 @@ import { useHistory } from "react-router-dom";
export function ViewProfile(props: any) {
const history = useHistory();
const { contact, ship } = props;
const { contact, isPublic, ship } = props;
return (
<>
@ -63,17 +63,20 @@ export function ViewProfile(props: any) {
</Row>
) : null
}
<Box
height="200px"
borderRadius={1}
bg="white"
border={1}
borderColor="washedGray">
<Center height="100%">
<Text mono pr={1} color="gray">{ship}</Text>
<Text color="gray">remains private</Text>
</Center>
</Box>
{ !isPublic && ship === `~${window.ship}` ? (
<Box
height="200px"
borderRadius={1}
bg="white"
border={1}
borderColor="washedGray">
<Center height="100%">
<Text mono pr={1} color="gray">{ship}</Text>
<Text color="gray">remains private</Text>
</Center>
</Box>
) : null
}
</>
);
}

View File

@ -22,6 +22,7 @@ export default function ProfileScreen(props: any) {
render={({ match, history }) => {
const ship = match.params.ship;
const isEdit = match.url.includes('edit');
const isPublic = props.isContactPublic;
const contact = props.contacts?.[ship];
const sigilColor = contact?.color
? `#${uxToHex(contact.color)}`
@ -46,6 +47,7 @@ export default function ProfileScreen(props: any) {
api={props.api}
s3={props.s3}
isEdit={isEdit}
isPublic={isPublic}
/>
</Box>
</Box>