diff --git a/src/components/Comment.tsx b/src/components/Comment.tsx index 75cbe98..57053e0 100644 --- a/src/components/Comment.tsx +++ b/src/components/Comment.tsx @@ -3,12 +3,23 @@ import Mdown from './Mdown' interface Props { author: string content: string + date_posted: number } -export default function Comment({ author, content }: Props) { +export default function Comment({ author, content, date_posted }: Props) { + let date = new Date(date_posted * 1000) return ( -
-

{author}

+
+

+ {author} + + {date.toLocaleDateString('fr-FR', { + day: 'numeric', + month: 'long', + year: 'numeric', + })} + +

{content}
diff --git a/src/components/Header.tsx b/src/components/Header.tsx index b360520..a7a8b10 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -34,9 +34,7 @@ export default function Header() {
- {lang == 'fr' - ? "[WIP] Livre d'Or" - : '[WIP] Golden Book'} + {lang == 'fr' ? "Livre d'Or" : 'Golden Book'}
diff --git a/src/components/WriteComment.tsx b/src/components/WriteComment.tsx new file mode 100644 index 0000000..2804716 --- /dev/null +++ b/src/components/WriteComment.tsx @@ -0,0 +1,81 @@ +import { useRouter } from '@tanstack/react-router' +import { useState } from 'react' +import Mdown from './Mdown' +import { loadLang } from '@/integrations/lang/lang' + +export default function WriteComment() { + const router = useRouter() + const [pseudo, setPseudo] = useState('') + const [content, setContent] = useState('') + const [preview, setPreview] = useState(false) + const lang = loadLang() + + function sendComment() { + if (content.trim() == '') { + alert('Attention, un contenu doit être précisé !') + return + } + fetch(`${import.meta.env.VITE_API}/comment/create`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + author: pseudo.trim() == '' ? 'Inconnu·e' : pseudo.trim(), + content: content, + }), + }).then(() => { + router.invalidate() + setPseudo('') + setContent('') + }) + } + + return ( +
+

+ {lang == 'fr' + ? 'Écrivez un commentaire (Markdown supporté)' + : 'Write a comment (Markdown supported)'} +

+
+

+ setPseudo(e.target.value)} + className="w-full" + /> +

+
+ {preview ? ( + {content} + ) : ( +