Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
urdadx committed Jun 29, 2022
1 parent 3a2d5a7 commit 4c83515
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ColorDetail from "./Pages/ColorDetail";
import { Toaster } from "react-hot-toast";
import Bookmarks from "./Pages/Bookmarks";
import NotFound from "./Pages/NotFound";
import SortedColors from "./Pages/SortedColors";

const App = () => {

Expand All @@ -15,6 +16,7 @@ const App = () => {
<Route path="/" element={<Home />} />
<Route path="/indie-color/:name" element={<ColorDetail />} />
<Route path="/bookmarks" element={<Bookmarks />} />
<Route path="/sorted/:sortedName" element={<SortedColors />} />
<Route path="*" element={<NotFound title="Page not Found" status="404" icon="🤖" />} />
</Routes>
</Router>
Expand Down
6 changes: 2 additions & 4 deletions src/Pages/Bookmarks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Navbar from "../components/Navbar";
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import Card from "../components/Card";
import { TailSpin } from "react-loader-spinner";
import Meta from "../components/Meta";
import Spinner from "../components/Spinner";

const Bookmarks = () => {

Expand Down Expand Up @@ -33,9 +33,7 @@ const Bookmarks = () => {
<Card color={gradient.colors} name={gradient.name} />
</Link>
}) :
<div className="loader">
<TailSpin color="blue" />
</div>
<Spinner />

}

Expand Down
25 changes: 17 additions & 8 deletions src/Pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TailSpin } from "react-loader-spinner";
import { Link } from "react-router-dom";
import Meta from "../components/Meta";
import { Button } from "../styles/ButtonStyled";
import Spinner from "../components/Spinner";

const Home = () => {

Expand All @@ -27,11 +28,21 @@ const Home = () => {
<Navbar />
<div className="wrapper">
<div className="category">
<Button border="none" background="#FF025E">Red</Button>
<Button border="none" background="#FFD000">Yellow</Button>
<Button border="none" background="#64F38C">Blue</Button>
<Button border="none" background="#019DF7">Green</Button>
<Button border="none" background="#161A1D">Black</Button>
<Link className="sorted-link" to="/sorted/red">
<Button border="none" background="#FF025E">Red</Button>
</Link>
<Link className="sorted-link" to="/sorted/yellow">
<Button border="none" background="#FFD000">Yellow</Button>
</Link>
<Link className="sorted-link" to="/sorted/green">
<Button border="none" background="#64F38C">Green</Button>
</Link>
<Link className="sorted-link" to="/sorted/blue">
<Button border="none" background="#019DF7">Blue</Button>
</Link>
<Link className="sorted-link" to="/sorted/black">
<Button border="none" background="#161A1D">Black</Button>
</Link>
</div>
<section className="main">
{
Expand All @@ -40,9 +51,7 @@ const Home = () => {
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
}) :
<div className="loader">
<TailSpin width="90" color="blue" />
</div>
<Spinner />
}

</section>
Expand Down
105 changes: 105 additions & 0 deletions src/Pages/SortedColors.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import Card from "../components/Card";
import Navbar from "../components/Navbar";
import { HomeStyled } from "../styles/HomeStyled";
import { useState, useEffect } from "react";
import { Link } from "react-router-dom";
import Meta from "../components/Meta";
import { Button } from "../styles/ButtonStyled";
import { useParams } from "react-router-dom";
import { greenGradients, redGradients, yellowGradients, blackGradients, blueGradients, whiteGradients } from "../utils/generateColors";
import Spinner from "../components/Spinner";

const SortedColors = () => {

const [loading, setIsLoading] = useState(false);
const { sortedName } = useParams()

console.log(sortedName)

useEffect(() => {
setIsLoading(false)
}, [])



return (
<>
<Meta />
<HomeStyled>
<Navbar />
<div className="wrapper">
<div className="category">
<Link className="sorted-link" to="/sorted/red">
<Button border="none" background="#FF025E">Red</Button>
</Link>
<Link className="sorted-link" to="/sorted/yellow">
<Button border="none" background="#FFD000">Yellow</Button>
</Link>
<Link className="sorted-link" to="/sorted/green">
<Button border="none" background="#64F38C">Green</Button>
</Link>
<Link className="sorted-link" to="/sorted/blue">
<Button border="none" background="#019DF7">Blue</Button>
</Link>
<Link className="sorted-link" to="/sorted/black">
<Button border="none" background="#161A1D">Black</Button>
</Link>
</div>
<section className="main">

{
<>
{loading ? (
<Spinner />
) :
(
<>
{sortedName === "red"
? redGradients.map((gradient) => (
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}>
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
))
: sortedName === "green"
? greenGradients.map((gradient) => (
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}>
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
))
: sortedName === "blue"
? blueGradients.map((gradient) => (
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}>
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
))
: sortedName === "white"
? whiteGradients.map((gradient) => (
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}>
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
))
: sortedName === "yellow"
? yellowGradients.map((gradient) => (
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}>
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
))
: blackGradients.map((gradient) => (
<Link style={{textDecoration:"none"}} to={`/indie-color/${gradient.name}`}>
<Card color={gradient.colors} name={gradient.name} isSaved = {true} />
</Link>
))}
</>
)}
</>
}


