Skip to content

Commit

Permalink
feat(smartAvatar): ACT-761 add smartAvatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-wolf3d committed Aug 5, 2024
1 parent 95e47a1 commit 33aead5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/components/SmartAvatar/SmartAvatar.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { FC, useMemo } from 'react';
import { useDeviceDetector, DeviceDetectorHookProps } from 'src/hooks/useDeviceDetector/use-device-detector.hook';
import qs from 'qs';
import { Avatar, AvatarProps } from '../Avatar';

export interface SmartAvatarProps extends AvatarProps, DeviceDetectorHookProps {}

/**
* Detects the device performance and adjusts the avatar props accordingly
*/

const SmartAvatar: FC<SmartAvatarProps> = (props) => {
const deviceDetector = useDeviceDetector(props);

const updatedProps: AvatarProps = useMemo(() => {
if (props.modelSrc instanceof Blob) {
return props;
}
const [modelUrl, originalQueryParams] = props.modelSrc.split('?');

const queryStringParams = {
...qs.parse(originalQueryParams),
...qs.parse(deviceDetector?.toQueryString() || '')
};

return {
...props,
modelSrc: `${modelUrl}?${qs.stringify(queryStringParams)}`
};
}, [props, deviceDetector]);

return <Avatar {...updatedProps} />;
};

export default SmartAvatar;

0 comments on commit 33aead5

Please sign in to comment.