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}
+ ) : (
+
+
+
+
+
+
+
+ )
+}
diff --git a/src/routes/comments/index.tsx b/src/routes/comments/index.tsx
index c45384f..f9cf190 100644
--- a/src/routes/comments/index.tsx
+++ b/src/routes/comments/index.tsx
@@ -1,35 +1,45 @@
import Comment from '@/components/Comment'
-import type { CommentType } from '@/types/comments'
+import WriteComment from '@/components/WriteComment'
+import { loadLang } from '@/integrations/lang/lang'
+import { queryOptions } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router'
// ===================
// =====< UTILS >=====
// ===================
-async function fetchData(): Promise {
- let data = await fetch(`${import.meta.env.VITE_API}/comments`)
- return await data.json()
-}
-
// =======================
// =====< COMPONENT >=====
// =======================
export const Route = createFileRoute('/comments/')({
- loader: async () => fetchData(),
+ loader: () =>
+ fetch(`${import.meta.env.VITE_API}/comments`).then((r) => r.json()),
component: Comments,
})
export default function Comments() {
let data = Route.useLoaderData()
+ let lang = loadLang()
- const items = data.map((e, i) => (
-
+ const items = data.map((e: any, i: any) => (
+
))
return (
-
{items}
+
+
+ {lang == 'fr' ? "Livre d'Or" : 'Golden Book'}
+
+
+
{items}
+
)
}