Last remaining componentWillReceiveProps, whew

This commit is contained in:
James Barnsley
2020-03-12 21:32:50 +13:00
parent 29b7b65b9c
commit 28fc55bad1
18 changed files with 6810 additions and 10005 deletions

View File

@ -13,6 +13,7 @@ class EditPlaylist extends React.Component {
constructor(props) {
super(props);
this.state = {
loaded: false,
error: null,
name: '',
description: '',
@ -27,13 +28,14 @@ class EditPlaylist extends React.Component {
if (this.props.playlist) {
this.setState({
loaded: true,
name: this.props.playlist.name,
description: this.props.playlist.description,
public: (this.props.playlist.public == true),
collaborative: (this.props.playlist.collaborative == true),
});
} else {
switch (helpers.uriSource(this.props.uri)) {
switch (uriSource(this.props.uri)) {
case 'spotify':
this.props.spotifyActions.getPlaylist(this.props.uri);
this.props.spotifyActions.following(this.props.uri);
@ -48,22 +50,36 @@ class EditPlaylist extends React.Component {
}
}
componentWillReceiveProps(nextProps) {
// Playlist just loaded
if (!this.props.playlist && nextProps.playlist) {
this.setState({
name: nextProps.playlist.name,
description: nextProps.playlist.description,
public: (nextProps.playlist.public == true),
collaborative: (nextProps.playlist.collaborative == true),
});
componentDidUpdate = ({
mopidy_connected: prev_mopidy_connected,
}) => {
const {
uri,
playlist,
mopidy_connected,
mopidyActions: {
getPlaylist,
},
} = this.props;
// Mopidy just connected, and we don't have the playlist yet
} else if (this.props.mopidy_connected != nextProps.mopidy_connected && !nextProps.playlist) {
this.props.mopidyActions.getPlaylist(this.props.uri);
if (!prev_mopidy_connected && mopidy_connected && !playlist) {
getPlaylist(uri);
}
}
static getDerivedStateFromProps({ playlist }, state) {
if (playlist && !state.loaded) {
return {
loaded: true,
name: playlist.name,
description: playlist.description,
public: (playlist.public === true),
collaborative: (playlist.collaborative === true),
};
}
return null;
}
savePlaylist(e) {
e.preventDefault();

View File

@ -33,10 +33,9 @@ class EditRadio extends React.Component {
}
}
componentWillReceiveProps(nextProps) {
if (!this.props.radio && nextProps.radio) {
this.loadRadio(nextProps.radio);
}
componentDidUpdate = ({ radio: prev_radio }) => {
const { radio } = this.props;
if (!prev_radio && radio) this.loadRadio(radio);
}
loadRadio(radio) {

View File

@ -44,27 +44,27 @@ class KioskMode extends React.Component {
}
}
componentWillReceiveProps(nextProps) {
componentDidUpdate = ({
current_track: prev_current_track,
}) => {
const {
current_track,
show_lyrics,
geniusActions,
genius_authorized,
geniusActions: {
findTrackLyrics,
},
} = this.props;
const {
current_track: next_current_track,
show_lyrics: next_show_lyrics,
genius_authorized: next_genius_authorized,
} = nextProps;
if (!current_track && next_current_track) {
this.setWindowTitle(next_current_track);
if (!prev_current_track && current_track) {
this.setWindowTitle(current_track);
if (show_lyrics && next_genius_authorized && next_current_track && next_current_track.artists && !next_current_track.lyrics_results) {
geniusActions.findTrackLyrics(next_current_track);
if (show_lyrics && genius_authorized && current_track && current_track.artists && !current_track.lyrics_results) {
findTrackLyrics(current_track);
}
} else if (show_lyrics !== next_show_lyrics && next_show_lyrics && next_current_track) {
if (next_genius_authorized && next_current_track && next_current_track.artists && !next_current_track.lyrics_results) {
geniusActions.findTrackLyrics(next_current_track);
} else if (show_lyrics !== show_lyrics && show_lyrics && current_track) {
if (genius_authorized && current_track && current_track.artists && !current_track.lyrics_results) {
findTrackLyrics(current_track);
}
}
}