third commit
This commit is contained in:
parent
3e3c0ca339
commit
0e79054b4e
@ -13,6 +13,7 @@ export default function Home() {
|
|||||||
const [articles, setArticles] = useState([])
|
const [articles, setArticles] = useState([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [articleByTag, setArticleByTag] = useState('')
|
const [articleByTag, setArticleByTag] = useState('')
|
||||||
|
const [message, setMessage] = useState('')
|
||||||
const [articleByFollowing, setArticleByFollowing] = useState(false)
|
const [articleByFollowing, setArticleByFollowing] = useState(false)
|
||||||
const [meta, setMeta] = useState({
|
const [meta, setMeta] = useState({
|
||||||
to: 0,
|
to: 0,
|
||||||
@ -24,18 +25,27 @@ export default function Home() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchArticles = async () => {
|
const fetchArticles = async () => {
|
||||||
|
setMessage('')
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
if (articleByTag) {
|
if (articleByTag) {
|
||||||
const response = await axios.get(`${BASE_URL}/tag/${articleByTag}/articles`)
|
const response = await axios.get(`${BASE_URL}/tag/${articleByTag}/articles`)
|
||||||
setArticles(response.data.data)
|
if (response.data.data.length) {
|
||||||
setMeta(response.data.meta)
|
setArticles(response.data.data)
|
||||||
|
setMeta(response.data.meta)
|
||||||
|
}else {
|
||||||
|
setMessage('No articles found.')
|
||||||
|
}
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} else if (articleByFollowing) {
|
} else if (articleByFollowing) {
|
||||||
const response = await axios.get(`${BASE_URL}/followings/articles`,
|
const response = await axios.get(`${BASE_URL}/followings/articles`,
|
||||||
getConfig(token))
|
getConfig(token))
|
||||||
setArticles(response.data.data)
|
if (response.data.data.length) {
|
||||||
setMeta(response.data.meta)
|
setArticles(response.data.data)
|
||||||
|
setMeta(response.data.meta)
|
||||||
|
}else {
|
||||||
|
setMessage('No articles found.')
|
||||||
|
}
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} else {
|
} else {
|
||||||
const response = await axios.get(`${BASE_URL}/articles`)
|
const response = await axios.get(`${BASE_URL}/articles`)
|
||||||
@ -90,10 +100,19 @@ export default function Home() {
|
|||||||
setArticleByTag={setArticleByTag} />
|
setArticleByTag={setArticleByTag} />
|
||||||
}
|
}
|
||||||
{/* display all the published articles */}
|
{/* display all the published articles */}
|
||||||
<ArticleList articles={articles}
|
{
|
||||||
fetchNextArticles={fetchNextArticles}
|
message ?
|
||||||
meta={meta}
|
<div className="col-md-8">
|
||||||
|
<div className="alert alert-info">
|
||||||
|
No articles found
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<ArticleList articles={articles}
|
||||||
|
fetchNextArticles={fetchNextArticles}
|
||||||
|
meta={meta}
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
{/* display all the tags */}
|
{/* display all the tags */}
|
||||||
<Tags setArticleByTag={setArticleByTag}
|
<Tags setArticleByTag={setArticleByTag}
|
||||||
articleByTag={articleByTag}
|
articleByTag={articleByTag}
|
||||||
|
|||||||
@ -25,14 +25,10 @@ export default function ArticleList({articles, fetchNextArticles, meta}) {
|
|||||||
return (
|
return (
|
||||||
<div className='col-md-8'>
|
<div className='col-md-8'>
|
||||||
{
|
{
|
||||||
articles?.length ? articles?.map(article => (
|
articles?.map(article => (
|
||||||
<ArticleListItem article={article}
|
<ArticleListItem article={article}
|
||||||
key={article.id} />
|
key={article.id} />
|
||||||
))
|
))
|
||||||
:
|
|
||||||
<div className="alert alert-info">
|
|
||||||
No article found.
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { BASE_URL } from '../../helpers/config'
|
import { BASE_URL } from '../../helpers/config'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link, useNavigate } from 'react-router-dom'
|
||||||
|
|
||||||
export default function SearchBox() {
|
export default function SearchBox() {
|
||||||
const [searchTerm, setSearTerm] = useState('')
|
const [searchTerm, setSearTerm] = useState('')
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
const [articles, setArticles] = useState([])
|
const [articles, setArticles] = useState([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const searchArticles = async (e) => {
|
const searchArticles = async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -34,6 +35,11 @@ export default function SearchBox() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const viewArticleDetails = (slug) => {
|
||||||
|
navigate(`/articles/${slug}`)
|
||||||
|
setArticles([])
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="offcanvas offcanvas-start" tabIndex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
|
<div className="offcanvas offcanvas-start" tabIndex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel">
|
||||||
<div className="offcanvas-header">
|
<div className="offcanvas-header">
|
||||||
@ -84,10 +90,10 @@ export default function SearchBox() {
|
|||||||
<span>
|
<span>
|
||||||
{ article.title }
|
{ article.title }
|
||||||
</span>
|
</span>
|
||||||
<Link to={`/articles/${article.slug}`}
|
<button onClick={() => viewArticleDetails(article.slug)}
|
||||||
className='text-decoration-none text-primary'>
|
className='text-decoration-none btn btn-link text-primary'>
|
||||||
View
|
View
|
||||||
</Link>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
))
|
))
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { Link, useNavigate } from 'react-router-dom'
|
import { Link, useNavigate } from 'react-router-dom'
|
||||||
import useTitle from '../../custom/useTitle'
|
import useTitle from '../../custom/useTitle'
|
||||||
|
import { bookmark } from '../../../redux/slices/bookmarkSlice'
|
||||||
|
|
||||||
export default function Bookmarked() {
|
export default function Bookmarked() {
|
||||||
const { isLoggedIn } = useSelector(state => state.user)
|
const { isLoggedIn } = useSelector(state => state.user)
|
||||||
const { bookmarked } = useSelector(state => state.bookmark)
|
const { bookmarked } = useSelector(state => state.bookmark)
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
//change page title
|
//change page title
|
||||||
useTitle('Saved Articles')
|
useTitle('Saved Articles')
|
||||||
@ -45,6 +47,10 @@ export default function Bookmarked() {
|
|||||||
to={`/articles/${article.slug}`}>
|
to={`/articles/${article.slug}`}>
|
||||||
<i className="bi bi-eye"></i>
|
<i className="bi bi-eye"></i>
|
||||||
</Link>
|
</Link>
|
||||||
|
<button className="btn btn-sm btn-danger ms-2"
|
||||||
|
onClick={() => dispatch(bookmark(article))}>
|
||||||
|
<i className="bi bi-bookmark-dash"></i>
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { Link, useNavigate } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { setCurrentUser } from '../../../redux/slices/userSlice'
|
import { setCurrentUser } from '../../../redux/slices/userSlice'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
@ -10,20 +10,25 @@ import Spinner from '../../layouts/Spinner'
|
|||||||
export default function UserArticles() {
|
export default function UserArticles() {
|
||||||
const { token } = useSelector(state => state.user)
|
const { token } = useSelector(state => state.user)
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const navigate = useNavigate()
|
|
||||||
const [articles, setArticles] = useState([])
|
const [articles, setArticles] = useState([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [message, setMessage] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchUserArticles()
|
fetchUserArticles()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const fetchUserArticles = async () => {
|
const fetchUserArticles = async () => {
|
||||||
|
setMessage('')
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${BASE_URL}/user/articles`,
|
const response = await axios.get(`${BASE_URL}/user/articles`,
|
||||||
getConfig(token))
|
getConfig(token))
|
||||||
setArticles(response.data.data)
|
if (response.data.data.length) {
|
||||||
|
setArticles(response.data.data)
|
||||||
|
}else {
|
||||||
|
setMessage('No articles found.')
|
||||||
|
}
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@ -55,7 +60,11 @@ export default function UserArticles() {
|
|||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
:
|
:
|
||||||
articles?.length ?
|
message ?
|
||||||
|
<div className="alert alert-info">
|
||||||
|
{ message }
|
||||||
|
</div>
|
||||||
|
:
|
||||||
<table className='table table-responsive'>
|
<table className='table table-responsive'>
|
||||||
<caption>List of published articles</caption>
|
<caption>List of published articles</caption>
|
||||||
<thead>
|
<thead>
|
||||||
@ -111,10 +120,6 @@ export default function UserArticles() {
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
:
|
|
||||||
<div className="alert alert-info">
|
|
||||||
No articles found.
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user