import { View, Text, ScrollView, RefreshControl, Pressable } from "react-native"; import { useRouter } from "expo-router"; import { useState, useCallback } from "react"; import { usePaginatedQuery, 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"; import { Button } from "../../../components/ui/button"; 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 [refreshing, setRefreshing] = useState(false); const postsResult = usePaginatedQuery( api.posts.listPaginated, activeTab === "open" ? { status: "open" as const } : {}, { initialNumItems: 20 } ); const onRefresh = useCallback(() => { setRefreshing(true); setTimeout(() => setRefreshing(false), 800); }, []); const isCustomer = currentUser?.role !== "handyman"; return ( } contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md, paddingBottom: 80 }} > {isAuthenticated && isCustomer && ( )} {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 ? theme.shadows.sm : undefined), }} > {tab.label} ))} {postsResult.status === "LoadingFirstPage" ? ( ) : postsResult.results.length === 0 ? ( 📋 Нема побарувања {activeTab === "open" ? "Нема отворени побарувања во моментот." : "Сè уште нема побарувања."} ) : ( {postsResult.results.map((post) => ( ))} )} {postsResult.status === "CanLoadMore" && ( postsResult.loadMore(20)} style={{ backgroundColor: theme.colors.surfaceAlt, borderRadius: theme.radius.md, paddingVertical: theme.spacing.md, alignItems: "center", borderWidth: 1, borderColor: theme.colors.borderLight, }} > Вчитај повеќе )} ); }