better types

This commit is contained in:
Ste Vaidis 2022-12-11 21:49:24 +02:00
parent 24c99868e1
commit c09ef3e077
6 changed files with 83 additions and 77 deletions

View File

@ -85,8 +85,8 @@ const CoinChart = (props: ICoinChartProps): JSX.Element => {
}); });
} }
function formatChartLabels(data: any): any { function formatChartLabels(data: IChartData): string[] {
return data['prices'].map((value: (string | number | Date)[]) => return data['prices'].map((value: IChartDataItem) =>
format(new Date(value[0]), 'MM/dd/yyyy') format(new Date(value[0]), 'MM/dd/yyyy')
); );
} }

View File

@ -19,10 +19,6 @@ const CoinDetails = (): JSX.Element => {
isSuccess, isSuccess,
} = useGetCoinInfoQuery(id ? id : ''); } = useGetCoinInfoQuery(id ? id : '');
React.useEffect(() => {
console.log(data)
}, [])
return ( return (
<div className="details"> <div className="details">
{isLoading && <div>Loading...</div>} {isLoading && <div>Loading...</div>}

View File

@ -9,12 +9,24 @@ import Button from '@mui/material/Button';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import { IGetCoinInfoResponse } from '../coinApi-types'
// export interface ICoinInfoProps {
// [key: string]: any;
// }
// interface ICoinInfoProps {
// data: IGetCoinInfoResponse;
// }
export interface ICoinInfoProps { export interface ICoinInfoProps {
[key: string]: any; [key: string]: any;
} }
const CoinInfo = (props: ICoinInfoProps): JSX.Element => { const CoinInfo = (props: ICoinInfoProps): JSX.Element => {
const { data } = props; const { data } = props;
console.log("CoinInfo props.data: ", data)
return ( return (
<div> <div>
@ -51,7 +63,6 @@ const CoinInfo = (props: ICoinInfoProps): JSX.Element => {
Object.entries(data.links.chat_url).map( Object.entries(data.links.chat_url).map(
([key, value]) => { ([key, value]) => {
if (Boolean(value)) { if (Boolean(value)) {
console.log(value);
const domain = new URL(String(value)); const domain = new URL(String(value));
const label = domain.hostname.split(".")[0] const label = domain.hostname.split(".")[0]
return ( return (

View File

@ -5,14 +5,19 @@ import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead'; import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow'; import TableRow from '@mui/material/TableRow';
import { IGetCoinInfoResponse, IGetCoinInfoData } from '../coinApi-types' import { IGetCoinInfoResponse } from '../coinApi-types'
interface ICoinStatsProps { interface ICoinStatsProps {
data: IGetCoinInfoResponse; data: IGetCoinInfoResponse;
} }
interface IRow {
title: string;
value: string;
}
const CoinStats = (props: ICoinStatsProps): JSX.Element => { const CoinStats = (props: ICoinStatsProps): JSX.Element => {
console.log("CoinStats props", props) // console.log("CoinStats props", props)
const { data } = props; const { data } = props;
@ -37,7 +42,7 @@ const CoinStats = (props: ICoinStatsProps): JSX.Element => {
<Table size="small" > <Table size="small" >
<TableBody> <TableBody>
{ {
tableData.map((row: any, index: any) => ( tableData.map((row: IRow, index: number) => (
<TableRow key={row.title}> <TableRow key={row.title}>
<TableCell align="left">{row.title}</TableCell> <TableCell align="left">{row.title}</TableCell>
<TableCell align="right">{row.value}</TableCell> <TableCell align="right">{row.value}</TableCell>

View File

@ -32,12 +32,6 @@ header a {
color: #e15241 color: #e15241
} }
/* #chart {
position: absolute;
height: 400px;
} */
.coinName { .coinName {
font-weight: bold; font-weight: bold;
margin-left: 10px; margin-left: 10px;