1
1
'use client' ;
2
2
3
+ import { useState , useEffect } from 'react' ;
3
4
import { Button } from '@/components/ui/button' ;
5
+ import { KeluhCard } from '@/components/keluh-card' ;
6
+ import { KeluhAdd } from '@/components/keluh-add' ;
7
+ import { getPosts } from '@/lib/storage' ;
4
8
import { MessageSquarePlus } from 'lucide-react' ;
9
+ import { KeluhPost } from './types' ;
5
10
6
11
export default function Home ( ) {
12
+ const [ posts , setPosts ] = useState < KeluhPost [ ] > ( [ ] ) ;
13
+ const [ isNewPostOpen , setIsNewPostOpen ] = useState ( false ) ;
14
+
15
+ const loadPosts = ( ) => {
16
+ setPosts ( getPosts ( ) ) ;
17
+ } ;
18
+
19
+ useEffect ( ( ) => {
20
+ loadPosts ( ) ;
21
+ } , [ ] ) ;
7
22
8
23
return (
9
24
< main className = "min-h-screen bg-gray-50 dark:bg-gray-900" >
@@ -13,15 +28,34 @@ export default function Home() {
13
28
Keluh Kesah
14
29
</ h1 >
15
30
< p className = "text-muted-foreground text-center mb-6" >
16
- Silahkan berkeluh kesah di sini sepuasnya .
31
+ Silahkan berkeluh kesah di sini.
17
32
</ p >
18
33
< Button
19
34
size = "lg"
35
+ onClick = { ( ) => setIsNewPostOpen ( true ) }
20
36
>
21
37
< MessageSquarePlus className = "w-5 h-5" />
22
- Keluhan Baru
38
+ Tambah Keluhan
23
39
</ Button >
24
40
</ div >
41
+
42
+ < div className = "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 max-w-7xl mx-auto" >
43
+ { posts . map ( ( post ) => (
44
+ < KeluhCard key = { post . id } post = { post } onUpdate = { loadPosts } />
45
+ ) ) }
46
+ </ div >
47
+
48
+ { posts . length === 0 && (
49
+ < div className = "text-center text-muted-foreground mt-8" >
50
+ Belum ada yang ngeluh nih. Yuk mulai ngeluh!
51
+ </ div >
52
+ ) }
53
+
54
+ < KeluhAdd
55
+ open = { isNewPostOpen }
56
+ onOpenChange = { setIsNewPostOpen }
57
+ onPostCreated = { loadPosts }
58
+ />
25
59
</ div >
26
60
</ main >
27
61
) ;
0 commit comments