mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
fixed profile patching
This commit is contained in:
parent
f25d627b4e
commit
60dffc2353
6 changed files with 209 additions and 60 deletions
|
@ -1,15 +1,17 @@
|
|||
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';
|
||||
import React, { FC, useState, useCallback, useEffect, useRef } 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'];
|
||||
cover: IUser["cover"];
|
||||
}
|
||||
|
||||
const CoverBackdrop: FC<IProps> = ({ cover }) => {
|
||||
const ref = useRef<HTMLImageElement>();
|
||||
|
||||
const [is_loaded, setIsLoaded] = useState(false);
|
||||
|
||||
const onLoad = useCallback(() => setIsLoaded(true), [setIsLoaded]);
|
||||
|
@ -17,7 +19,11 @@ const CoverBackdrop: FC<IProps> = ({ cover }) => {
|
|||
const image = getURL(cover, PRESETS.cover);
|
||||
|
||||
useEffect(() => {
|
||||
if (!cover || !cover.url || !ref || !ref.current) return;
|
||||
|
||||
ref.current.src = "";
|
||||
setIsLoaded(false);
|
||||
ref.current.src = getURL(cover, PRESETS.cover);
|
||||
}, [cover]);
|
||||
|
||||
if (!cover) return null;
|
||||
|
@ -27,7 +33,7 @@ const CoverBackdrop: FC<IProps> = ({ cover }) => {
|
|||
className={classNames(styles.cover, { [styles.active]: is_loaded })}
|
||||
style={{ backgroundImage: `url("${image}")` }}
|
||||
>
|
||||
<img src={image} onLoad={onLoad} />
|
||||
<img onLoad={onLoad} ref={ref} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue