);
}
}
/**
* Rebuild a track URI with some ugly-ass handling of encoding.
*
* Basically the ID part of a Mopidy URI needs to be encoded, but the rest of the URI can't be.
* This means we need to break down the URI (decoded) and then reconstruct with an encoded ID.
* This is all required because he URI is passed to us *from* a URL which has been encoded for
* obvious reasons.
*
* @param uri String
* @return String
* */
const rebuildUri = (uri) => {
const rebuilt_uri = `${uriSource(uri)}:${uriType(uri)}:`;
// Escape unreserved characters (RFC 3986)
// https://stackoverflow.com/questions/18251399/why-doesnt-encodeuricomponent-encode-single-quotes-apostrophes
let id = getFromUri('trackid', uri);
id = encodeURIComponent(id).replace(/[!'()*]/g, escape);
// Reinstate slashes for the Mopidy-Local structure
id = id.replace(/%2F/g, '/');
return rebuilt_uri + id;
};
const mapStateToProps = (state, ownProps) => {
let uri = decodeURIComponent(ownProps.match.params.uri);
uri = rebuildUri(uri);
return {
uri,
slim_mode: state.ui.slim_mode,
load_queue: state.ui.load_queue,
track: (state.core.tracks && state.core.tracks[uri] !== undefined ? state.core.tracks[uri] : false),
tracks: state.core.tracks,
artists: state.core.artists,
albums: state.core.albums,
spotify_library_albums: state.spotify.library_albums,
local_library_albums: state.mopidy.library_albums,
lastfm_authorized: state.lastfm.authorization,
spotify_authorized: state.spotify.authorization,
genius_authorized: state.genius.authorization,
};
};
const mapDispatchToProps = (dispatch) => ({
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
lastfmActions: bindActionCreators(lastfmActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch),
geniusActions: bindActionCreators(geniusActions, dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps)(Track);