File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useState } from "react" ;
14import { PostList } from "@/components/feed/PostList" ;
25import { CreatePostDialog } from "@/components/feed/CreatePostDialog" ;
36
47export default function FeedPage ( ) {
8+ const [ refreshKey , setRefreshKey ] = useState ( 0 ) ;
9+
510 return (
611 < div className = "space-y-6" >
712 < div className = "flex items-center justify-between" >
813 < h1 className = "text-2xl font-semibold" > Posts</ h1 >
9- < CreatePostDialog />
14+ < CreatePostDialog onSuccess = { ( ) => setRefreshKey ( ( k ) => k + 1 ) } />
1015 </ div >
11- < PostList />
16+ < PostList refreshKey = { refreshKey } />
1217 </ div >
1318 ) ;
1419}
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ const schema = z.object({
2525
2626type FormData = z . infer < typeof schema > ;
2727
28- export function CreatePostDialog ( ) {
28+ export function CreatePostDialog ( { onSuccess } : { onSuccess ?: ( ) => void } ) {
2929 const [ open , setOpen ] = useState ( false ) ;
3030 const [ loading , setLoading ] = useState ( false ) ;
3131
@@ -48,6 +48,7 @@ export function CreatePostDialog() {
4848 toast . success ( "Post created!" ) ;
4949 reset ( ) ;
5050 setOpen ( false ) ;
51+ onSuccess ?.( ) ;
5152 } catch {
5253 toast . error ( "Failed to create post." ) ;
5354 } finally {
Original file line number Diff line number Diff line change @@ -4,15 +4,15 @@ import { useEffect, useState } from "react";
44import { Post } from "@/types" ;
55import { PostCard } from "./PostCard" ;
66
7- export function PostList ( ) {
7+ export function PostList ( { refreshKey } : { refreshKey ?: number } ) {
88 const [ posts , setPosts ] = useState < Post [ ] > ( [ ] ) ;
99
1010 useEffect ( ( ) => {
1111 fetch ( "/api/posts" )
1212 . then ( ( r ) => ( r . ok ? r . json ( ) : [ ] ) )
1313 . then ( setPosts )
1414 . catch ( console . error ) ;
15- } , [ ] ) ;
15+ } , [ refreshKey ] ) ;
1616
1717 if ( posts . length === 0 ) {
1818 return < p className = "text-center text-muted-foreground py-12" > No posts yet. Be the first!</ p > ;
You can’t perform that action at this time.
0 commit comments