Skip to content

Commit

Permalink
🎨 Remove duplication in get preview URL logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Dec 23, 2016
1 parent b645527 commit b01a716
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/app/ui/MusicSelectScene.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SceneHeading from 'bemuse/ui/SceneHeading'
import SceneToolbar from 'bemuse/ui/SceneToolbar'
import c from 'classnames'
import compose from 'recompose/compose'
import getPreviewUrl from 'bemuse/music-collection/getPreviewUrl'
import online from 'bemuse/online/instance'
import pure from 'recompose/pure'
import { OFFICIAL_SERVER_URL } from 'bemuse/music-collection'
Expand Down Expand Up @@ -96,9 +97,7 @@ export const MusicSelectScene = React.createClass({
},
getPreviewUrl () {
const song = this.props.musicSelect.song
if (!song) return null
if (song.tutorial) return null
return this.props.collectionUrl + '/' + song.path + '/_bemuse_preview.mp3'
return getPreviewUrl(this.props.collectionUrl, song)
},
render () {
let musicSelect = this.props.musicSelect
Expand Down
3 changes: 2 additions & 1 deletion src/music-collection-viewer/MusicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'lodash'
import MusicSelectPreviewer from 'bemuse/music-previewer/MusicSelectPreviewer'
import React from 'react'
import getPlayableCharts from 'bemuse/music-collection/getPlayableCharts'
import getPreviewUrl from 'bemuse/music-collection/getPreviewUrl'
import groupSongsIntoCategories from 'bemuse/music-collection/groupSongsIntoCategories'
import sortSongs from 'bemuse/music-collection/sortSongs'

Expand Down Expand Up @@ -156,7 +157,7 @@ export class MusicTable extends React.Component {
<span
style={{ color: '#8b8685' }}
onClick={() => {
const previewUrl = this.props.url + '/' + song.path + '/_bemuse_preview.mp3'
const previewUrl = getPreviewUrl(this.props.url, song)
this.setState({ previewUrl })
}}
>{song.genre}</span><br />
Expand Down
8 changes: 8 additions & 0 deletions src/music-collection/getPreviewUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export function getPreviewUrl (serverUrl, song) {
if (!song) return null
if (song.tutorial) return null
return serverUrl + '/' + song.path + '/_bemuse_preview.mp3'
}

export default getPreviewUrl

0 comments on commit b01a716

Please sign in to comment.