details info query working

This commit is contained in:
Ste Vaidis 2022-12-09 00:44:10 +02:00
parent 7962e19205
commit a015f18db0
3 changed files with 61 additions and 5 deletions

View File

@ -27,7 +27,7 @@ router.get('/coins/markets', function (req, res) {
}) })
router.get('/coins/count', function (req, res) { router.get('/count', function (req, res) {
let url = config.coingecko.api_url + '/global'; let url = config.coingecko.api_url + '/global';
// console.log("url: ", url); // console.log("url: ", url);
@ -41,4 +41,25 @@ router.get('/coins/count', function (req, res) {
}) })
}) })
router.get('/coin/:id', function (req, res) {
let id = req.params['id'];
let url = config.coingecko.api_url + '/coins/' + id;
console.log("id: ", id);
api_helper.REMOTE_API_call(url)
.then(response => {
res.json(response);
})
.catch(error => {
console.log("error: ", error);
res.send(error);
})
})
module.exports = router; module.exports = router;

View File

@ -1,8 +1,11 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
// URL's
const baseUrl = "http://127.0.0.1:8080"; const baseUrl = "http://127.0.0.1:8080";
const marketsUrl = '/coins/markets'; const marketsUrl = '/coins/markets';
const countUrl = '/coins/count'; const countUrl = '/count';
const coinInfoUrl = (id:string) => `/coin/${id}`;
const coinGraphUrl = (id:string) => `/coin/${id}`;
export const coinListApi = createApi({ export const coinListApi = createApi({
baseQuery: fetchBaseQuery({ baseUrl: baseUrl }), baseQuery: fetchBaseQuery({ baseUrl: baseUrl }),
@ -13,7 +16,16 @@ export const coinListApi = createApi({
getCount: builder.query<any, number | void>({ getCount: builder.query<any, number | void>({
query: () => countUrl, query: () => countUrl,
}), }),
getCoinInfo: builder.query<any, string>({
query: (id: string) => coinInfoUrl(id),
}),
getCoinGraph: builder.query<any, string>({
query: (id: string) => coinGraphUrl(id),
}),
}), }),
}) })
export const { useGetMarketsQuery, useGetCountQuery } = coinListApi; export const {
useGetMarketsQuery,
useGetCountQuery,
useGetCoinInfoQuery } = coinListApi;

View File

@ -1,10 +1,33 @@
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { useGetCoinInfoQuery } from '../coinApi';
const CoinDetails = (): JSX.Element => { const CoinDetails = (): JSX.Element => {
const { id } = useParams(); const { id } = useParams();
console.log("id: ", id) console.log("id: ", id)
const {
data,
error,
isLoading,
isSuccess,
refetch
} = useGetCoinInfoQuery(id || 'btc');
// const { id } = data;
return ( return (
<div>CoinDetails</div> <div>CoinDetails
{
data &&
<div className="info">
<div>ID: {data.id}</div>
<div className="links">
<div>Homepage: {data.links.homepage}</div>
</div>
<div>Description{data.description.en}</div>
</div>
}
</div>
) )
} }