So I have created a method inside of the App React component so that when someone goes to save, the DOM switches and renders the loading page, process the POST request, and then re-renders the original page.
loadingPlaylist() {
// Using pending variable to determine what to do next //
let pending = false;
if(pending === true) {
return (
ReactDOM.render(<LoadingScreen />, document.getElementsByClassName('app'))
)
}
// trackCheck is checking if there is something in the playlist to save, if not alert should pop up.
// If there is something to save, loading pending is changed to true and LoadingScreen renders
const trackCheck = () => {
if(!this.state.playlistTracks.length) {
return alert('There are no tracks in your playlist dude');
} else {
pending = true;
}
}
// Performs functions in order to run check. Checks if something is there to save, saves the info,
// then checks if the area is empty
const isLoading = () => {
trackCheck();
this.savePlaylist();
trackCheck();
}
isLoading();
//Method is saved to a event listener
}
I know if is probably garbage for a React App and nothing is currently working as intended. Need help to do this correctly.