Merge pull request #4486 from urbit/mp/landscape/authors

links, publish, notifications: work with flattened contacts
This commit is contained in:
matildepark 2021-02-23 20:18:14 -05:00 committed by GitHub
commit b4333c711e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 59 deletions

View File

@ -46,7 +46,6 @@ export function LinkResource(props: LinkResourceProps) {
const resource = associations.graph[rid] const resource = associations.graph[rid]
? associations.graph[rid] ? associations.graph[rid]
: { metadata: {} }; : { metadata: {} };
const contactDetails = contacts[resource?.group] || {};
const group = groups[resource?.group] || {}; const group = groups[resource?.group] || {};
const graph = graphs[resourcePath] || null; const graph = graphs[resourcePath] || null;
@ -99,9 +98,6 @@ export function LinkResource(props: LinkResourceProps) {
if (!node) { if (!node) {
return <Box>Not found</Box>; return <Box>Not found</Box>;
} }
const contact = contactDetails[node.post.author];
return ( return (
<Col alignItems="center" overflowY="auto" width="100%"> <Col alignItems="center" overflowY="auto" width="100%">
<Col width="100%" p={3} maxWidth="768px"> <Col width="100%" p={3} maxWidth="768px">
@ -126,7 +122,7 @@ export function LinkResource(props: LinkResourceProps) {
resource={resourcePath} resource={resourcePath}
association={association} association={association}
unreads={unreads} unreads={unreads}
contacts={contactDetails} contacts={contacts}
api={api} api={api}
editCommentId={editCommentId} editCommentId={editCommentId}
history={props.history} history={props.history}

View File

@ -11,11 +11,9 @@ import {
Groups Groups
} from '~/types'; } from '~/types';
import { Header } from './header'; import { Header } from './header';
import { cite, deSig, pluralize } from '~/logic/lib/util'; import { cite, deSig, pluralize, useShowNickname } from '~/logic/lib/util';
import { Sigil } from '~/logic/lib/sigil'; import Author from '~/views/components/Author';
import RichText from '~/views/components/RichText';
import GlobalApi from '~/logic/api/global'; import GlobalApi from '~/logic/api/global';
import ReactMarkdown from 'react-markdown';
import { getSnippet } from '~/logic/lib/publish'; import { getSnippet } from '~/logic/lib/publish';
import styled from 'styled-components'; import styled from 'styled-components';
import { MentionText } from '~/views/components/MentionText'; import { MentionText } from '~/views/components/MentionText';
@ -188,25 +186,10 @@ const GraphNode = ({
read, read,
onRead, onRead,
showContact = false, showContact = false,
}): ReactElement => { }) => {
author = deSig(author); author = deSig(author);
const history = useHistory(); const history = useHistory();
const img = showContact ? (
<Sigil
ship={`~${author}`}
size={16}
icon
color={`#000000`}
classes='mix-blend-diff'
padding={2}
/>
) : (
<Box style={{ width: '16px' }}></Box>
);
const groupContacts = contacts[groupPath] ?? {};
const nodeUrl = getNodeUrl(mod, group?.hidden, groupPath, graph, index); const nodeUrl = getNodeUrl(mod, group?.hidden, groupPath, graph, index);
const onClick = useCallback(() => { const onClick = useCallback(() => {
@ -216,34 +199,29 @@ const GraphNode = ({
history.push(nodeUrl); history.push(nodeUrl);
}, [read, onRead]); }, [read, onRead]);
const showNickname = useShowNickname(contacts?.[`~${author}`]);
const nickname = (contacts?.[`~${author}`]?.nickname && showNickname) ? contacts[`~${author}`].nickname : cite(author);
return ( return (
<Row onClick={onClick} gapX='2' pt={showContact ? 2 : 0}> <Row onClick={onClick} gapX='2' pt={showContact ? 2 : 0}>
<Col>{img}</Col>
<Col flexGrow={1} alignItems='flex-start'> <Col flexGrow={1} alignItems='flex-start'>
{showContact && ( {showContact && (
<Row <Author
mb='2' showImage
height='16px' contacts={contacts}
alignItems='center' ship={author}
p='1' date={time}
backgroundColor='white' group={group}
> />
<Text mono title={author}>
{cite(author)}
</Text>
<Text ml='2' gray>
{moment(time).format('HH:mm')}
</Text>
</Row>
)} )}
<Row width='100%' p='1' flexDirection='column'> <Row width='100%' p='1' flexDirection='column'>
<GraphNodeContent <GraphNodeContent
contacts={groupContacts} contacts={contacts}
post={post} post={post}
mod={mod} mod={mod}
description={description} description={description}
index={index} index={index}
group={group} group={group}
remoteContentPolicy={{}}
/> />
</Row> </Row>
</Col> </Col>

View File

@ -15,7 +15,7 @@ const Text = (props: PropFunc<typeof Text>) => (
); );
function Author(props: { patp: string; contacts: Contacts; last?: boolean }): ReactElement { function Author(props: { patp: string; contacts: Contacts; last?: boolean }): ReactElement {
const contact: Contact | undefined = props.contacts?.[props.patp]; const contact: Contact | undefined = props.contacts?.[`~${props.patp}`];
const showNickname = useShowNickname(contact); const showNickname = useShowNickname(contact);
const name = contact?.nickname || `~${props.patp}`; const name = contact?.nickname || `~${props.patp}`;
@ -40,8 +40,7 @@ export function Header(props: {
read: boolean; read: boolean;
associations: Associations; associations: Associations;
} & PropFunc<typeof Row> ): ReactElement { } & PropFunc<typeof Row> ): ReactElement {
const { description, channel, group, moduleIcon, read } = props; const { description, channel, contacts, moduleIcon, read } = props;
const contacts = props.contacts[group] || {};
const authors = _.uniq(props.authors); const authors = _.uniq(props.authors);

View File

@ -17,7 +17,6 @@ export function PublishResource(props: PublishResourceProps) {
const { association, api, baseUrl, notebooks } = props; const { association, api, baseUrl, notebooks } = props;
const rid = association.resource; const rid = association.resource;
const [, , ship, book] = rid.split('/'); const [, , ship, book] = rid.split('/');
const notebookContacts = props.contacts[association.group];
return ( return (
<Box height="100%" width="100%" overflowY="auto"> <Box height="100%" width="100%" overflowY="auto">
@ -29,7 +28,6 @@ export function PublishResource(props: PublishResourceProps) {
groups={props.groups} groups={props.groups}
associations={props.associations} associations={props.associations}
association={association} association={association}
notebookContacts={notebookContacts}
rootUrl={baseUrl} rootUrl={baseUrl}
baseUrl={`${baseUrl}/resource/publish/ship/${ship}/${book}`} baseUrl={`${baseUrl}/resource/publish/ship/${ship}/${book}`}
history={props.history} history={props.history}

View File

@ -13,7 +13,6 @@ interface NotebookProps {
ship: string; ship: string;
book: string; book: string;
graph: Graph; graph: Graph;
notebookContacts: Contacts;
association: Association; association: Association;
associations: Associations; associations: Associations;
contacts: Rolodex; contacts: Rolodex;
@ -27,7 +26,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps): ReactEleme
const { const {
ship, ship,
book, book,
notebookContacts, contacts,
groups, groups,
association, association,
graph graph
@ -40,8 +39,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps): ReactEleme
const relativePath = (p: string) => props.baseUrl + p; const relativePath = (p: string) => props.baseUrl + p;
const contact = notebookContacts?.[ship]; const contact = contacts?.[`~${ship}`];
const isOwn = `~${window.ship}` === ship;
console.log(association.resource); console.log(association.resource);
const showNickname = useShowNickname(contact); const showNickname = useShowNickname(contact);
@ -62,7 +60,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps): ReactEleme
graph={graph} graph={graph}
host={ship} host={ship}
book={book} book={book}
contacts={notebookContacts ? notebookContacts : {}} contacts={contacts}
unreads={props.unreads} unreads={props.unreads}
baseUrl={props.baseUrl} baseUrl={props.baseUrl}
api={props.api} api={props.api}

View File

@ -27,7 +27,7 @@ export function NotebookPosts(props: NotebookPostsProps) {
host={props.host} host={props.host}
book={props.book} book={props.book}
unreads={props.unreads} unreads={props.unreads}
contact={props.contacts[node.post.author]} contact={props.contacts[`~${node.post.author}`]}
contacts={props.contacts} contacts={props.contacts}
node={node} node={node}
baseUrl={props.baseUrl} baseUrl={props.baseUrl}

View File

@ -23,7 +23,6 @@ interface NotebookRoutesProps {
ship: string; ship: string;
book: string; book: string;
graphs: Graphs; graphs: Graphs;
notebookContacts: Contacts;
unreads: Unreads; unreads: Unreads;
contacts: Rolodex; contacts: Rolodex;
groups: Groups; groups: Groups;
@ -37,7 +36,7 @@ interface NotebookRoutesProps {
export function NotebookRoutes( export function NotebookRoutes(
props: NotebookRoutesProps & RouteComponentProps props: NotebookRoutesProps & RouteComponentProps
) { ) {
const { ship, book, api, notebookContacts, baseUrl, rootUrl, groups } = props; const { ship, book, api, contacts, baseUrl, rootUrl, groups } = props;
useEffect(() => { useEffect(() => {
ship && book && api.graph.getGraph(ship, book); ship && book && api.graph.getGraph(ship, book);
@ -60,7 +59,7 @@ export function NotebookRoutes(
return <Notebook return <Notebook
{...props} {...props}
graph={graph} graph={graph}
contacts={notebookContacts} contacts={contacts}
association={props.association} association={props.association}
rootUrl={rootUrl} rootUrl={rootUrl}
baseUrl={baseUrl} baseUrl={baseUrl}
@ -107,7 +106,7 @@ export function NotebookRoutes(
notebook={graph} notebook={graph}
unreads={props.unreads} unreads={props.unreads}
noteId={noteIdNum} noteId={noteIdNum}
contacts={notebookContacts} contacts={contacts}
association={props.association} association={props.association}
group={group} group={group}
s3={props.s3} s3={props.s3}

View File

@ -6,7 +6,7 @@ import { Row, Box, BaseImage } from '@tlon/indigo-react';
import { Contacts } from '@urbit/api/contacts'; import { Contacts } from '@urbit/api/contacts';
import { Group } from '@urbit/api'; import { Group } from '@urbit/api';
import { uxToHex, cite, useShowNickname } from '~/logic/lib/util'; import { uxToHex, cite, useShowNickname, deSig } from '~/logic/lib/util';
import OverlaySigil from './OverlaySigil'; import OverlaySigil from './OverlaySigil';
import { Sigil } from '~/logic/lib/sigil'; import { Sigil } from '~/logic/lib/sigil';
import GlobalApi from '~/logic/api/global'; import GlobalApi from '~/logic/api/global';
@ -20,7 +20,7 @@ interface AuthorProps {
children?: ReactNode; children?: ReactNode;
unread?: boolean; unread?: boolean;
group: Group; group: Group;
api: GlobalApi; api?: GlobalApi;
} }
// eslint-disable-next-line max-lines-per-function // eslint-disable-next-line max-lines-per-function
@ -29,7 +29,7 @@ export default function Author(props: AuthorProps): ReactElement {
const history = useHistory(); const history = useHistory();
let contact; let contact;
if (contacts) { if (contacts) {
contact = ship in contacts ? contacts[ship] : null; contact = `~${deSig(ship)}` in contacts ? contacts[`~${deSig(ship)}`] : null;
} }
const color = contact?.color ? `#${uxToHex(contact?.color)}` : '#000000'; const color = contact?.color ? `#${uxToHex(contact?.color)}` : '#000000';
const showNickname = useShowNickname(contact); const showNickname = useShowNickname(contact);