diff --git a/Back/src/application_controller.js b/Back/src/application_controller.js index 9593282..2e6b717 100644 --- a/Back/src/application_controller.js +++ b/Back/src/application_controller.js @@ -15,8 +15,9 @@ router.get('/coins/markets', function (req, res) { api_helper.REMOTE_API_call(url) .then(response => { - console.log("url: ", url); - console.log("response.length: ", response.length); + console.log("response.length : ", response.length); + console.log("response.page : ", page); +//console.log("url : ", url); res.json(response); }) .catch(error => { @@ -28,7 +29,7 @@ router.get('/coins/markets', function (req, res) { router.get('/coins/count', function (req, res) { let url = config.coingecko.api_url + '/global'; - console.log("url: ", url); +// console.log("url: ", url); api_helper.REMOTE_API_call(url) .then(response => { diff --git a/Front/src/App.tsx b/Front/src/App.tsx index d27a17b..86b206d 100644 --- a/Front/src/App.tsx +++ b/Front/src/App.tsx @@ -15,7 +15,7 @@ function App() { } /> - } /> + } /> diff --git a/Front/src/coinList/coinList-api.ts b/Front/src/coinApi.ts similarity index 74% rename from Front/src/coinList/coinList-api.ts rename to Front/src/coinApi.ts index 9be9c72..3140813 100644 --- a/Front/src/coinList/coinList-api.ts +++ b/Front/src/coinApi.ts @@ -7,8 +7,8 @@ const countUrl = '/coins/count'; export const coinListApi = createApi({ baseQuery: fetchBaseQuery({ baseUrl: baseUrl }), endpoints: (builder) => ({ - getMarkets: builder.query({ - query: (page = 1) => `${marketsUrl}?per_page=10&page=${page}`, + getMarkets: builder.query({ + query: (payload: {page: number, per_page: number}) => `${marketsUrl}?per_page=${payload.per_page}&page=${payload.page}`, }), getCount: builder.query({ query: () => countUrl, diff --git a/Front/src/coinDetails/coinDetails.tsx b/Front/src/coinDetails/coinDetails.tsx index 4ba8175..307b9e7 100644 --- a/Front/src/coinDetails/coinDetails.tsx +++ b/Front/src/coinDetails/coinDetails.tsx @@ -1,6 +1,8 @@ +import { useParams } from 'react-router-dom'; -const CoinDetails = (props: any): JSX.Element => { - console.log("props: ", props) +const CoinDetails = (): JSX.Element => { + const { id } = useParams(); + console.log("id: ", id) return (
CoinDetails
) diff --git a/Front/src/coinList/coinList.tsx b/Front/src/coinList/coinList.tsx index e9466d3..91aa701 100644 --- a/Front/src/coinList/coinList.tsx +++ b/Front/src/coinList/coinList.tsx @@ -1,25 +1,29 @@ -import {useParams, useLocation} from 'react-router-dom'; -import { useGetMarketsQuery } from './coinList-api'; +import {useSearchParams} from 'react-router-dom'; +import { useGetMarketsQuery } from '../coinApi'; import Pager from './coinListPager'; const CoinList = (): JSX.Element => { - const location = useLocation() - const { page } = useParams(); - - const { data, error, isLoading, isSuccess, refetch } = useGetMarketsQuery(); - console.log(page) - console.log(location.search) + const [searchParams, setSearchParams] = useSearchParams(); + const page = Number(searchParams.get('page')) || 1 + const per_page = Number(searchParams.get('per_page')) || 20 + const payload = {page, per_page} + const { data, error, isLoading, isSuccess, refetch } = useGetMarketsQuery(payload); + console.log("payload: ", payload); return (
CoinList + + {isLoading &&
Loading...
} + - { data && + + { data && isSuccess && data.map((item: any, index: any) => { return ( @@ -36,7 +40,7 @@ const CoinList = (): JSX.Element => { }
- +
) } diff --git a/Front/src/coinList/coinListPager.tsx b/Front/src/coinList/coinListPager.tsx index 88a5e06..9483a9f 100644 --- a/Front/src/coinList/coinListPager.tsx +++ b/Front/src/coinList/coinListPager.tsx @@ -1,14 +1,29 @@ -import { useGetCountQuery } from './coinList-api'; +import { useGetCountQuery } from '../coinApi'; +import { useNavigate } from "react-router-dom"; +const Pager = (props:any): JSX.Element => { + + console.log("page props", props) + + const { page, per_page, } = props; -const Pager = (): JSX.Element => { - const { data, error, isLoading, isSuccess, refetch } = useGetCountQuery(); + const navigate = useNavigate(); + + const lastPage = Math.ceil(data / per_page) + + function handlePager(page: number) { + const url = `/?page=${page}` + navigate(url) + } return (
- pager - coins: {JSON.stringify(data)} + + +
Page {page} from {lastPage}
+ +
) } diff --git a/Front/src/store.ts b/Front/src/store.ts index 5515955..e661663 100644 --- a/Front/src/store.ts +++ b/Front/src/store.ts @@ -1,7 +1,7 @@ import { combineReducers, configureStore } from '@reduxjs/toolkit' import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'; -import { coinListApi } from './coinList/coinList-api'; +import { coinListApi } from './coinApi'; // import listSliceReducer from './chartList/chartList-slice'