diff --git a/.prettierrc b/.prettierrc index 9ef31bca..c04b1d7c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -4,4 +4,5 @@ "semi": false, "singleQuote": true, "trailingComma": "all", + "endOfLine": "auto", } \ No newline at end of file diff --git a/src/pages/Post/Post.css b/src/pages/Post/Post.css new file mode 100644 index 00000000..9e6a9327 --- /dev/null +++ b/src/pages/Post/Post.css @@ -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; +} \ No newline at end of file diff --git a/src/pages/Post/Post.tsx b/src/pages/Post/Post.tsx new file mode 100644 index 00000000..bb215381 --- /dev/null +++ b/src/pages/Post/Post.tsx @@ -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([]) + const [loading, setLoading] = useState(true) + const [error, setError] = useState('') + + useEffect(() => { + const fetchData = async () => { + try { + const {data} = await axios.get('/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 ( +
+
    + {posts.map(({id, caption, short_text, links}) => ( +
  • +

    {caption}

    +

    {short_text}

    + {links.map(({id, url, caption}) => ( +

    +

    + {caption} +

    +

    + ))} +
    PODROBNOSTI
    +
  • + ))} +
+ {error &&

{error}

} +
+ ) +} diff --git a/src/pages/Router/Router.tsx b/src/pages/Router/Router.tsx index f9631bb5..bc10b0db 100644 --- a/src/pages/Router/Router.tsx +++ b/src/pages/Router/Router.tsx @@ -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 ( @@ -116,7 +117,7 @@ const ZdruzenieRouter: React.FC = () => { return ( <> - + )