mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
dynamically loading images for hero
This commit is contained in:
parent
5cd5941be0
commit
2386b3f8d8
4 changed files with 23 additions and 7 deletions
|
@ -26,7 +26,7 @@
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: url(~/sprites/dots.svg) rgba(0, 0, 0, 0.5);
|
background: url(~/sprites/stripes.svg) rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@include tablet {
|
@include tablet {
|
||||||
|
|
|
@ -7,14 +7,13 @@ import { getURL } from '~/utils/dom';
|
||||||
import { withRouter, RouteComponentProps } from 'react-router';
|
import { withRouter, RouteComponentProps } from 'react-router';
|
||||||
import { URLS } from '~/constants/urls';
|
import { URLS } from '~/constants/urls';
|
||||||
import { Icon } from '~/components/input/Icon';
|
import { Icon } from '~/components/input/Icon';
|
||||||
import { Filler } from '~/components/containers/Filler';
|
|
||||||
|
|
||||||
type IProps = RouteComponentProps & {
|
type IProps = RouteComponentProps & {
|
||||||
heroes: IFlowState['heroes'];
|
heroes: IFlowState['heroes'];
|
||||||
};
|
};
|
||||||
|
|
||||||
const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
||||||
const [limit, setLimit] = useState(Math.max(heroes.length, 10));
|
const [limit, setLimit] = useState(Math.min(heroes.length, 6));
|
||||||
const [current, setCurrent] = useState(0);
|
const [current, setCurrent] = useState(0);
|
||||||
const [loaded, setLoaded] = useState([]);
|
const [loaded, setLoaded] = useState([]);
|
||||||
const timer = useRef(null);
|
const timer = useRef(null);
|
||||||
|
@ -31,6 +30,11 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
||||||
setCurrent(index > loaded.length - 2 ? loaded[0] : loaded[index + 1]);
|
setCurrent(index > loaded.length - 2 ? loaded[0] : loaded[index + 1]);
|
||||||
}, [loaded, current, setCurrent, timer]);
|
}, [loaded, current, setCurrent, timer]);
|
||||||
|
|
||||||
|
const onNextPress = useCallback(() => {
|
||||||
|
setLimit(Math.min(heroes.length, limit + 1));
|
||||||
|
onNext();
|
||||||
|
}, [onNext, heroes, limit, setLimit]);
|
||||||
|
|
||||||
const onPrevious = useCallback(() => {
|
const onPrevious = useCallback(() => {
|
||||||
clearTimeout(timer.current);
|
clearTimeout(timer.current);
|
||||||
|
|
||||||
|
@ -52,13 +56,13 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
||||||
}, [loaded]);
|
}, [loaded]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLimit(Math.max(heroes.length, limit));
|
setLimit(limit > 0 ? Math.min(heroes.length, limit) : heroes.length);
|
||||||
}, [heroes, limit]);
|
}, [heroes, limit]);
|
||||||
|
|
||||||
const stopSliding = useCallback(() => {
|
const stopSliding = useCallback(() => {
|
||||||
clearTimeout(timer.current);
|
clearTimeout(timer.current);
|
||||||
timer.current = setTimeout(onNext, 3000);
|
timer.current = setTimeout(onNext, 3000);
|
||||||
}, [timer]);
|
}, [timer, onNext]);
|
||||||
|
|
||||||
const onClick = useCallback(() => {
|
const onClick = useCallback(() => {
|
||||||
if (!current) return;
|
if (!current) return;
|
||||||
|
@ -66,6 +70,10 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
||||||
history.push(URLS.NODE_URL(current));
|
history.push(URLS.NODE_URL(current));
|
||||||
}, [current]);
|
}, [current]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log({ limit });
|
||||||
|
}, [limit]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap} onMouseOver={stopSliding} onFocus={stopSliding}>
|
<div className={styles.wrap} onMouseOver={stopSliding} onFocus={stopSliding}>
|
||||||
<div className={styles.info}>
|
<div className={styles.info}>
|
||||||
|
@ -77,7 +85,7 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
||||||
<div className={styles.button} onClick={onPrevious}>
|
<div className={styles.button} onClick={onPrevious}>
|
||||||
<Icon icon="left" />
|
<Icon icon="left" />
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.button} onClick={onNext}>
|
<div className={styles.button} onClick={onNextPress}>
|
||||||
<Icon icon="right" />
|
<Icon icon="right" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: url('~/sprites/dots.svg') rgba(0, 0, 0, 0.3);
|
background: url('~/sprites/stripes.svg') rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
|
|
8
src/sprites/stripes.svg
Normal file
8
src/sprites/stripes.svg
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
|
||||||
|
<defs>
|
||||||
|
<pattern id="pattern_KGiq8" patternUnits="userSpaceOnUse" width="3.5" height="3.5" patternTransform="rotate(45)">
|
||||||
|
<line x1="0" y="0" x2="0" y2="3.5" stroke="#000000" stroke-width="1" />
|
||||||
|
</pattern>
|
||||||
|
</defs>
|
||||||
|
<rect width="100%" height="100%" fill="url(#pattern_KGiq8)" opacity="1" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 371 B |
Loading…
Add table
Add a link
Reference in a new issue