import { View, Text, Pressable, ScrollView, RefreshControl } from "react-native";
import { useLocalSearchParams, Link } from "expo-router";
import { useState, useCallback } from "react";
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 (
}
contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md }}
>
← Сите
{catEmoji}
{catName}
{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.md,
paddingVertical: theme.spacing.md,
alignItems: "center",
borderWidth: 1,
borderColor: theme.colors.border,
}}
>
Вчитај повеќе
)}
);
}
return (
}
contentContainerStyle={{ padding: theme.spacing.lg, gap: theme.spacing.md }}
>
Пребарувај по категорија
Сите огласи
{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.md,
paddingVertical: theme.spacing.md,
alignItems: "center",
borderWidth: 1,
borderColor: theme.colors.border,
}}
>
Вчитај повеќе
)}
);
}