From 3af1e72c06f888c1cc6e8cb16151fecab5038019 Mon Sep 17 00:00:00 2001 From: JaPatryk Date: Sun, 1 Jun 2025 08:57:49 +0200 Subject: [PATCH] add props and link to home section --- ArtisanConnect/app/(tabs)/index.jsx | 4 +-- ArtisanConnect/app/(tabs)/notices.jsx | 27 +++++++++++++++++-- ArtisanConnect/components/CategorySection.jsx | 7 ++--- ArtisanConnect/components/NoticeSection.jsx | 6 ++++- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/ArtisanConnect/app/(tabs)/index.jsx b/ArtisanConnect/app/(tabs)/index.jsx index b631c24..884f285 100644 --- a/ArtisanConnect/app/(tabs)/index.jsx +++ b/ArtisanConnect/app/(tabs)/index.jsx @@ -16,9 +16,9 @@ export default function Home() { return ( - + - + ); } diff --git a/ArtisanConnect/app/(tabs)/notices.jsx b/ArtisanConnect/app/(tabs)/notices.jsx index 479bc3f..d478f0d 100644 --- a/ArtisanConnect/app/(tabs)/notices.jsx +++ b/ArtisanConnect/app/(tabs)/notices.jsx @@ -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 Nie udało sie pobrać listy. {error.message}; } + return ( + { const categoryObj = categoryMap.find((cat) => cat.value === item); return ( + {categoryObj ? categoryObj.label : item} ({getCount(item)}) + ); }} /> diff --git a/ArtisanConnect/components/NoticeSection.jsx b/ArtisanConnect/components/NoticeSection.jsx index 478dbe7..2e3d339 100644 --- a/ArtisanConnect/components/NoticeSection.jsx +++ b/ArtisanConnect/components/NoticeSection.jsx @@ -1,5 +1,6 @@ import { View} from 'react-native'; import { Heading } from '@/components/ui/heading'; +import { Link } from 'expo-router'; import { FlatList } from 'react-native'; import {NoticeCard} from "@/components/NoticeCard"; import { Box } from '@/components/ui/box'; @@ -7,7 +8,7 @@ import { HStack } from "@/components/ui/hstack" import { VStack } from '@/components/ui/vstack'; import { Button, ButtonText } from "@/components/ui/button" -export function NoticeSection({ notices, title }) { +export function NoticeSection({ notices, title, ctaLink=''}) { const rows = []; for (let i = 0; i < notices.length; i += 2) { rows.push( @@ -23,9 +24,12 @@ export function NoticeSection({ notices, title }) { {rows} + {ctaLink && ( + + )} ); } \ No newline at end of file