fix login check and urls
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import { ScrollView, View } from "react-native";
|
||||
import { useNoticesStore } from '@/store/noticesStore';
|
||||
import { useNoticesStore } from "@/store/noticesStore";
|
||||
import { CategorySection } from "@/components/CategorySection";
|
||||
import { NoticeSection } from "@/components/NoticeSection";
|
||||
import { UserSection } from "@/components/UserSection";
|
||||
import { SearchSection } from "@/components/SearchSection";
|
||||
import { FlatList } from 'react-native';
|
||||
import { FlatList } from "react-native";
|
||||
import { useAuthStore } from "@/store/authStore";
|
||||
import { useRouter } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
// import { SafeAreaView } from "react-native-safe-area-context";
|
||||
import { SafeAreaView } from "react-native";
|
||||
|
||||
export default function Home() {
|
||||
const token = useAuthStore((state) => state.token);
|
||||
const token = useAuthStore((state) => state.token);
|
||||
const router = useRouter();
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
|
||||
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
|
||||
|
||||
useEffect(() => {
|
||||
setIsReady(true);
|
||||
@@ -27,36 +26,41 @@ const token = useAuthStore((state) => state.token);
|
||||
}
|
||||
}, [isReady, token, router]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (token) {
|
||||
fetchNotices();
|
||||
}
|
||||
}, [token, fetchNotices]);
|
||||
|
||||
fetchNotices();
|
||||
}
|
||||
}, [token, fetchNotices]);
|
||||
|
||||
const notices = useNoticesStore((state) => state.notices);
|
||||
// console.log("Notices:", notices);
|
||||
|
||||
// console.log("Notices:", notices);
|
||||
|
||||
const latestNotices = [...notices]
|
||||
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate))
|
||||
.slice(0, 6);
|
||||
const recomendedNotices = [...notices]
|
||||
const recomendedNotices = [...notices]
|
||||
.sort(() => Math.random() - 0.5)
|
||||
.slice(0, 6);
|
||||
|
||||
|
||||
return (
|
||||
<SafeAreaView className="flex-1 m-2">
|
||||
{/* <View> */}
|
||||
<SearchSection/>
|
||||
<ScrollView showsVerticalScrollIndicator={false} >
|
||||
<SafeAreaView className="flex-1 m-2">
|
||||
{/* <View> */}
|
||||
<SearchSection />
|
||||
<ScrollView showsVerticalScrollIndicator={false}>
|
||||
<CategorySection title="Polecane kategorie" notices={notices} />
|
||||
<NoticeSection title="Najnowsze ogłoszenia" notices={latestNotices} ctaLink="/notices?sort=latest"/>
|
||||
<NoticeSection
|
||||
title="Najnowsze ogłoszenia"
|
||||
notices={latestNotices}
|
||||
ctaLink="/notices?sort=latest"
|
||||
/>
|
||||
<UserSection title="Popularni sprzedawcy" notices={notices} />
|
||||
<NoticeSection title="Proponowane ogłoszenia" notices={recomendedNotices} ctaLink="/notices"/>
|
||||
</ScrollView>
|
||||
{/* </View> */}
|
||||
</SafeAreaView>
|
||||
<NoticeSection
|
||||
title="Proponowane ogłoszenia"
|
||||
notices={recomendedNotices}
|
||||
ctaLink="/notices"
|
||||
/>
|
||||
</ScrollView>
|
||||
{/* </View> */}
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user