profile: design tweaks

This commit is contained in:
James Acklin 2021-02-24 21:32:08 -05:00
parent cc6adb3ffd
commit a3052004f2
2 changed files with 114 additions and 105 deletions

View File

@ -1,16 +1,10 @@
import React, { ReactElement, useEffect, useRef, useState } from 'react'; import React, { ReactElement, useEffect, useRef, useState } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { import { Center, Box, Row, BaseImage, Text } from '@tlon/indigo-react';
Center,
Box,
Row,
BaseImage,
Text
} from "@tlon/indigo-react";
import RichText from '~/views/components/RichText' import RichText from '~/views/components/RichText';
import useLocalState from "~/logic/state/local"; import useLocalState from '~/logic/state/local';
import { Sigil } from '~/logic/lib/sigil'; import { Sigil } from '~/logic/lib/sigil';
import { ViewProfile } from './ViewProfile'; import { ViewProfile } from './ViewProfile';
import { EditProfile } from './EditProfile'; import { EditProfile } from './EditProfile';
@ -31,78 +25,106 @@ export function Profile(props: any): ReactElement {
const nacked = nackedContacts.has(ship); const nacked = nackedContacts.has(ship);
useEffect(() => { useEffect(() => {
if(hasLoaded && !contact && !nacked) { if (hasLoaded && !contact && !nacked) {
props.api.contacts.retrieve(ship); props.api.contacts.retrieve(ship);
} }
}, [hasLoaded, contact]); }, [hasLoaded, contact]);
const hexColor = contact?.color ? `#${uxToHex(contact.color)}` : '#000000'; const hexColor = contact?.color ? `#${uxToHex(contact.color)}` : '#000000';
const cover = (contact?.cover) const cover = contact?.cover ? (
? <BaseImage src={contact.cover} width='100%' height='100%' style={{ objectFit: 'cover' }} /> <BaseImage
: <Box display="block" width='100%' height='100%' backgroundColor='washedGray' />; src={contact.cover}
width='100%'
height='100%'
style={{ objectFit: 'cover' }}
/>
) : (
<Box
display='block'
width='100%'
height='100%'
backgroundColor='washedGray'
/>
);
const image = (!hideAvatars && contact?.avatar) const image =
? <BaseImage src={contact.avatar} width='100%' height='100%' style={{ objectFit: 'cover' }} /> !hideAvatars && contact?.avatar ? (
: <Sigil padding={24} ship={ship} size={128} color={hexColor} />; <BaseImage
src={contact.avatar}
width='100%'
height='100%'
style={{ objectFit: 'cover' }}
/>
) : (
<Sigil padding={24} ship={ship} size={128} color={hexColor} />
);
const anchorRef = useRef<HTMLElement | null>(null); const anchorRef = useRef<HTMLElement | null>(null);
useTutorialModal('profile', ship === `~${window.ship}`, anchorRef.current); useTutorialModal('profile', ship === `~${window.ship}`, anchorRef.current);
return ( return (
<Center <Center p={[0, 4]} height='100%' width='100%'>
p={[0,4]} <Box ref={anchorRef} maxWidth='600px' width='100%'>
height="100%" <Box border='1px solid' borderColor='lightGray' borderRadius='2'>
width="100%" <Row alignItems='center' justifyContent='space-between' px='3'>
> <Row>
{ship === `~${window.ship}` ? (
<Box <>
ref={anchorRef} <Text
maxWidth="600px" py='2'
width="100%" cursor='pointer'
> fontWeight='500'
<Row alignItems="center" justifyContent="space-between"> onClick={() => {
<Row> history.push(`/~profile/${ship}/edit`);
{ship === `~${window.ship}` ? ( }}
<> >
<Text Edit {isPublic ? 'Public' : 'Private'} Profile
</Text>
<SetStatusBarModal
isControl
py='2'
ml='3'
api={props.api}
ship={`~${window.ship}`}
contact={contact}
/>
</>
) : null}
</Row>
<RichText
mb='0'
py='2' py='2'
cursor='pointer' disableRemoteContent
onClick={() => { maxWidth='18rem'
history.push(`/~profile/${ship}/edit`); overflowX='hidden'
}} textOverflow='ellipsis'
whiteSpace='nowrap'
overflow='hidden'
display='inline-block'
verticalAlign='middle'
color='gray'
> >
Edit Profile {contact?.status ?? ''}
</Text> </RichText>
<SetStatusBarModal
py='2'
ml='3'
api={props.api}
ship={`~${window.ship}`}
contact={contact}
/>
</>
) : null}
</Row> </Row>
<RichText mb='0' py='2' disableRemoteContent maxWidth='18rem' overflowX='hidden' textOverflow="ellipsis" <Row width='100%' height='300px'>
whiteSpace="nowrap" {cover}
overflow="hidden" display="inline-block" verticalAlign="middle">{contact?.status ?? ""}</RichText> </Row>
</Row> </Box>
<Row width="100%" height="300px"> <Row pb={2} alignItems='center' width='100%'>
{cover} <Center width='100%' marginTop='-64px'>
</Row> <Box
<Row height='128px'
pb={2} width='128px'
alignItems="center" borderRadius='2'
width="100%" overflow='hidden'
> >
<Center width="100%" marginTop="-48px">
<Box height='128px' width='128px' borderRadius="2" overflow="hidden">
{image} {image}
</Box> </Box>
</Center> </Center>
</Row> </Row>
{ isEdit ? ( {isEdit ? (
<EditProfile <EditProfile
ship={ship} ship={ship}
contact={contact} contact={contact}
@ -122,7 +144,7 @@ export function Profile(props: any): ReactElement {
groups={props.groups} groups={props.groups}
associations={props.associations} associations={props.associations}
/> />
) } )}
</Box> </Box>
</Center> </Center>
); );

View File

@ -1,31 +1,18 @@
import React, { import React, { useState, useEffect } from 'react';
useState,
useEffect
} from 'react';
import { import { Row, Box, Text } from '@tlon/indigo-react';
Row,
Box,
Text
} from '@tlon/indigo-react';
import { SetStatus } from '~/views/apps/profile/components/SetStatus'; import { SetStatus } from '~/views/apps/profile/components/SetStatus';
export const SetStatusBarModal = (props) => { export const SetStatusBarModal = (props) => {
const { const { ship, contact, api, isControl, ...rest } = props;
ship,
contact,
api,
...rest
} = props;
const [modalShown, setModalShown] = useState(false); const [modalShown, setModalShown] = useState(false);
const handleKeyDown = (event) => { const handleKeyDown = (event) => {
if (event.key === 'Escape') { if (event.key === 'Escape') {
setModalShown(false); setModalShown(false);
} }
} };
useEffect(() => { useEffect(() => {
window.addEventListener('keydown', handleKeyDown); window.addEventListener('keydown', handleKeyDown);
@ -40,28 +27,28 @@ export const SetStatusBarModal = (props) => {
{modalShown && ( {modalShown && (
<Box <Box
backgroundColor='scales.black30' backgroundColor='scales.black30'
left="0px" left='0px'
top="0px" top='0px'
width="100%" width='100%'
height="100%" height='100%'
zIndex={4} zIndex={4}
position="fixed" position='fixed'
display="flex" display='flex'
justifyContent="center" justifyContent='center'
alignItems="center" alignItems='center'
onClick={() => setModalShown(false)} onClick={() => setModalShown(false)}
> >
<Box <Box
maxWidth="500px" maxWidth='500px'
width="100%" width='100%'
bg="white" bg='white'
borderRadius={2} borderRadius={2}
border={[0, 1]} border={[0, 1]}
borderColor={["washedGray", "washedGray"]} borderColor={['washedGray', 'washedGray']}
onClick={e => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
display="flex" display='flex'
alignItems="stretch" alignItems='stretch'
flexDirection="column" flexDirection='column'
> >
<Box m={3}> <Box m={3}>
<SetStatus <SetStatus
@ -70,23 +57,23 @@ export const SetStatusBarModal = (props) => {
api={api} api={api}
callback={() => { callback={() => {
setModalShown(false); setModalShown(false);
}} /> }}
/>
</Box> </Box>
</Box> </Box>
</Box> </Box>
)} )}
<Row <Row {...rest} flexShrink={0} onClick={() => setModalShown(true)}>
{...rest} <Text
flexShrink={0} color='black'
onClick={() => setModalShown(true)}>
<Text color='black'
cursor='pointer' cursor='pointer'
fontWeight={isControl ? '500' : '400'}
flexShrink={0} flexShrink={0}
fontSize={1}> fontSize={1}
>
Set Status Set Status
</Text> </Text>
</Row> </Row>
</> </>
); );
} };