add props and link to home section
This commit is contained in:
@@ -16,9 +16,9 @@ export default function Home() {
|
||||
return (
|
||||
<ScrollView showsVerticalScrollIndicator={false} className='m-2'>
|
||||
<CategorySection title="Polecane kategorie" notices={notices} />
|
||||
<NoticeSection title="Najnowsze ogłoszenia" notices={latestNotices}/>
|
||||
<NoticeSection title="Najnowsze ogłoszenia" notices={latestNotices} ctaLink="/notices?sort=latest"/>
|
||||
<UserSection title="Popularni sprzedawcy" notices={notices} />
|
||||
<NoticeSection title="Proponowane ogłoszenia" notices={recomendedNotices}/>
|
||||
<NoticeSection title="Proponowane ogłoszenia" notices={recomendedNotices} ctaLink="/notices"/>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,18 @@ import {FlatList, Text, ActivityIndicator, RefreshControl} from "react-native";
|
||||
import {useState, useEffect} from "react";
|
||||
import {useNoticesStore} from "@/store/noticesStore";
|
||||
import {NoticeCard} from "@/components/NoticeCard";
|
||||
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { HStack } from "@gluestack-ui/themed";
|
||||
import { Button, ButtonText } from "@components/ui/Button";
|
||||
import { Actionsheet } from "@components/ui/Actionsheet";
|
||||
export default function Notices() {
|
||||
const {notices, fetchNotices} = useNoticesStore();
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
const params = useLocalSearchParams();
|
||||
console.log("GET params:", params);
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
@@ -25,6 +30,22 @@ export default function Notices() {
|
||||
}
|
||||
};
|
||||
|
||||
let filteredNotices = notices;
|
||||
|
||||
if (params.sort) {
|
||||
if( params.sort === "latest") {
|
||||
filteredNotices = [...filteredNotices].sort(
|
||||
(a, b) => new Date(b.publishDate) - new Date(a.publishDate)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if(params.category) {
|
||||
filteredNotices = filteredNotices.filter(
|
||||
(notice) => notice.category === params.category
|
||||
);
|
||||
}
|
||||
|
||||
const onRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
try {
|
||||
@@ -44,10 +65,12 @@ export default function Notices() {
|
||||
return <Text>Nie udało sie pobrać listy. {error.message}</Text>;
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
|
||||
<FlatList
|
||||
key={2}
|
||||
data={notices}
|
||||
data={filteredNotices}
|
||||
numColumns={2}
|
||||
columnContainerClassName="m-2"
|
||||
columnWrapperClassName="gap-2 m-2"
|
||||
|
||||
Reference in New Issue
Block a user