/*---------------------------------------------------------------------------*\
 |  search.js                                                                |
 |                                                                           |
 |  Copyright © 2017-2020, Rajiv Bakulesh Shah, original author.             |
 |                                                                           |
 |      This program is free software: you can redistribute it and/or modify |
 |      it under the terms of the GNU General Public License as published by |
 |      the Free Software Foundation, either version 3 of the License, or    |
 |      (at your option) any later version.                                  |
 |                                                                           |
 |      This program is distributed in the hope that it will be useful, but  |
 |      WITHOUT ANY WARRANTY; without even the implied warranty of           |
 |      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
 |      General Public License for more details.                             |
 |                                                                           |
 |      You should have received a copy of the GNU General Public License    |
 |      along with this program.  If not, see:                               |
 |          <http://www.gnu.org/licenses/>                                   |
\*---------------------------------------------------------------------------*/

export const SET_QUERY = 'SET_QUERY';
export const SHOW_RESULTS = 'SHOW_RESULTS';
export const SET_SELECTED = 'SET_SELECTED';
export const CLEAR_SEARCH = 'CLEAR_SEARCH';

const setQuery = (query) => {
  const message = {
    type: SET_QUERY,
    query,
  };
  return message;
}

const showResults = (results) => {
  const message = {
    type: SHOW_RESULTS,
    results,
  };
  return message;
}

export const setSelected = (index) => {
  const message = {
    type: SET_SELECTED,
    index,
  };
  return message;
}

export const clearSearch = () => {
  const message = {
    type: CLEAR_SEARCH,
  };
  return message;
}

export const executeSearch = (query) => {
  return (dispatch) => {
    if (query) {
      dispatch(setQuery(query));
      fetch(`${process.env.REACT_APP_API}/v1/songs/search?q=${query}`)
        .then((response) => response.json())
        .then((data) => dispatch(showResults(data.songs)))
        .catch(console.log);
      } else {
        dispatch(clearSearch());
      }
  };
}

@@ -1709,36 +1709,32 @@
 onst message = %7B
-%0A   
  type: SET_QUERY
@@ -1738,21 +1738,14 @@
 ERY,
-%0A   
  query
-,%0A 
  %7D;%0A
@@ -1811,36 +1811,32 @@
 onst message = %7B
-%0A   
  type: SHOW_RESU
@@ -1843,20 +1843,16 @@
 LTS,
-%0A   
  results
 ,%0A  
@@ -1847,19 +1847,16 @@
  results
-,%0A 
  %7D;%0A  re
@@ -1927,28 +1927,24 @@
  message = %7B
-%0A   
  type: SET_S
@@ -1955,21 +1955,14 @@
 TED,
-%0A   
  index
-,%0A 
  %7D;%0A
@@ -2036,20 +2036,16 @@
 sage = %7B
-%0A   
  type: C
@@ -2059,11 +2059,8 @@
 ARCH
-,%0A 
  %7D;%0A

Make stylistic improvements