fix login check and urls

This commit is contained in:
Patryk
2025-06-07 23:08:21 +02:00
parent 472dcfc96a
commit c19333ad8b
10 changed files with 424 additions and 374 deletions

View File

@@ -1,64 +1,70 @@
import {Tabs} from "expo-router";
import {Ionicons} from "@expo/vector-icons";
import { Tabs, Redirect } from "expo-router";
import { Ionicons } from "@expo/vector-icons";
import { useAuthStore } from "@/store/authStore";
export default function TabLayout() {
return (
<Tabs
screenOptions={{
tabBarActiveTintColor: "rgb(var(--color-primary-500))",
}}
>
<Tabs.Screen
name="index"
options={{
title: "Home",
tabBarLabel: "Home",
tabBarIcon: ({color, size}) => (
<Ionicons name="home-outline" size={size} color={color}/>
),
}}
/>
<Tabs.Screen
name="notices"
options={{
title: "Ogłoszenia",
tabBarLabel: "Ogłoszenia",
tabBarIcon: ({color, size}) => (
<Ionicons name="list-outline" size={size} color={color}/>
),
}}
/>
<Tabs.Screen
name="notice/create"
options={{
title: "Dodaj",
tabBarLabel: "Dodaj",
tabBarIcon: ({color, size}) => (
<Ionicons name="add-circle-outline" size={size} color={color}/>
),
}}
/>
<Tabs.Screen
name="wishlist"
options={{
title: "Ulubione",
tabBarLabel: "Ulubione",
tabBarIcon: ({color, size}) => (
<Ionicons name="heart-outline" size={size} color={color}/>
),
}}
/>
<Tabs.Screen
name="dashboard"
options={{
headerShown: false,
title: "Konto",
tabBarLabel: "Konto",
tabBarIcon: ({color, size}) => (
<Ionicons name="person-outline" size={size} color={color}/>
),
}}
/>
</Tabs>
);
const token = useAuthStore((state) => state.token);
if (!token) {
return <Redirect href="/login" />;
}
return (
<Tabs
screenOptions={{
tabBarActiveTintColor: "rgb(var(--color-primary-500))",
}}
>
<Tabs.Screen
name="index"
options={{
title: "Home",
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => (
<Ionicons name="home-outline" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="notices"
options={{
title: "Ogłoszenia",
tabBarLabel: "Ogłoszenia",
tabBarIcon: ({ color, size }) => (
<Ionicons name="list-outline" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="notice/create"
options={{
title: "Dodaj",
tabBarLabel: "Dodaj",
tabBarIcon: ({ color, size }) => (
<Ionicons name="add-circle-outline" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="wishlist"
options={{
title: "Ulubione",
tabBarLabel: "Ulubione",
tabBarIcon: ({ color, size }) => (
<Ionicons name="heart-outline" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="dashboard"
options={{
headerShown: false,
title: "Konto",
tabBarLabel: "Konto",
tabBarIcon: ({ color, size }) => (
<Ionicons name="person-outline" size={size} color={color} />
),
}}
/>
</Tabs>
);
}

View File

@@ -1,6 +1,15 @@
import { DrawerItem } from "@react-navigation/drawer";
import { Drawer } from "expo-router/drawer";
import { useAuthStore } from "@/store/authStore";
import {
DrawerContentScrollView,
DrawerItemList,
} from "@react-navigation/drawer";
export default function AccountDrawerLayout() {
const signOut = useAuthStore((state) => state.signOut);
return (
<Drawer
screenOptions={{
@@ -9,10 +18,19 @@ export default function AccountDrawerLayout() {
drawerActiveBackgroundColor: "#f0f0f0",
drawerItemStyle: {
borderRadius: 8,
// backgroundColor: "transparent",
},
headerTintColor: "#1c1c1e",
}}
drawerContent={(props) => (
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
label="Wyloguj"
onPress={signOut}
labelStyle={{ color: "red" }}
/>
</DrawerContentScrollView>
)}
>
<Drawer.Screen name="account" options={{ title: "Konto" }} />
<Drawer.Screen

View File

@@ -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>
);
}