Skip to content

Commit

Permalink
Post (#18)
Browse files Browse the repository at this point in the history
* prispevky na zdruzeni, zatial bez vela css

* zobrazenie linkov

* Update src/pages/Post/Post.tsx

oprava useStatov

Co-authored-by: Richard Trembecký <[email protected]>

* zapracovanie pripomienok

* Update src/pages/Post/Post.tsx

destructuring

Co-authored-by: Richard Trembecký <[email protected]>

* oprava

* fix line endings handling on Windows

* rewrite promise-style fetch to awaited axios.get

also fix bad merge and bring back destructuring

Co-authored-by: Adzedze <[email protected]>
Co-authored-by: Richard Trembecký <[email protected]>
  • Loading branch information
3 people authored Apr 27, 2021
1 parent d546f12 commit 99bc4b2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "auto",
}
13 changes: 13 additions & 0 deletions src/pages/Post/Post.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#posts {
background-color: white;
text-decoration-color: black;
position: static;
padding-left: 0cm;
}

#post {
list-style: none;
margin: 0px auto;
width: 800px;
text-align: left;
}
63 changes: 63 additions & 0 deletions src/pages/Post/Post.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import './Post.css'

import axios, {AxiosError} from 'axios'
import React, {FC, useEffect, useState} from 'react'

interface IPost {
id: number
links: {id: number; caption: string; url: string}[]
caption: string
short_text: string
details: string
added_at: string
show_after: string
disable_after: string
}

export const Posts: FC = () => {
const [posts, setPosts] = useState<IPost[]>([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState('')

useEffect(() => {
const fetchData = async () => {
try {
const {data} = await axios.get<IPost[]>('/api/cms/post/visible/', {
headers: {
'Content-type': 'application/json',
},
})
setPosts(data)
} catch (e) {
const ex = e as AxiosError
const error = ex.response?.status === 404 ? 'Resource not found' : 'An unexpected error has occurred'
setError(error)
} finally {
setLoading(false)
}
}
fetchData()
}, [])

return (
<div id="posts">
<ul id="post">
{posts.map(({id, caption, short_text, links}) => (
<li key={id}>
<h2 id="bold">{caption}</h2>
<h3>{short_text}</h3>
{links.map(({id, url, caption}) => (
<p key={id}>
<h3>
<a href={url}>{caption}</a>
</h3>
</p>
))}
<h5 id="bold">PODROBNOSTI</h5>
</li>
))}
</ul>
{error && <p>{error}</p>}
</div>
)
}
3 changes: 2 additions & 1 deletion src/pages/Router/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {LatexExample} from '../../components/Latex/LatexExample'
import {PageLayout} from '../../components/PageLayout/PageLayout'
import {Admin} from '../Admin/Admin'
import {PagePlaceholder} from '../PagePlaceholder'
import {Posts} from '../Post/Post'

export const Router: React.FC<{seminarId: number}> = ({seminarId}) => {
return (
Expand Down Expand Up @@ -116,7 +117,7 @@ const ZdruzenieRouter: React.FC = () => {
return (
<>
<Route exact path={path}>
<PagePlaceholder title="Združenie home" />
<Posts />
</Route>
</>
)
Expand Down

0 comments on commit 99bc4b2

Please sign in to comment.