import { View, Text, Pressable, ScrollView, RefreshControl } from "react-native";
import { useLocalSearchParams, Link } from "expo-router";
import { useState, useCallback } from "react";
import { Ionicons } from "@expo/vector-icons";
import { useTheme } from "../../../components/theme";
import { usePaginatedQuery, useQuery } from "convex/react";
import { api } from "../../../convex/_generated/api";
import { CategoryGrid } from "../../../components/category-grid";
import { AdCard } from "../../../components/ad-card";
import { Loading } from "../../../components/ui/loading";
import { CATEGORIES, CATEGORY_EMOJI, getCategoryName } from "../../../lib/constants";
export default function ExploreScreen() {
const theme = useTheme();
const { category } = useLocalSearchParams<{ category?: string }>();
const [refreshing, setRefreshing] = useState(false);
const categories = useQuery(api.categories.list);
const categoryAdsResult = usePaginatedQuery(
api.ads.getByCategoryPaginated,
category ? { category } : "skip",
{ initialNumItems: 20 }
);
const allAdsResult = usePaginatedQuery(api.ads.listPaginated, {}, { initialNumItems: 20 });
const onRefresh = useCallback(() => {
setRefreshing(true);
setTimeout(() => setRefreshing(false), 800);
}, []);
const displayCategories = categories ?? CATEGORIES;
if (category) {
const catName = getCategoryName(category);
const catEmoji = CATEGORY_EMOJI[category] ?? "📋";
return (
{catEmoji}
{catName}
}
contentContainerStyle={{ padding: theme.spacing.md, gap: theme.spacing.sm, paddingBottom: 100 }}
>
{categoryAdsResult.status === "LoadingFirstPage" ? (
) : categoryAdsResult.results.length === 0 ? (
Нема огласи
Нема огласи во оваа категорија
) : (
categoryAdsResult.results.map((ad) => (
))
)}
{categoryAdsResult.status === "CanLoadMore" && (
categoryAdsResult.loadMore(20)}
style={{
backgroundColor: theme.colors.surface,
borderRadius: theme.radius.lg,
paddingVertical: 14,
alignItems: "center",
borderWidth: 1,
borderColor: theme.colors.border,
marginTop: theme.spacing.sm,
...theme.shadows.xs,
}}
>
Вчитај повеќе
)}
);
}
return (
Категории
Изберете категорија за да пребарувате
}
contentContainerStyle={{ padding: theme.spacing.md, gap: theme.spacing.md, paddingBottom: 100 }}
>
Сите огласи
{allAdsResult.results.length}+
{allAdsResult.status === "LoadingFirstPage" ? (
) : allAdsResult.results.length === 0 ? (
Нема огласи
) : (
allAdsResult.results.map((ad) => (
))
)}
{allAdsResult.status === "CanLoadMore" && (
allAdsResult.loadMore(20)}
style={{
backgroundColor: theme.colors.surface,
borderRadius: theme.radius.lg,
paddingVertical: 14,
alignItems: "center",
borderWidth: 1,
borderColor: theme.colors.border,
marginTop: theme.spacing.sm,
...theme.shadows.xs,
}}
>
Вчитај повеќе
)}
);
}