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

player bar appearance

This commit is contained in:
Fedor Katurov 2019-10-15 16:29:49 +07:00
parent 794318ed80
commit 87b9b5f514
6 changed files with 118 additions and 16 deletions

View file

@ -1,4 +1,4 @@
import React, { FC } from 'react'; import React, { FC, useCallback, useState, useEffect } from 'react';
import * as styles from './styles.scss'; import * as styles from './styles.scss';
import { Icon } from '~/components/input/Icon'; import { Icon } from '~/components/input/Icon';
import { Filler } from '~/components/containers/Filler'; import { Filler } from '~/components/containers/Filler';
@ -7,27 +7,79 @@ import { connect } from 'react-redux';
import pick from 'ramda/es/pick'; import pick from 'ramda/es/pick';
import { selectPlayer } from '~/redux/player/selectors'; import { selectPlayer } from '~/redux/player/selectors';
import * as PLAYER_ACTIONS from '~/redux/player/actions'; import * as PLAYER_ACTIONS from '~/redux/player/actions';
import { IPlayerProgress, Player } from '~/utils/player';
const mapStateToProps = state => pick(['status'], selectPlayer(state)); const mapStateToProps = state => pick(['status', 'file'], selectPlayer(state));
const mapDispatchToProps = { const mapDispatchToProps = {
playerPlay: PLAYER_ACTIONS.playerPlay, playerPlay: PLAYER_ACTIONS.playerPlay,
playerPause: PLAYER_ACTIONS.playerPause, playerPause: PLAYER_ACTIONS.playerPause,
playerSeek: PLAYER_ACTIONS.playerSeek,
}; };
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {}; type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
const PlayerBarUnconnected: FC<IProps> = ({ status }) => { const PlayerBarUnconnected: FC<IProps> = ({
status,
playerPlay,
playerPause,
playerSeek,
file,
}) => {
const [progress, setProgress] = useState<IPlayerProgress>({ progress: 0, current: 0, total: 0 });
const onClick = useCallback(() => {
if (status === PLAYER_STATES.PLAYING) return playerPause();
return playerPlay();
}, [playerPlay, playerPause, status]);
const onProgress = useCallback(
({ detail }: { detail: IPlayerProgress }) => {
if (!detail || !detail.total) return;
setProgress(detail);
},
[setProgress]
);
const onSeek = useCallback(
event => {
event.stopPropagation();
const { clientX, target } = event;
const { left, width } = target.getBoundingClientRect();
playerSeek((clientX - left) / width);
},
[playerSeek]
);
useEffect(() => {
Player.on('playprogress', onProgress);
return () => {
Player.off('playprogress', onProgress);
};
}, [onProgress]);
if (status === PLAYER_STATES.UNSET) return null; if (status === PLAYER_STATES.UNSET) return null;
const title =
file.metadata &&
(file.metadata.title ||
[file.metadata.id3artist, file.metadata.id3title].filter(el => !!el).join(' - '));
return ( return (
<div className={styles.place}> <div className={styles.place}>
<div className={styles.wrap}> <div className={styles.wrap}>
<div className={styles.status}> <div className={styles.status}>
<div className={styles.playpause}> <div className={styles.playpause} onClick={onClick}>
<Icon icon="play" /> {status === PLAYER_STATES.PLAYING ? <Icon icon="pause" /> : <Icon icon="play" />}
</div> </div>
<Filler /> <div className={styles.info}>
<div className={styles.title}>{title}</div>
<div className={styles.progress} onClick={onSeek}>
<div className={styles.bar} style={{ width: `${progress.progress}%` }} />
</div>
</div>
<div className={styles.close}> <div className={styles.close}>
<Icon icon="close" /> <Icon icon="close" />

View file

@ -1,6 +1,6 @@
.place { .place {
position: relative; position: relative;
height: 54px; height: 64px;
flex: 0 1 500px; flex: 0 1 500px;
display: flex; display: flex;
@ -13,29 +13,30 @@
.wrap { .wrap {
display: flex; display: flex;
border-radius: 27px; border-radius: $radius $radius 0 0;
background: $green_gradient; background: $green_gradient;
align-items: center; align-items: center;
box-shadow: rgba(0, 0, 0, 0.5) 0 2px 5px, inset rgba(255, 255, 255, 0.3) 0 1px, box-shadow: rgba(0, 0, 0, 0.5) 0 2px 5px, inset rgba(255, 255, 255, 0.3) 1px 1px,
inset rgba(0, 0, 0, 0.3) 0 -1px; inset rgba(0, 0, 0, 0.3) 0 -1px;
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 54px; height: 64px;
flex-direction: column; flex-direction: column;
transform: translate(0, 0); transform: translate(0, 0);
z-index: 3; z-index: 3;
min-width: 0;
} }
.status { .status {
flex: 0 0 54px; flex: 0 0 64px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: 100%; width: 100%;
position: absolute; position: absolute;
z-index: 1; z-index: 1;
height: 54px; height: 64px;
} }
.playpause, .playpause,
@ -60,3 +61,50 @@
height: 24px; height: 24px;
} }
} }
.info {
display: flex;
min-width: 0;
align-items: center;
justify-content: center;
padding: 10px;
flex-direction: column;
}
.title {
color: #222222;
font: $font_14_semibold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}
.progress {
position: relative;
height: 20px;
width: 100%;
cursor: pointer;
&::after {
content: ' ';
top: 9px;
left: 0;
width: 100%;
height: 2px;
background: #222222;
position: absolute;
border-radius: 2px;
opacity: 0.5;
}
}
.bar {
top: 7px;
left: 0;
width: 100%;
height: 6px;
background: #222222;
position: absolute;
border-radius: 2px;
}

View file

@ -86,10 +86,11 @@ const AudioPlayerUnconnected = ({
{playing && status === PLAYER_STATES.PLAYING ? <Icon icon="pause" /> : <Icon icon="play" />} {playing && status === PLAYER_STATES.PLAYING ? <Icon icon="pause" /> : <Icon icon="play" />}
</div> </div>
<div className={styles.content}> <div className={styles.content}>
<div className={styles.title}>{title || 'Unknown'}</div>
<div className={styles.progress} onClick={onSeek}> <div className={styles.progress} onClick={onSeek}>
<div className={styles.bar} style={{ width: `${progress.progress}%` }} /> <div className={styles.bar} style={{ width: `${progress.progress}%` }} />
</div> </div>
<div className={styles.title}>{title || 'Unknown'}</div>
</div> </div>
</div> </div>
); );

View file

@ -1,10 +1,10 @@
.wrap { .wrap {
position: fixed; position: fixed;
transform: translateZ(0); transform: translateZ(0);
bottom: $gap; bottom: 0;
pointer-events: none; pointer-events: none;
touch-action: none; touch-action: none;
height: 54px; height: 64px;
display: flex; display: flex;
z-index: 10; z-index: 10;
width: 100%; width: 100%;

View file

@ -14,6 +14,6 @@
width: 100%; width: 100%;
max-width: $content_width; max-width: $content_width;
display: flex; display: flex;
padding-bottom: 10px; padding-bottom: 64px;
flex-direction: column; flex-direction: column;
} }

View file

@ -56,6 +56,7 @@ const NodeLayoutUnconnected: FC<IProps> = ({
}, },
[node, nodeUpdateTags] [node, nodeUpdateTags]
); );
const block = node && node.type && NODE_COMPONENTS[node.type] && NODE_COMPONENTS[node.type]; const block = node && node.type && NODE_COMPONENTS[node.type] && NODE_COMPONENTS[node.type];
return ( return (