@@ -4,13 +4,13 @@ import { useEffect, useState } from "react";
44import CreatePostModal from "@/components/modals/CreatePostModal" ;
55import { Button } from "@/components/ui/button" ;
66import { useUserStore } from "@/store/codev-store" ;
7- import { ChevronDown } from "lucide-react" ;
87
98import Feed from "./_components/Feed" ;
109import SocialPointsCard from "./_components/SocialPointsCard" ;
1110import SortMenu from "./_components/SortMenu" ;
1211import { SEARCH_DEBOUNCE_MS } from "./_constants" ;
13- import { getUserRole } from "./_services/action" ;
12+ import { getUserRole , hasReachedDailyPostLimit } from "./_services/action" ;
13+ import toast from "react-hot-toast" ;
1414
1515type SortField = "title" | "date" | "upvotes" ;
1616type SortOrder = "asc" | "desc" ;
@@ -22,7 +22,6 @@ export default function FeedsPage() {
2222 const [ debouncedQuery , setDebouncedQuery ] = useState ( "" ) ;
2323 const [ sortField , setSortField ] = useState < SortField > ( "date" ) ;
2424 const [ sortOrder , setSortOrder ] = useState < SortOrder > ( "desc" ) ;
25- const [ sortMenuOpen , setSortMenuOpen ] = useState ( false ) ;
2625 const { user } = useUserStore ( ) ;
2726
2827 useEffect ( ( ) => {
@@ -42,7 +41,22 @@ export default function FeedsPage() {
4241 return ( ) => clearTimeout ( handler ) ;
4342 } , [ searchQuery ] ) ;
4443
45- const openModal = ( ) => setIsModalOpen ( true ) ;
44+ const openModal = async ( ) => {
45+ if ( ! user ) return ;
46+
47+ try {
48+ const unallowed = await hasReachedDailyPostLimit ( user . id ) ;
49+
50+ if ( unallowed ) {
51+ toast . error ( "Daily post limit reached. You’re not allowed to create a post right now." ) ;
52+ return ;
53+ }
54+
55+ setIsModalOpen ( true ) ;
56+ } catch ( error ) {
57+ console . error ( "Failed to check posting permission" , error ) ;
58+ }
59+ } ;
4660 const closeModal = ( ) => setIsModalOpen ( false ) ;
4761
4862 return (
0 commit comments