-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb2d0ba
commit f371607
Showing
10 changed files
with
221 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Banner = () => { | ||
return ( | ||
<>Banner</> | ||
) | ||
} | ||
|
||
export default Banner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { useEffect, useState } from "react"; | ||
import { NavLink } from "react-router-dom"; | ||
import styled from "styled-components"; | ||
import { COLORS } from "../constants"; | ||
import { fullWrittenDate, shortWrittenDate } from "../helpers"; | ||
import { FaCircle, FaRegPaperPlane } from "react-icons/fa"; | ||
import Loading from "./Loading/Loading"; | ||
|
||
const Trending = () => { | ||
const [loading, setLoading] = useState(true); | ||
const [data, setData] = useState([]); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
fetch(`/api/trending`) | ||
.then((res) => res.json()) | ||
.then((response) => { | ||
// console.log(response.data); | ||
setData(response.data); | ||
setLoading(false); | ||
}); | ||
// eslint-disable-next-line | ||
}, []); | ||
|
||
const stopPropagation = (event) => { | ||
event.stopPropagation(); | ||
} | ||
|
||
if (loading) return <Loading size="32" />; | ||
|
||
return ( | ||
<> | ||
<Title> | ||
<div><FaRegPaperPlane /></div> | ||
<div>Trending on {fullWrittenDate(new Date().getTime(), 'en-US')}</div> | ||
</Title> | ||
<Wrapper> | ||
{ | ||
data.map((item, index) => ( | ||
<Container key={item._id}> | ||
<Indice>0{index + 1}.</Indice> | ||
<SubWrapper> | ||
<StyledLink | ||
to={`/${item.username}/${item.slug}`} | ||
onClick={stopPropagation} | ||
>{ item.title }</StyledLink> | ||
<StyledInfo> | ||
<div>{shortWrittenDate(item.createdAt)}</div> | ||
<Circle><FaCircle /></Circle> | ||
<div>{item.readingTime} min read</div> | ||
</StyledInfo> | ||
</SubWrapper> | ||
</Container> | ||
)) | ||
} | ||
</Wrapper> | ||
</> | ||
) | ||
} | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin: 16px 0 24px 0; | ||
`; | ||
const SubWrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
const Container = styled.button` | ||
display: flex; | ||
width: 50%; | ||
gap: 16px; | ||
padding: 16px; | ||
align-items: flex-start; | ||
background: none; | ||
outline: none; | ||
border: none; | ||
border-radius: 4px; | ||
text-align: left; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: ${COLORS.light}; | ||
} | ||
`; | ||
const Indice = styled.div` | ||
font-size: 32px; | ||
font-weight: bold; | ||
color: ${COLORS.grey}; | ||
`; | ||
const StyledLink = styled(NavLink)` | ||
font-size: 16px; | ||
color: ${COLORS.dark}; | ||
text-decoration: none; | ||
margin-top: 3px; | ||
&:hover { | ||
color: ${COLORS.black}; | ||
} | ||
`; | ||
const StyledInfo = styled.div` | ||
display: flex; | ||
justify-content: flex-start; | ||
align-items: center; | ||
font-size: 14px; | ||
gap: 4px; | ||
color: ${COLORS.secondary}; | ||
margin-top: 8px; | ||
`; | ||
const Circle = styled.div` | ||
font-size: 3px; | ||
`; | ||
const Title = styled.div` | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
font-size: 16px; | ||
font-weight: bold; | ||
margin-top: 24px; | ||
`; | ||
|
||
export default Trending; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// https://gist.github.com/codeguy/6684588?permalink_comment_id=3243980#gistcomment-3243980 | ||
const slugify = (text) => { | ||
return text | ||
.toString() // Cast to string (optional) | ||
.normalize("NFKD") // The normalize() using NFKD method returns the Unicode Normalization Form of a given string. | ||
.toLowerCase() // Convert the string to lowercase letters | ||
.trim() // Remove whitespace from both sides of a string (optional) | ||
.replace(/\s+/g, "-") // Replace spaces with - | ||
.replace(/[^\w\-]+/g, "") // Remove all non-word chars | ||
.replace(/\-\-+/g, "-"); // Replace multiple - with single - | ||
}; | ||
|
||
const readingTime = (text) => { | ||
const contentString = JSON.stringify(text); | ||
const words = contentString.split(" ").length; | ||
const wordsPerMinute = 200; | ||
return Math.ceil(words / wordsPerMinute); | ||
}; | ||
|
||
module.exports = { | ||
slugify, | ||
readingTime, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters