diff --git a/lib/hooks/avatar-hooks.js b/lib/hooks/avatar-hooks.js new file mode 100644 --- /dev/null +++ b/lib/hooks/avatar-hooks.js @@ -0,0 +1,20 @@ +// @flow + +import { threadInfoSelector } from '../selectors/thread-selectors.js'; +import { getAvatarForThread } from '../shared/avatar-utils.js'; +import type { ClientAvatar } from '../types/avatar-types.js'; +import type { + ThreadInfo, + RawThreadInfo, +} from '../types/minimally-encoded-thread-permissions-types.js'; +import { useSelector } from '../utils/redux-utils.js'; + +function useAvatarForThread(thread: RawThreadInfo | ThreadInfo): ClientAvatar { + const { containingThreadID } = thread; + const containingThreadInfo = useSelector(state => + containingThreadID ? threadInfoSelector(state)[containingThreadID] : null, + ); + return getAvatarForThread(thread, containingThreadInfo); +} + +export { useAvatarForThread }; diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js --- a/lib/shared/avatar-utils.js +++ b/lib/shared/avatar-utils.js @@ -8,7 +8,6 @@ import { threadOtherMembers } from './thread-utils.js'; import genesis from '../facts/genesis.js'; import { useENSAvatar } from '../hooks/ens-cache.js'; -import { threadInfoSelector } from '../selectors/thread-selectors.js'; import { getETHAddressForUserInfo } from '../shared/account-utils.js'; import type { ClientAvatar, @@ -22,7 +21,6 @@ } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; import type { UserInfos } from '../types/user-types.js'; -import { useSelector } from '../utils/redux-utils.js'; const defaultAnonymousUserEmojiAvatar: ClientEmojiAvatar = { color: selectedThreadColors[4], @@ -316,15 +314,6 @@ return getDefaultAvatar(thread.id, thread.color); } -function useAvatarForThread(thread: RawThreadInfo | ThreadInfo): ClientAvatar { - const containingThreadID = thread.containingThreadID; - const containingThreadInfo = useSelector(state => - containingThreadID ? threadInfoSelector(state)[containingThreadID] : null, - ); - - return getAvatarForThread(thread, containingThreadInfo); -} - function useENSResolvedAvatar( avatarInfo: ClientAvatar, userInfo: ?GenericUserInfoWithAvatar, @@ -362,6 +351,5 @@ getAvatarForUser, getUserAvatarForThread, getAvatarForThread, - useAvatarForThread, useENSResolvedAvatar, }; diff --git a/native/avatars/thread-avatar.react.js b/native/avatars/thread-avatar.react.js --- a/native/avatars/thread-avatar.react.js +++ b/native/avatars/thread-avatar.react.js @@ -2,10 +2,8 @@ import * as React from 'react'; -import { - useAvatarForThread, - useENSResolvedAvatar, -} from 'lib/shared/avatar-utils.js'; +import { useAvatarForThread } from 'lib/hooks/avatar-hooks.js'; +import { useENSResolvedAvatar } from 'lib/shared/avatar-utils.js'; import { getSingleOtherUser } from 'lib/shared/thread-utils.js'; import type { AvatarSize } from 'lib/types/avatar-types.js'; import type { diff --git a/web/avatars/thread-avatar.react.js b/web/avatars/thread-avatar.react.js --- a/web/avatars/thread-avatar.react.js +++ b/web/avatars/thread-avatar.react.js @@ -2,10 +2,8 @@ import * as React from 'react'; -import { - useAvatarForThread, - useENSResolvedAvatar, -} from 'lib/shared/avatar-utils.js'; +import { useAvatarForThread } from 'lib/hooks/avatar-hooks.js'; +import { useENSResolvedAvatar } from 'lib/shared/avatar-utils.js'; import { getSingleOtherUser } from 'lib/shared/thread-utils.js'; import type { AvatarSize } from 'lib/types/avatar-types.js'; import type { diff --git a/web/avatars/thread-emoji-avatar-selection-modal.react.js b/web/avatars/thread-emoji-avatar-selection-modal.react.js --- a/web/avatars/thread-emoji-avatar-selection-modal.react.js +++ b/web/avatars/thread-emoji-avatar-selection-modal.react.js @@ -4,10 +4,8 @@ import * as React from 'react'; import { EditThreadAvatarContext } from 'lib/components/base-edit-thread-avatar-provider.react.js'; -import { - getDefaultAvatar, - useAvatarForThread, -} from 'lib/shared/avatar-utils.js'; +import { useAvatarForThread } from 'lib/hooks/avatar-hooks.js'; +import { getDefaultAvatar } from 'lib/shared/avatar-utils.js'; import type { ClientAvatar, ClientEmojiAvatar,