diff --git a/pkg/interface/src/logic/state/contact.ts b/pkg/interface/src/logic/state/contact.ts index fa78d54e8..4646edab5 100644 --- a/pkg/interface/src/logic/state/contact.ts +++ b/pkg/interface/src/logic/state/contact.ts @@ -1,4 +1,4 @@ -import { Contact, Patp, Rolodex } from '@urbit/api'; +import { Contact, deSig, Patp, Rolodex } from '@urbit/api'; import { useCallback } from 'react'; import _ from 'lodash'; import { reduce, reduceNacks } from '../reducers/contact-update'; @@ -43,7 +43,7 @@ const useContactState = createState( export function useContact(ship: string) { return useContactState( - useCallback(s => s.contacts[ship] as Contact | null, [ship]) + useCallback(s => s.contacts[`~${deSig(ship)}`] as Contact | null, [ship]) ); } diff --git a/pkg/interface/src/views/components/Author.tsx b/pkg/interface/src/views/components/Author.tsx index b771765df..3eac067dd 100644 --- a/pkg/interface/src/views/components/Author.tsx +++ b/pkg/interface/src/views/components/Author.tsx @@ -3,9 +3,9 @@ import moment from 'moment'; import React, { ReactElement, ReactNode } from 'react'; import { Sigil } from '~/logic/lib/sigil'; import { useCopy } from '~/logic/lib/useCopy'; -import { cite, deSig, useShowNickname, uxToHex } from '~/logic/lib/util'; -import useContactState from '~/logic/state/contact'; -import useLocalState from '~/logic/state/local'; +import { cite, useShowNickname, uxToHex } from '~/logic/lib/util'; +import { useContact } from '~/logic/state/contact'; +import { useDark } from '~/logic/state/join'; import useSettingsState, { selectCalmState } from '~/logic/state/settings'; import { PropFunc } from '~/types'; import ProfileOverlay from './ProfileOverlay'; @@ -23,7 +23,7 @@ export interface AuthorProps { } // eslint-disable-next-line max-lines-per-function -export default function Author(props: AuthorProps & PropFunc): ReactElement { +function Author(props: AuthorProps & PropFunc): ReactElement { const { ship = '', date, @@ -41,16 +41,9 @@ export default function Author(props: AuthorProps & PropFunc): React const size = props.size || 16; const sigilPadding = props.sigilPadding || 2; - const osDark = useLocalState(state => state.dark); + const dark = useDark(); - const theme = useSettingsState(s => s.display.theme); - const dark = theme === 'dark' || (theme === 'auto' && osDark); - - let contact; - const contacts = useContactState(state => state.contacts); - if (contacts) { - contact = `~${deSig(ship)}` in contacts ? contacts[`~${deSig(ship)}`] : null; - } + const contact = useContact(ship); const color = contact?.color ? `#${uxToHex(contact?.color)}` : dark ? '#000000' : '#FFFFFF'; const showNickname = useShowNickname(contact); const { hideAvatars } = useSettingsState(selectCalmState); @@ -124,3 +117,5 @@ export default function Author(props: AuthorProps & PropFunc): React ); } + +export default React.memo(Author);