Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature song play time #1956

Open
wants to merge 10 commits into
base: default
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/HeaderBar/CurrentDJ.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import { translate } from '@u-wave/react-translate';
import PlayTime from './PlayTime';

const CurrentDJ = ({ t, className, dj }) => (
const CurrentDJ = ({
t, className, dj, startTime, mediaDuration,
}) => (
<div className={className}>
{t('booth.currentDJ', { user: dj.username })}
{t('booth.currentDJ', { user: dj.username })} - <PlayTime className="HeaderBar-timer" startTime={startTime} mediaDuration={mediaDuration} />
</div>
);

Expand All @@ -14,6 +17,8 @@ CurrentDJ.propTypes = {
dj: PropTypes.shape({
username: PropTypes.string.isRequired,
}),
startTime: PropTypes.number.isRequired,
mediaDuration: PropTypes.number.isRequired,
};

export default translate()(CurrentDJ);
23 changes: 23 additions & 0 deletions src/components/HeaderBar/PlayTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import cx from 'clsx';
import React from 'react';
import PropTypes from 'prop-types';
import formatDuration from 'format-duration';
import useClock from '../../hooks/useClock';

function PlayTime({ className, startTime, mediaDuration }) {
const currentTime = useClock();
const currentElapsed = currentTime - startTime;
return (
<span className={cx('Timer', className)}>
{formatDuration(currentElapsed)} / {formatDuration(mediaDuration * 1000)}
</span>
);
}

PlayTime.propTypes = {
className: PropTypes.string,
startTime: PropTypes.number.isRequired,
mediaDuration: PropTypes.number.isRequired,
};

export default React.memo(PlayTime);
6 changes: 5 additions & 1 deletion src/components/HeaderBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const HeaderBar = ({
mediaStartTime,
volume,
muted,
startTime,
mediaDuration,
onVolumeChange,
onVolumeMute,
onVolumeUnmute,
Expand All @@ -35,7 +37,7 @@ const HeaderBar = ({
</AppTitle>
<div className="HeaderBar-nowPlaying">
<CurrentMedia className="HeaderBar-media" media={media} />
{dj && <CurrentDJ className="HeaderBar-dj" dj={dj} />}
{dj && <CurrentDJ className="HeaderBar-dj" dj={dj} startTime={startTime} mediaDuration={mediaDuration} />}
</div>
{media && (
<Progress
Expand Down Expand Up @@ -68,6 +70,8 @@ HeaderBar.propTypes = {
mediaStartTime: PropTypes.number,
volume: PropTypes.number,
muted: PropTypes.bool,
startTime: PropTypes.number,
mediaDuration: PropTypes.number,

onVolumeChange: PropTypes.func,
onVolumeMute: PropTypes.func,
Expand Down
9 changes: 8 additions & 1 deletion src/containers/HeaderBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { setVolume, mute, unmute } from '../actions/PlaybackActionCreators';
import { toggleRoomHistory, toggleAbout } from '../actions/OverlayActionCreators';
import { djSelector, mediaSelector, startTimeSelector } from '../selectors/boothSelectors';
import {
djSelector,
mediaSelector,
startTimeSelector,
mediaDurationSelector,
} from '../selectors/boothSelectors';
import { volumeSelector, isMutedSelector } from '../selectors/settingSelectors';
import HeaderBar from '../components/HeaderBar';

Expand All @@ -12,6 +17,8 @@ const mapStateToProps = createStructuredSelector({
dj: djSelector,
volume: volumeSelector,
muted: isMutedSelector,
startTime: startTimeSelector,
mediaDuration: mediaDurationSelector,
});

const mapDispatchToProps = {
Expand Down