@@ -9,8 +9,10 @@ import Feed from "./_components/Feed";
99import SocialPointsCard from "./_components/SocialPointsCard" ;
1010import SortMenu from "./_components/SortMenu" ;
1111import { SEARCH_DEBOUNCE_MS } from "./_constants" ;
12- import { getUserRole , hasReachedDailyPostLimit } from "./_services/action" ;
12+ import { getUserRole , hasNotPostedYet , hasReachedDailyPostLimit } from "./_services/action" ;
1313import toast from "react-hot-toast" ;
14+ import FirstPostPrompt from "./_components/FirstPostPrompt" ;
15+ import { PlusCircle } from "lucide-react" ;
1416
1517type SortField = "title" | "date" | "upvotes" ;
1618type SortOrder = "asc" | "desc" ;
@@ -22,6 +24,7 @@ export default function FeedsPage() {
2224 const [ debouncedQuery , setDebouncedQuery ] = useState ( "" ) ;
2325 const [ sortField , setSortField ] = useState < SortField > ( "date" ) ;
2426 const [ sortOrder , setSortOrder ] = useState < SortOrder > ( "desc" ) ;
27+ const [ userHasNotPostedYet , setUserHasNotPostedYet ] = useState ( false ) ;
2528 const { user } = useUserStore ( ) ;
2629
2730 useEffect ( ( ) => {
@@ -33,6 +36,21 @@ export default function FeedsPage() {
3336 if ( user ) fetchRole ( ) ;
3437 } , [ user ] ) ;
3538
39+ useEffect ( ( ) => {
40+ if ( ! user ) return ;
41+
42+ const checkIfUserHasPosted = async ( ) => {
43+ try {
44+ const result = await hasNotPostedYet ( user . id ) ;
45+ setUserHasNotPostedYet ( result ) ;
46+ } catch ( error ) {
47+ console . error ( error ) ;
48+ }
49+ } ;
50+
51+ checkIfUserHasPosted ( ) ;
52+ } , [ user ] ) ;
53+
3654 useEffect ( ( ) => {
3755 const handler = setTimeout (
3856 ( ) => setDebouncedQuery ( searchQuery ) ,
@@ -72,9 +90,21 @@ export default function FeedsPage() {
7290
7391 < SocialPointsCard />
7492
75- < Button className = "mb-4 mt-4 w-auto" onClick = { openModal } >
76- Create Post
77- </ Button >
93+ { userHasNotPostedYet && (
94+ < div className = "mb-4" >
95+ < FirstPostPrompt onCreatePost = { openModal } />
96+ </ div >
97+ ) }
98+
99+ { ! userHasNotPostedYet && (
100+ < Button
101+ onClick = { openModal }
102+ className = "gap-2 w-auto mb-4"
103+ >
104+ < PlusCircle className = "h-5 w-5" />
105+ Create Post
106+ </ Button >
107+ ) }
78108
79109 { /* Search bar + sort button row */ }
80110 < div className = "relative mb-6 flex items-center gap-4" >
0 commit comments