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

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