1+ import useAPI from "../../hooks/useAPI.js" ;
2+ import useOrderedStyles from "../../hooks/useOrderedStyles.js" ;
3+ import { useContext , useEffect , useState } from "react" ;
4+ import AuthContext from "../../contexts/AuthContext.js" ;
5+ import { useNavigate , useParams } from "react-router" ;
6+ import ArticleTile from "./ArticleTile.jsx" ;
7+
8+ export default function Article ( props ) {
9+ const { date, feast, saint, holiday, author, image, content, title} = props
10+ const { id} = useParams ( )
11+ const { loadArticles} = useAPI ( ) ;
12+ const { addStyle} = useOrderedStyles ( )
13+ const { is_authenticated} = useContext ( AuthContext )
14+ const [ article , setArticle ] = useState ( { } ) ;
15+ const navigate = useNavigate ( ) ;
16+
17+ useEffect ( ( ) => {
18+ addStyle ( "/articles/article.css" , "articles" )
19+ } , [ ] ) ;
20+
21+ useEffect ( ( ) => {
22+ loadArticles ( date , feast , saint , holiday , author , id ) . then ( response => {
23+ setArticle (
24+ response ?. data [ 0 ]
25+ )
26+ }
27+ )
28+ } , [ date , feast , saint , holiday , author ] ) ;
29+
30+ return (
31+ < >
32+ < section className = "single-article" >
33+ < article >
34+ < figure >
35+ { ! ! article . image && ( < img src = { article . image } alt = { article . title } /> ) }
36+ { ! article . image && ( < img src = { '/src/assets/images/articles/saint.webp' } alt = "няма изображение" /> ) }
37+ </ figure >
38+ < main >
39+ < h2 > { article . title } </ h2 >
40+ < p > { article . content } </ p >
41+ < nav >
42+ < ul >
43+ { /*{% if article.is_own %}*/ }
44+ { /*<li><a href="{% url "article-delete" article.pk %}">*/ }
45+ { /* */ }
46+ { /*</a></li>*/ }
47+ { /*{% endif %}*/ }
48+ { /*{% if article.can_change or article.is_own %}*/ }
49+ { /*<li><a href="{% url "article-edit" article.pk %}">*/ }
50+ { /* */ }
51+ { /*</a></li>*/ }
52+ { /*{% endif %}*/ }
53+ </ ul >
54+ </ nav >
55+ </ main >
56+ </ article >
57+ </ section >
58+ </ >
59+ )
60+ }
0 commit comments