Adding page titles

This commit is contained in:
James Barnsley
2018-06-28 08:12:03 +12:00
parent eeb24f4c54
commit 29f60071a9
18 changed files with 46532 additions and 48450 deletions

2
src/js/bootstrap.js vendored
View File

@ -81,7 +81,7 @@ var initialState = {
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_lastfm.php'
},
genius: {
provider_url: 'https://jamesbarnsley.co.nz/iris/provider_genius.php'
provider_url: 'https://james.barnsley.nz/iris/provider_genius.php'
},
spotify: {
me: false,

View File

@ -752,37 +752,6 @@ export let isObject = function(value){
}
/**
* Set window title
* @param track
**/
export let setWindowTitle = function (track = false, play_state = false){
var title = 'No track playing'
if (track){
var icon = '\u25A0 ';
var artist_string = '';
if (track.artists){
for (var i = 0; i < track.artists.length; i++){
if (artist_string != ''){
artist_string += ', ';
}
artist_string += track.artists[i].name
}
}
if (play_state && play_state == 'playing'){
icon = '\u25B6 ';
}
title = icon +' '+ track.name +' - '+ artist_string;
}
document.title = title
}
/**
* Detect if an item is in the loading queue. We simply loop all load items to
* see if any items contain our searched key.

View File

@ -339,16 +339,6 @@ const CoreMiddleware = (function(){
tracks: [action.track]
});
// Set our window title to the track title
helpers.setWindowTitle(action.track, store.getState().mopidy.play_state);
next(action);
break;
case 'CLEAR_CURRENT_TRACK':
// Set our window title to the track title
helpers.setWindowTitle(null, store.getState().mopidy.play_state);
next(action);
break;

View File

@ -20,14 +20,13 @@ const sendRequest = (dispatch, getState, endpoint) => {
var config = {
method: 'GET',
url: getState().genius.provider_url+endpoint,
dataType: "json",
timeout: 10000
};
$.ajax(config).then(
response => {
dispatch(uiActions.stopLoading(loader_key));
resolve(response.result);
resolve(response);
},
(xhr, status, error) => {
dispatch(uiActions.stopLoading(loader_key));
@ -64,6 +63,7 @@ export function getTrackLyrics(uri, url){
sendRequest(dispatch, getState, "?action=lyrics&url="+url)
.then(
response => {
var html = $(response);
var lyrics = html.find('.lyrics');
if (lyrics.length > 0){

View File

@ -1,14 +1,6 @@
export default function reducer(genius = {}, action){
switch (action.type){
case 'GENIUS_CONNECT':
case 'GENIUS_CONNECTING':
return Object.assign({}, genius, { connected: false, connecting: true });
case 'GENIUS_CONNECTED':
return Object.assign({}, genius, { connected: true, connecting: false });
default:
return genius
}

View File

@ -246,6 +246,11 @@ const MopidyMiddleware = (function(){
* General playback
**/
case 'MOPIDY_PLAY_STATE':
store.dispatch(uiActions.setWindowTitle(null, action.play_state));
next(action);
break
case 'MOPIDY_GET_PLAY_STATE':
request(socket, store, 'playback.getState')
.then(

View File

@ -1,6 +1,14 @@
import * as helpers from '../../helpers'
export function setWindowTitle(title = null, play_state = null){
return {
type: 'SET_WINDOW_TITLE',
title: title,
play_state: play_state
}
}
export function setSelectedTracks(keys = []){
if (typeof(keys) === 'string'){
keys = [keys]

View File

@ -22,11 +22,36 @@ const UIMiddleware = (function(){
if (tracks[current_track_uri] !== undefined){
current_track = tracks[current_track_uri];
}
helpers.setWindowTitle(current_track, action.data);
next(action);
break
case 'SET_WINDOW_TITLE':
var window_title = "";
if (action.play_state){
var play_state = action.play_state;
} else {
var play_state = store.getState().mopidy.play_state;
}
if (play_state == 'playing'){
window_title = '\u25B6';
} else {
window_title = '\u25A0';
}
if (action.title){
var title = action.title;
} else {
var title = store.getState().ui.window_title;
}
document.title = window_title+' '+title;
next(action);
break;
case 'OPEN_MODAL':
if (store.getState().ui.allow_reporting){
ReactGA.event({ category: 'Modal', action: 'Opened', label: action.modal.name });

View File

@ -14,9 +14,15 @@ export default function reducer(ui = {}, action){
return Object.assign({}, ui, { debug_response: action.response })
case 'UI_SET':
console.log(action);
return Object.assign({}, ui, action.data);
case 'SET_WINDOW_TITLE':
if (action.title){
return Object.assign({}, ui, { window_title: action.title });
} else {
return ui;
}
case 'TOGGLE_SIDEBAR':
var new_state = !ui.sidebar_open
if (typeof(action.new_state) !== 'undefined' ) new_state = action.new_state

View File

@ -26,6 +26,10 @@ class Debug extends React.Component{
}
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Debug");
}
callMopidy(e){
e.preventDefault()
this.props.mopidyActions.debug(this.state.mopidy_call, JSON.parse(this.state.mopidy_data) )

View File

@ -26,6 +26,10 @@ class Queue extends React.Component{
super(props)
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Now playing");
}
removeTracks(track_indexes){
var tlids = [];
for (var i = 0; i < track_indexes.length; i++){

View File

@ -20,6 +20,7 @@ class QueueHistory extends React.Component{
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Queue history");
this.loadHistory()
}

View File

@ -33,6 +33,7 @@ class Search extends React.Component{
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Search");
// Auto-focus on the input field
$(document).find('.search-form input').focus();

View File

@ -36,6 +36,10 @@ class Settings extends React.Component {
}
}
componentDidMount(){
this.props.uiActions.setWindowTitle("Settings");
}
componentWillReceiveProps(nextProps){
var changed = false
var state = this.state

View File

@ -57,6 +57,8 @@ class Track extends React.Component{
// We have just received our full track info (with artists)
if (!this.props.track.artists && nextProps.track.artists){
this.props.uiActions.setWindowTitle(nextProps.track.name+" by XXXX");
// Ready to load LastFM
if (nextProps.lastfm_authorized){
this.props.lastfmActions.getTrack(nextProps.track.uri);