Skip to content

Commit

Permalink
init: modal window; update: project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Danylo Prudnikov committed Sep 23, 2022
1 parent eddc37f commit 931fadf
Show file tree
Hide file tree
Showing 13 changed files with 976 additions and 529 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "crypto-app",
"version": "0.1.0",
"private": true,
"homepage": "https://trevisfox.github.io/Crypto/",
"dependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
Expand All @@ -13,10 +12,10 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"antd": "^4.23.2",
"axios": "^0.27.2",
"chart.js": "^3.9.1",
"dotenv": "^16.0.2",
"gh-pages": "^4.0.0",
"html-react-parser": "^3.0.4",
"millify": "^5.0.0",
"moment": "^2.29.4",
Expand All @@ -34,9 +33,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "gh-pages -d build",
"predeploy": "yarn run build"
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
Expand Down
8 changes: 4 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Container } from "@mui/system";
import Navbar from "./components/Navigation/Navbar";
import Homepage from "./components/Homepage/Hompage";
import Favorites from "./components/Favorites/Favorites";
import Cryptocurrencies from "./components/Cryptocurrencies/Cryptocurrencies";
import CryptoDetails from "./components/CryptoDetails/CryptoDetails";
import News from "./components/News/News";
import NewsList from "./components/NewsList/NewsList";
import CoinList from "./components/CoinList/CoinList";

function App() {
return (
Expand All @@ -24,13 +24,13 @@ function App() {
></Route>
<Route
path="/cryptocurrencies"
element={<Cryptocurrencies />}
element={<CoinList />}
></Route>
<Route
path="/crypto/:coinId"
element={<CryptoDetails />}
></Route>
<Route path="/news" element={<News />}></Route>
<Route path="/news" element={<NewsList />}></Route>
</Routes>
</Container>
</main>
Expand Down
118 changes: 118 additions & 0 deletions src/components/CoinItem/CoinItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React from "react";
import { Link } from "react-router-dom";
import {
Card,
CardContent,
Typography,
CardActions,
IconButton,
} from "@mui/material";
import millify from "millify";
import AddIcon from "@mui/icons-material/Add";
import ReadMoreIcon from "@mui/icons-material/ReadMore";

const CoinItem = ({ currency }) => {
return (
<Card
sx={{
minHeight: 255,
}}
>
<CardContent>
<Typography
gutterBottom
variant="h5"
component="h5"
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
gap: 2,
pb: 2,
mb: 2,
fontWeight: "bold",
borderBottom: 0.5,
borderColor: "silver",
}}
>
<img
src={currency.iconUrl}
alt="Coin icon"
width="50"
height="50"
/>
{currency.name}
</Typography>
<Typography
variant="body2"
color="text.secondary"
sx={{
fontSize: 16,
color: "grey",
mb: 1,
}}
>
Rank: {currency.rank}
</Typography>
<Typography
variant="body2"
color="text.secondary"
sx={{
fontSize: 16,
color: "grey",
mb: 1,
}}
>
Price: {millify(currency.price)} $
</Typography>
<Typography
variant="body2"
color="text.secondary"
sx={{
fontSize: 16,
color: "grey",
mb: 1,
}}
>
Market Cap: {millify(currency.marketCap)}
</Typography>
<Typography
variant="body2"
color="text.secondary"
sx={{
fontSize: 16,
color: "grey",
}}
>
Daily Change: {millify(currency.change)}%
</Typography>
</CardContent>
<CardActions
sx={{
display: "flex",
justifyContent: "flex-end",
bgcolor: "#1976d2",
}}
>
<IconButton
sx={{
color: "white",
}}
>
<AddIcon />
</IconButton>
<Link to={`/crypto/${currency.uuid}`}>
<IconButton
sx={{
color: "white",
}}
>
<ReadMoreIcon />
</IconButton>
</Link>
</CardActions>
</Card>
);
};

export default CoinItem;
52 changes: 52 additions & 0 deletions src/components/CoinList/CoinList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useState, useEffect } from "react";
import { useGetCryptosQuery } from "../../services/cryptoApi";
import Loader from "../Loader/Loader";
import { Grid, TextField, Box } from "@mui/material";
import CoinItem from "../CoinItem/CoinItem";

const CoinList = ({ simplified }) => {
const count = simplified ? 12 : 100;
const { data: cryptosList, isFetching } = useGetCryptosQuery(count);
const [cryptos, setCryptos] = useState([]);
const [searchTerm, setSearchTerm] = useState("");

useEffect(() => {
const filteredData = cryptosList?.data?.coins.filter((coin) =>
coin.name.toLowerCase().includes(searchTerm.toLowerCase())
);
setCryptos(filteredData);
}, [cryptosList, searchTerm]);

if (isFetching) return <Loader />;

return (
<>
{!simplified && (
<Box
component="form"
sx={{
"& > :not(style)": { my: 3, width: "31%" },
}}
noValidate
>
<TextField
id="standard-basic"
label="Search coin..."
variant="standard"
onChange={(e) => setSearchTerm(e.target.value)}
/>
</Box>
)}

<Grid container spacing={5}>
{cryptos?.map((currency, index) => (
<Grid item md={4} key={index}>
<CoinItem currency={currency} />
</Grid>
))}
</Grid>
</>
);
};

export default CoinList;
41 changes: 13 additions & 28 deletions src/components/CryptoDetails/CryptoDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ const CryptoDetails = () => {
timePeriod,
});
const cryptoDetails = data?.data?.coin;

const time = ["3h", "24h", "7d", "30d", "1y", "3m", "3y", "5y"];

if (isFetching) return <Loader />;
console.log(cryptoDetails);

return (
<>
Expand All @@ -48,30 +46,15 @@ const CryptoDetails = () => {
{cryptoDetails.name} ({cryptoDetails.symbol}) Price
</Typography>

<FormControl
variant="standard"
sx={{
width: "25%",
}}
<Select
value={timePeriod}
onChange={(e) => setTimePeriod(e.target.value)}
>
<InputLabel
sx={{
fontSize: 18,
}}
>
Select a time interval
</InputLabel>
<Select
className="select-timeperiod"
placeholder="Select time period"
defaultValue="7d"
onChange={(value) => setTimePeriod(value)}
>
{time.map((value) => {
return <MenuItem key={value}>{value}</MenuItem>;
})}
</Select>
</FormControl>
{time.map((date) => (
<MenuItem key={date}>{date}</MenuItem>
))}
</Select>

<LineChart
coinHistory={coinHistory}
currentPrice={millify(cryptoDetails?.price)}
Expand All @@ -93,9 +76,11 @@ const CryptoDetails = () => {
<Typography>Rank: {cryptoDetails.rank}</Typography>
<Typography>
24h Volume:{" "}
{cryptoDetails.volume
? cryptoDetails.volume
: "no data available"}
{cryptoDetails.volume ? (
cryptoDetails.volume
) : (
<em>no data available</em>
)}
</Typography>
<Typography>Market Cap: {cryptoDetails.marketCap}</Typography>
<Typography>
Expand Down
Loading

0 comments on commit 931fadf

Please sign in to comment.