</section>
</div>
</HomeStyled>
</>
);
}

export default SortedColors;
16 changes: 16 additions & 0 deletions src/components/Spinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TailSpin } from "react-loader-spinner";
import { HomeStyled } from "../styles/HomeStyled";

const Spinner = () => {
return (
<>
<HomeStyled>
<div className="loader">
<TailSpin width="90" color="blue" />
</div>
</HomeStyled>
</>
);
}

export default Spinner ;
39 changes: 39 additions & 0 deletions src/helpers/Sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const hexToRGB = (hex) => {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
return r + r + g + g + b + b;
});

var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
}
: null;
};

export const generateCategory = (hex) => {
const RGB = hexToRGB(hex);

const { r, g, b } = RGB;

if (r > 200 && g > 200 && b > 200) {
return "white";
} else if (r > b && g > b && r > 200 && g > 100 && g < 200 && b < 100) {
return "yellow";
} else if (r > g && r > b && r > 150 && g < 120) {
return "red";
} else if (g > b && g > r && g > 150 && b < 150) {
return "green";
} else if (b > r && b > g && b > 150) {
return "blue";
} else if (r < 90 && g < 90 && b < 90) {
return "black";
} else {
return "none";
}
};

5 changes: 5 additions & 0 deletions src/styles/HomeStyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const HomeStyled = styled.div`
}
.sorted-link{
text-decoration: none;
color:white;
}
.saved{
color:#24306d;
Expand Down
40 changes: 40 additions & 0 deletions src/utils/generateColors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { generateCategory } from "../helpers/Sort";
import gradients from "../data/data.json";


export const whiteGradients = gradients.filter((gradient) => {
return (
generateCategory(gradient.colors[0]) === "white" ||
generateCategory(gradient.colors[1]) === "white"
);
});
export const yellowGradients = gradients.filter((gradient) => {
return (
generateCategory(gradient.colors[0]) === "yellow" ||
generateCategory(gradient.colors[1]) === "yellow"
);
});
export const redGradients = gradients.filter((gradient) => {
return (
generateCategory(gradient.colors[0]) === "red" ||
generateCategory(gradient.colors[1]) === "red"
);
});
export const greenGradients = gradients.filter((gradient) => {
return (
generateCategory(gradient.colors[0]) === "green" ||
generateCategory(gradient.colors[1]) === "green"
);
});
export const blueGradients = gradients.filter((gradient) => {
return (
generateCategory(gradient.colors[0]) === "blue" ||
generateCategory(gradient.colors[1]) === "blue"
);
});
export const blackGradients = gradients.filter((gradient) => {
return (
generateCategory(gradient.colors[0]) === "black" ||
generateCategory(gradient.colors[1]) === "black"
);
});

1 comment on commit 4c83515

@vercel
Copy link

@vercel vercel bot commented on 4c83515 Jun 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.