Skip to content

Commit fbd7377

Browse files
committed
add console logs for debugging
1 parent 916fb8f commit fbd7377

File tree

4 files changed

+60
-55
lines changed

4 files changed

+60
-55
lines changed

src/lib/ApiRequest/ApiRequest.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import PropTypes from 'prop-types';
22
import useApiRequest from './useApiRequest';
33

44
function ApiRequest(props) {
5-
const { data, loading, error } = useApiRequest(props.url, props.options);
6-
return props.children(data, loading, error);
5+
console.log('[ApiRequest]', props);
6+
const { data, loading, error } = useApiRequest(props.url, props.options);
7+
return props.children(data, loading, error);
78
}
89

910
ApiRequest.propTypes = {
10-
/** Options object */
11-
options: PropTypes.object,
12-
/** url to fetch from (HTTP request) */
13-
url: PropTypes.string.isRequired,
14-
/** Process spotify data with render props using props.children as a function */
15-
children: PropTypes.func.isRequired
11+
/** Options object */
12+
options: PropTypes.object,
13+
/** url to fetch from (HTTP request) */
14+
url: PropTypes.string.isRequired,
15+
/** Process spotify data with render props using props.children as a function */
16+
children: PropTypes.func.isRequired
1617
};
1718

1819
ApiRequest.defaultProps = {
19-
options: {}
20+
options: {}
2021
};
2122

2223
export default ApiRequest;

src/lib/ApiRequest/useApiRequest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function useApiRequest(url, options = {}) {
99
const token = React.useContext(SpotifyApiContext);
1010

1111
React.useEffect(() => {
12+
console.log('[useApiRequest]', url, options);
1213
async function loadData() {
1314
try {
1415
setLoading(true);
@@ -29,7 +30,8 @@ function useApiRequest(url, options = {}) {
2930
}
3031

3132
loadData();
32-
}, [url, options.ids, options.q, options, token]);
33+
// eslint-disable-next-line react-hooks/exhaustive-deps
34+
}, [url, options.ids, options.q, token]);
3335

3436
return { data, loading, error };
3537
}

src/lib/Search/Search.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,50 @@ import ApiRequest from '../ApiRequest/ApiRequest';
99
* @example ../../docs/Search/Search.md
1010
*/
1111
function Search(props) {
12-
const url = 'https://api.spotify.com/v1/search';
13-
const options = { ...props.options };
14-
const type = [];
15-
if (props.album) type.push('album');
16-
if (props.artist) type.push('artist');
17-
if (props.playlist) type.push('playlist');
18-
if (props.track) type.push('track');
19-
options.type = type.join(',');
20-
options.q = props.query;
12+
const url = 'https://api.spotify.com/v1/search';
13+
const options = { ...props.options };
14+
const type = [];
15+
if (props.album) type.push('album');
16+
if (props.artist) type.push('artist');
17+
if (props.playlist) type.push('playlist');
18+
if (props.track) type.push('track');
19+
options.type = type.join(',');
20+
options.q = props.query;
21+
console.log('[Search]', props);
2122

22-
return (
23-
<ApiRequest url={url} options={options}>
24-
{(data, loading, error) => {
25-
return props.children(data, loading, error);
26-
}}
27-
</ApiRequest>
28-
);
23+
return (
24+
<ApiRequest url={url} options={options}>
25+
{(data, loading, error) => {
26+
return props.children(data, loading, error);
27+
}}
28+
</ApiRequest>
29+
);
2930
}
3031

3132
Search.propTypes = {
32-
/** Search query keywords and optional field filters and operators. */
33-
query: PropTypes.string.isRequired,
34-
/** Get results for albums */
35-
album: PropTypes.bool,
36-
/** Get results for artists */
37-
artist: PropTypes.bool,
38-
/** Get results for playlists */
39-
playlist: PropTypes.bool,
40-
/** Get results for tracks */
41-
track: PropTypes.bool,
42-
/** Options object */
43-
options: PropTypes.shape({
44-
market: PropTypes.string,
45-
limit: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
46-
offset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
47-
include_external: PropTypes.string
48-
}),
49-
/** Process spotify data with render props using props.children as a function */
50-
children: PropTypes.func.isRequired
33+
/** Search query keywords and optional field filters and operators. */
34+
query: PropTypes.string.isRequired,
35+
/** Get results for albums */
36+
album: PropTypes.bool,
37+
/** Get results for artists */
38+
artist: PropTypes.bool,
39+
/** Get results for playlists */
40+
playlist: PropTypes.bool,
41+
/** Get results for tracks */
42+
track: PropTypes.bool,
43+
/** Options object */
44+
options: PropTypes.shape({
45+
market: PropTypes.string,
46+
limit: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
47+
offset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
48+
include_external: PropTypes.string
49+
}),
50+
/** Process spotify data with render props using props.children as a function */
51+
children: PropTypes.func.isRequired
5152
};
5253

5354
Search.defaultProps = {
54-
options: {}
55+
options: {}
5556
};
5657

5758
export default Search;

src/lib/Search/useSearch.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import useApiRequest from '../ApiRequest/useApiRequest';
55
* @param {Object} options - Options object
66
*/
77
function useSearch(query, options) {
8-
const url = 'https://api.spotify.com/v1/search';
9-
const type = [];
10-
if (options.album) type.push('album');
11-
if (options.artist) type.push('artist');
12-
if (options.playlist) type.push('playlist');
13-
if (options.track) type.push('track');
14-
const optionsObj = { q: query, type: type.join(','), ...options };
15-
const { data, loading, error } = useApiRequest(url, optionsObj);
8+
const url = 'https://api.spotify.com/v1/search';
9+
const type = [];
10+
if (options.album) type.push('album');
11+
if (options.artist) type.push('artist');
12+
if (options.playlist) type.push('playlist');
13+
if (options.track) type.push('track');
14+
const optionsObj = { q: query, type: type.join(','), ...options };
15+
const { data, loading, error } = useApiRequest(url, optionsObj);
16+
console.log('[useSearch]', query, options);
1617

17-
return { data, loading, error };
18+
return { data, loading, error };
1819
}
1920

2021
export default useSearch;

0 commit comments

Comments
 (0)