import { View, Text, ScrollView, Pressable } from "react-native"; import { useRouter } from "expo-router"; import { useState } from "react"; import { useQuery } from "convex/react"; import { api } from "../../../convex/_generated/api"; import { useAuth } from "../../_layout"; import { useTheme } from "../../../components/theme"; import { PostCard } from "../../../components/post-card"; import { Loading } from "../../../components/ui/loading"; const TABS = [ { key: "open", label: "Отворени" }, { key: "all", label: "Сите" }, ] as const; type TabKey = (typeof TABS)[number]["key"]; export default function PostsScreen() { const router = useRouter(); const theme = useTheme(); const { token, isAuthenticated } = useAuth(); const currentUser = useQuery( api.users.getCurrentUser, isAuthenticated && token ? { token } : "skip" ); const [activeTab, setActiveTab] = useState("open"); const posts = useQuery( api.posts.list, activeTab === "open" ? { status: "open" } : {} ); const isCustomer = currentUser?.role !== "handyman"; return ( {isAuthenticated && isCustomer && ( router.push("/post/create" as any)}> + Ново побарување )} {TABS.map((tab) => ( setActiveTab(tab.key)} style={{ flex: 1, paddingVertical: 10, borderRadius: theme.radius.sm, alignItems: "center", backgroundColor: activeTab === tab.key ? theme.colors.card : "transparent", ...(activeTab === tab.key ? { boxShadow: "0 1px 3px rgba(0,0,0,0.08)" as any } : {}), }} > {tab.label} ))} {posts === undefined ? ( ) : posts.length === 0 ? ( 📋 Нема побарувања {activeTab === "open" ? "Нема отворени побарувања во моментот." : "Сеуште нема побарувања."} ) : ( {posts.map((post) => ( ))} )} ); }