Skip to content

Commit 83d21bc

Browse files
author
Julia Miroshnichenko22
committed
Endpoints
1 parent 739bee6 commit 83d21bc

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/pages/Discover.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Error, Loader, SongCard } from '../components';
22
import { genres } from '../assets/constants';
3+
import { useGetTopChartsQuery } from '../redux/services/shazamCore';
34

45
const Discover = () => {
6+
const { data, isFetching, error } = useGetTopChartsQuery();
57
const genreTitle = 'Pop';
68

9+
console.log(data);
710
return (
811
<div className="flex flex-col">
912
<div className="flex flex-col items-center justify-between w-full mt-4 mb-10 sm:flex-row">

src/redux/services/shazamCore.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
2+
3+
//delete - if path is ok
4+
// fetch('https://shazam.p.rapidapi.com/charts/track', options)
5+
// .then((response) => response.json())
6+
// .then((response) => console.log(response))
7+
// .catch((err) => console.error(err));
8+
9+
export const shazamCoreApi = createApi({
10+
reducerPath: 'shazamCoreApi',
11+
baseQuery: fetchBaseQuery({
12+
baseUrl: 'https://shazam.p.rapidapi.com',
13+
prepareHeaders: (headers) => {
14+
headers.set('X-RapidAPI-Key', '367d97e0d1msh37aed431a4b5cf2p1cd6dcjsn5ab9c1c9041d');
15+
16+
return headers;
17+
},
18+
}),
19+
endpoints: (builder) => ({
20+
getTopCharts: builder.query({ query: '/charts/track' }),
21+
}),
22+
});
23+
24+
export const { useGetTopChartsQuery } = shazamCoreApi;

src/redux/store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { configureStore } from '@reduxjs/toolkit';
22

33
import playerReducer from './features/playerSlice';
4+
import { shazamCoreApi } from './services/shazamCore';
45

56
export const store = configureStore({
67
reducer: {
8+
[shazamCoreApi.reducerPath]: shazamCoreApi.reducer,
79
player: playerReducer,
810
},
11+
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(shazamCoreApi.middleware),
912
});

0 commit comments

Comments
 (0)