verdnatura-chat/app/containers/Avatar/AvatarContainer.tsx

77 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-12-21 22:41:22 +00:00
import React from 'react';
import { shallowEqual, useSelector } from 'react-redux';
2022-12-21 22:41:22 +00:00
import { IApplicationState } from '../../definitions';
import { getUserSelector } from '../../selectors/login';
import Avatar from './Avatar';
import { IAvatar } from './interfaces';
2022-12-21 22:41:22 +00:00
import { useAvatarETag } from './useAvatarETag';
2022-12-20 18:13:31 +00:00
interface IAvatarContainer extends IAvatar {
handleEdit?: () => void;
}
2022-12-20 16:40:53 +00:00
const AvatarContainer = ({
style,
text = '',
avatar,
emoji,
size,
borderRadius,
type,
children,
onPress,
getCustomEmoji,
isStatic,
2023-01-06 20:51:16 +00:00
rid
2022-12-20 16:40:53 +00:00
}: IAvatarContainer): React.ReactElement => {
const server = useSelector((state: IApplicationState) => state.share.server.server || state.server.server);
const serverVersion = useSelector((state: IApplicationState) => state.share.server.version || state.server.version);
const { id, token, username } = useSelector(
(state: IApplicationState) => ({
id: getUserSelector(state).id,
token: getUserSelector(state).token,
username: getUserSelector(state).username
}),
shallowEqual
);
const externalProviderUrl = useSelector(
(state: IApplicationState) => state.settings.Accounts_AvatarExternalProviderUrl as string
);
const blockUnauthenticatedAccess = useSelector(
(state: IApplicationState) =>
(state.share.settings?.Accounts_AvatarBlockUnauthenticatedAccess as boolean) ??
state.settings.Accounts_AvatarBlockUnauthenticatedAccess ??
true
);
[NEW] Channel avatars (#2504) * [WIP] Avatar cache invalidation * [WIP] Avatar container * [IMPROVEMENT] Avatar container * [CHORE] Improve code * Allow static image on Avatar * Fix avatar changing while change username (#1583) Co-authored-by: Prateek93a <prateek93a@gmail.com> * Add default props to properly update on Sidebar and ProfileView * Fix subscribing on the wrong moment * Storyshots update * RoomItem using Avatar Component * use iife to unsubscribe from user * Use component on avatar container * RoomItem as a React.Component * Move servers models to servers folder * Avatar -> AvatarContainer * Users indexed fields * Initialize author and check if u is present * Not was found -> User not found (turn comments more relevant) * RoomItemInner -> Wrapper * Revert Avatar Touchable logic * Revert responsability of LeftButton on Tablet Mode * Prevent setState on constructor * Run avatarURL only when its not static * Add streams RC Version * Move entire add user logic to result.success * Reorder init on RoomItem * onPress as a class function * Fix roomItem using same username * Add avatar Stories * Fix pick an image from gallery on ProfileView * Format Avatar URL to use RoomId. Co-authored-by: Ezequiel De Oliveira <ezequiel1de1oliveira@gmail.com> * edit room avatar * invalidate cache of room images * reinit avatar if something change * read avatar cache on search * room avatar changed system message * add avatar by rid test * update snapshot * etag cache on select channel * reset room avatar * increase caching to have a better image quality * fix lgtm warn * invalidate ci cache * get avatar etag on select users of create discussion * invalidate ci cache * Fix migration * Fix sidebar avatar not updating * Remove outdated comment * Tests Co-authored-by: Prateek93a <prateek93a@gmail.com> Co-authored-by: Diego Mello <diegolmello@gmail.com> Co-authored-by: Ezequiel De Oliveira <ezequiel1de1oliveira@gmail.com>
2020-10-30 13:51:04 +00:00
2022-12-21 22:41:22 +00:00
const { avatarETag } = useAvatarETag({ username, text, type, rid });
return (
2023-01-06 20:51:16 +00:00
<Avatar
server={server}
style={style}
text={text}
avatar={avatar}
emoji={emoji}
size={size}
borderRadius={borderRadius}
type={type}
children={children}
userId={id}
token={token}
onPress={onPress}
getCustomEmoji={getCustomEmoji}
isStatic={isStatic}
rid={rid}
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
externalProviderUrl={externalProviderUrl}
avatarETag={avatarETag}
serverVersion={serverVersion}
/>
);
};
export default AvatarContainer;