1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

displaying profile backdrop

This commit is contained in:
Fedor Katurov 2019-11-13 16:15:00 +07:00
parent 0eae79ec08
commit 327272a08a
5 changed files with 99 additions and 6 deletions

View file

@ -0,0 +1,35 @@
import React, { FC, useState, useCallback, useEffect } from 'react';
import { IUser } from '~/redux/auth/types';
import styles from './styles.scss';
import { getURL } from '~/utils/dom';
import { PRESETS } from '~/constants/urls';
import classNames from 'classnames';
interface IProps {
cover: IUser['cover'];
}
const ProfileBackdrop: FC<IProps> = ({ cover }) => {
const [is_loaded, setIsLoaded] = useState(false);
const onLoad = useCallback(() => setIsLoaded(true), [setIsLoaded]);
const image = getURL(cover, PRESETS.cover);
useEffect(() => {
setIsLoaded(false);
}, [cover]);
if (!cover) return null;
return (
<div
className={classNames(styles.cover, { [styles.active]: is_loaded })}
style={{ backgroundImage: `url("${image}")` }}
>
<img src={image} onLoad={onLoad} />
</div>
);
};
export { ProfileBackdrop };