Compare commits
24 Commits
53be0b2f50
...
authentica
| Author | SHA1 | Date | |
|---|---|---|---|
| d4133f28bd | |||
| b6f2225148 | |||
| 8dc51fafdf | |||
| 1862b6b79e | |||
| 9962dc1e55 | |||
| 00fbe8b655 | |||
| 532183b305 | |||
| a7cf31900b | |||
|
|
0295386dac | ||
|
|
6598faf5e8 | ||
| 47e5d80792 | |||
| 54db5eadf3 | |||
| 845a2e9593 | |||
| 1a8fe7bb1d | |||
| 50450ccd76 | |||
| 04778c4d78 | |||
| e197319d9b | |||
| 0a7be2e27b | |||
| 05916b959c | |||
| 37c273a746 | |||
| b8ca34f736 | |||
| 490bcc7585 | |||
| 657f307c30 | |||
| 580715947d |
0
ArtisanConnect/api/auth.jsx
Normal file
0
ArtisanConnect/api/auth.jsx
Normal file
12
ArtisanConnect/api/categories.jsx
Normal file
12
ArtisanConnect/api/categories.jsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||||
|
|
||||||
|
export async function listCategories() {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${API_URL}/vars/categories`);
|
||||||
|
return response.data;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,35 +1,122 @@
|
|||||||
const API_URL = "https://testowe.zikor.pl/api/v1/notices/";
|
import axios from "axios";
|
||||||
|
import FormData from 'form-data'
|
||||||
|
import {useAuthStore} from "@/store/authStore";
|
||||||
|
|
||||||
|
// const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||||
|
|
||||||
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||||
|
|
||||||
export async function listNotices() {
|
export async function listNotices() {
|
||||||
const response = await fetch(`${API_URL}get/all`);
|
const { token } = useAuthStore.getState();
|
||||||
const data = await response.json();
|
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Error");
|
const response = await fetch(`${API_URL}/notices/get/all`, {
|
||||||
}
|
headers: headers
|
||||||
return data;
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(response.toString());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getNoticeById(noticeId) {
|
export async function getNoticeById(noticeId) {
|
||||||
const response = await fetch(`${API_URL}get/${noticeId}`);
|
const response = await fetch(`${API_URL}/notices/get/${noticeId}`);
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Error");
|
throw new Error("Error");
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createNotice(notice) {
|
export async function createNotice(notice) {
|
||||||
// console.log("Notice created", notice);
|
try {
|
||||||
const response = await fetch(`${API_URL}add`, {
|
const response = await axios.post(`${API_URL}/notices/add`, notice, {
|
||||||
method: "POST",
|
headers: {
|
||||||
headers: {
|
"Content-Type": "application/json",
|
||||||
"Content-Type": "application/json",
|
},
|
||||||
},
|
});
|
||||||
body: JSON.stringify(notice),
|
|
||||||
});
|
if (response.data.noticeId !== null) {
|
||||||
console.log("Response", response);
|
for (const imageUri of notice.image) {
|
||||||
if (!response.ok) {
|
await uploadImage(response.data.noticeId, imageUri);
|
||||||
throw new Error("Error");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error", error.response.data, error.response.status);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getImageByNoticeId(noticeId) {
|
||||||
|
let imageUrl;
|
||||||
|
try {
|
||||||
|
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
|
||||||
|
|
||||||
|
const imageName = listResponse.data[0];
|
||||||
|
imageUrl = `${API_URL}/images/get/${imageName}`;
|
||||||
|
|
||||||
|
return imageUrl;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Zdjęcie nie istnieje dla notice o id: ${noticeId}`);
|
||||||
|
imageUrl = "https://http.cat/404.jpg";
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllImagesByNoticeId(noticeId) {
|
||||||
|
try {
|
||||||
|
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
|
||||||
|
|
||||||
|
if (listResponse.data && listResponse.data.length > 0) {
|
||||||
|
return listResponse.data.map(imageName =>
|
||||||
|
`${API_URL}/images/get/${imageName}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ["https://http.cat/404.jpg"];
|
||||||
|
} catch (err) {
|
||||||
|
if(err.response.status === 404) {
|
||||||
|
console.info(`Ogłoszenie o id: ${noticeId} nie posiada zdjęć.`);
|
||||||
|
return ["https://http.cat/404.jpg"];
|
||||||
|
}
|
||||||
|
console.warn(`Nie udało się pobrać listy zdjęć dla ogłoszenia o id: ${noticeId}`, err);
|
||||||
|
return ["https://http.cat/404.jpg"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const uploadImage = async (noticeId, imageUri) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
const filename = imageUri.split('/').pop();
|
||||||
|
|
||||||
|
const match = /\.(\w+)$/.exec(filename);
|
||||||
|
const type = match ? `image/${match[1]}` : 'image/jpeg';
|
||||||
|
|
||||||
|
formData.append('file', {
|
||||||
|
uri: imageUri,
|
||||||
|
name: filename,
|
||||||
|
type: type,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post(
|
||||||
|
`${API_URL}/images/upload/${noticeId}`,
|
||||||
|
formData,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.info('Upload successful:', response.data);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.log("imageURI:", imageUri);
|
||||||
|
console.error('Error uploading image:', error.response.data, error.response.status);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"expo": {
|
"expo": {
|
||||||
"name": "ArtisanConnect",
|
"name": "ArtisanConnect",
|
||||||
"slug": "ArtisanConnect",
|
"slug": "ArtisanConnect",
|
||||||
"scheme": "Artisanconnect",
|
"scheme": "com.hamx.artisanconnect",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"icon": "./assets/icon.png",
|
"icon": "./assets/icon.png",
|
||||||
@@ -14,19 +14,44 @@
|
|||||||
"backgroundColor": "#ffffff"
|
"backgroundColor": "#ffffff"
|
||||||
},
|
},
|
||||||
"ios": {
|
"ios": {
|
||||||
"supportsTablet": true
|
"supportsTablet": true,
|
||||||
|
"bundleIdentifier": "com.hamx.artisanconnect"
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
"adaptiveIcon": {
|
"adaptiveIcon": {
|
||||||
"foregroundImage": "./assets/adaptive-icon.png",
|
"foregroundImage": "./assets/adaptive-icon.png",
|
||||||
"backgroundColor": "#ffffff"
|
"backgroundColor": "#ffffff"
|
||||||
}
|
},
|
||||||
|
"permissions": [
|
||||||
|
"android.permission.RECORD_AUDIO",
|
||||||
|
"android.permission.CAMERA"
|
||||||
|
],
|
||||||
|
"package": "com.hamx.artisanconnect"
|
||||||
},
|
},
|
||||||
"web": {
|
"web": {
|
||||||
"favicon": "./assets/favicon.png"
|
"favicon": "./assets/favicon.png"
|
||||||
},
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"expo-router"
|
"expo-router",
|
||||||
]
|
[
|
||||||
|
"expo-image-picker",
|
||||||
|
{
|
||||||
|
"photosPermission": "The app accesses your photos to let you share them with your friends."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"expo-camera",
|
||||||
|
{
|
||||||
|
"cameraPermission": "Please allow $(PRODUCT_NAME) to access your camera"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"expo-web-browser"
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"router": {},
|
||||||
|
"eas": {
|
||||||
|
"projectId": "7a0d8bc8-938f-4d2a-babb-945faee13429"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +1,75 @@
|
|||||||
import { Tabs } from "expo-router";
|
import {Tabs} from "expo-router";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import {Ionicons} from "@expo/vector-icons";
|
||||||
|
|
||||||
export default function TabLayout() {
|
export default function TabLayout() {
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
tabBarActiveTintColor: "rgb(var(--color-primary-500))",
|
tabBarActiveTintColor: "rgb(var(--color-primary-500))",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="index"
|
name="index"
|
||||||
options={{
|
options={{
|
||||||
title: "Home",
|
title: "Home",
|
||||||
tabBarLabel: "Home",
|
tabBarLabel: "Home",
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({color, size}) => (
|
||||||
<Ionicons name="home-outline" size={size} color={color} />
|
<Ionicons name="home-outline" size={size} color={color}/>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="notices"
|
name="notices"
|
||||||
options={{
|
options={{
|
||||||
title: "Ogłoszenia",
|
title: "Ogłoszenia",
|
||||||
tabBarLabel: "Ogłoszenia",
|
tabBarLabel: "Ogłoszenia",
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({color, size}) => (
|
||||||
<Ionicons name="list-outline" size={size} color={color} />
|
<Ionicons name="list-outline" size={size} color={color}/>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="notice/create"
|
name="notice/create"
|
||||||
options={{
|
options={{
|
||||||
title: "Dodaj",
|
title: "Dodaj",
|
||||||
tabBarLabel: "Dodaj",
|
tabBarLabel: "Dodaj",
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({color, size}) => (
|
||||||
<Ionicons name="add-circle-outline" size={size} color={color} />
|
<Ionicons name="add-circle-outline" size={size} color={color}/>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="wishlist"
|
name="wishlist"
|
||||||
options={{
|
options={{
|
||||||
title: "Ulubione",
|
title: "Ulubione",
|
||||||
tabBarLabel: "Ulubione",
|
tabBarLabel: "Ulubione",
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarIcon: ({color, size}) => (
|
||||||
<Ionicons name="heart-outline" size={size} color={color} />
|
<Ionicons name="heart-outline" size={size} color={color}/>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="account"
|
name="login"
|
||||||
options={{
|
options={{
|
||||||
title: "Konto",
|
headerShown: false, // Ukryj nagłówek dla Drawer
|
||||||
tabBarLabel: "Konto",
|
title: "Authentication",
|
||||||
tabBarIcon: ({ color, size }) => (
|
tabBarLabel: "Authentication",
|
||||||
<Ionicons name="person-outline" size={size} color={color} />
|
tabBarIcon: ({color, size}) => (
|
||||||
),
|
<Ionicons name="key" size={size} color={color}/>
|
||||||
}}
|
),
|
||||||
/>
|
}}
|
||||||
</Tabs>
|
/>
|
||||||
);
|
<Tabs.Screen
|
||||||
|
name="dashboard"
|
||||||
|
options={{
|
||||||
|
headerShown: false, // Ukryj nagłówek dla Drawer
|
||||||
|
title: "Konto",
|
||||||
|
tabBarLabel: "Konto",
|
||||||
|
tabBarIcon: ({color, size}) => (
|
||||||
|
<Ionicons name="person-outline" size={size} color={color}/>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Tabs>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
24
ArtisanConnect/app/(tabs)/dashboard/_layout.jsx
Normal file
24
ArtisanConnect/app/(tabs)/dashboard/_layout.jsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Drawer } from "expo-router/drawer";
|
||||||
|
|
||||||
|
export default function AccountDrawerLayout() {
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
screenOptions={{
|
||||||
|
drawerActiveTintColor: "#1c1c1e",
|
||||||
|
drawerInactiveTintColor: "#8e8e8f",
|
||||||
|
drawerActiveBackgroundColor: "#f0f0f0",
|
||||||
|
drawerItemStyle: {
|
||||||
|
borderRadius: 8,
|
||||||
|
// backgroundColor: "transparent",
|
||||||
|
},
|
||||||
|
headerTintColor: "#1c1c1e",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Drawer.Screen name="account" options={{ title: "Konto" }} />
|
||||||
|
<Drawer.Screen
|
||||||
|
name="userNotices"
|
||||||
|
options={{ title: "Moje ogłoszenia" }}
|
||||||
|
/>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
}
|
||||||
4
ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx
Normal file
4
ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { Text } from "@/components/ui/text";
|
||||||
|
export default function UserNotices() {
|
||||||
|
return <Text>Użytkownik</Text>;
|
||||||
|
}
|
||||||
180
ArtisanConnect/app/(tabs)/login.jsx
Normal file
180
ArtisanConnect/app/(tabs)/login.jsx
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import React, {useEffect, useState} from 'react';
|
||||||
|
import {StyleSheet, ActivityIndicator, SafeAreaView, View, Platform} from 'react-native';
|
||||||
|
import {useAuthStore} from '@/store/authStore';
|
||||||
|
import {useRouter, Link} from 'expo-router';
|
||||||
|
|
||||||
|
import {Box} from "@/components/ui/box"
|
||||||
|
import {Button, ButtonText, ButtonIcon} from "@/components/ui/button"
|
||||||
|
import {Center} from "@/components/ui/center"
|
||||||
|
import {Heading} from "@/components/ui/heading"
|
||||||
|
import {Input, InputField} from "@/components/ui/input"
|
||||||
|
import {Text} from "@/components/ui/text"
|
||||||
|
import {VStack} from "@/components/ui/vstack"
|
||||||
|
import {HStack} from "@/components/ui/hstack"
|
||||||
|
import {ArrowRightIcon} from "@/components/ui/icon"
|
||||||
|
import {Divider} from '@/components/ui/divider';
|
||||||
|
import {Ionicons} from "@expo/vector-icons";
|
||||||
|
|
||||||
|
import * as WebBrowser from 'expo-web-browser';
|
||||||
|
import * as Google from "expo-auth-session/providers/google";
|
||||||
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
import {makeRedirectUri} from "expo-auth-session";
|
||||||
|
|
||||||
|
import Constants from 'expo-constants';
|
||||||
|
|
||||||
|
WebBrowser.maybeCompleteAuthSession();
|
||||||
|
|
||||||
|
// client_id ios 936418008320-ohefdfcebd41f6oa2o8phh1mgj9s49sl.apps.googleusercontent.com
|
||||||
|
// android 936418008320-d8dfjph5e4r28fcm1rbdfbh5phmbg03d.apps.googleusercontent.com
|
||||||
|
|
||||||
|
export default function Login() {
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const {signIn, isLoading, signInWithGoogle} = useAuthStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const [request, response, promptAsync] = Google.useAuthRequest({
|
||||||
|
androidClientId: "936418008320-d8dfjph5e4r28fcm1rbdfbh5phmbg03d.apps.googleusercontent.com",
|
||||||
|
iosClientId: "936418008320-ohefdfcebd41f6oa2o8phh1mgj9s49sl.apps.googleusercontent.com",
|
||||||
|
webClientId: "936418008320-btdngtlfnjac1p67guje72m9el5q59a7.apps.googleusercontent.com",
|
||||||
|
redirectUri:
|
||||||
|
Platform.OS === 'android'
|
||||||
|
? makeRedirectUri({
|
||||||
|
scheme: Constants.expoConfig.android.package,
|
||||||
|
path: '/',
|
||||||
|
})
|
||||||
|
: undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleInternalLogin = async () => {
|
||||||
|
if (!email || !password) {
|
||||||
|
alert('Proszę wprowadzić email i hasło.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await signIn(email, password);
|
||||||
|
alert(`Zalogowano jako ${email}`);
|
||||||
|
router.replace('/');
|
||||||
|
} catch (e) {
|
||||||
|
alert("Błąd logowania: " + (e.response?.data?.message || e.message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
handleGoogleLogin();
|
||||||
|
}, [response]);
|
||||||
|
|
||||||
|
const handleGoogleLogin = async () => {
|
||||||
|
// const user = await AsyncStorage.getItem("@user");
|
||||||
|
let user = null;
|
||||||
|
if (!user) {
|
||||||
|
if(response.type === "success") {
|
||||||
|
user = await getUserInfo(response.authentication.accessToken)
|
||||||
|
await signInWithGoogle(response.authentication.accessToken);
|
||||||
|
alert(`Zalogowano jako ${user.email}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.info("Pobrano użytkownika z AsyncStorage:", JSON.parse(user));
|
||||||
|
alert(`Zalogowano jako ${user.email}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getUserInfo = async (token) => {
|
||||||
|
if(!token) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch("https://www.googleapis.com/userinfo/v2/me",
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const user = await response.json();
|
||||||
|
await AsyncStorage.setItem("@user", JSON.stringify(user));
|
||||||
|
return user;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Błąd podczas pobierania informacji o użytkowniku:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<ActivityIndicator size="large"/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SafeAreaView style={styles.container}>
|
||||||
|
<Center>
|
||||||
|
<Box className="p-5 max-w-96 border border-background-300 rounded-lg">
|
||||||
|
<VStack className="pb-4" space="xs">
|
||||||
|
<Heading className="leading-[30px]">Logowanie</Heading>
|
||||||
|
<Box className="flex flex-row">
|
||||||
|
<Link href="/registration" asChild>
|
||||||
|
<Button variant="link" size="sm" className="p-0">
|
||||||
|
<ButtonText style={styles.signupbutton}>Nie masz jeszcze konta? Załóz je
|
||||||
|
tutaj!</ButtonText>
|
||||||
|
<ButtonIcon className="mr-1" size="md" as={ArrowRightIcon}/>
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</Box>
|
||||||
|
</VStack>
|
||||||
|
<VStack space="xl" className="py-2">
|
||||||
|
<Input>
|
||||||
|
<InputField className="py-2" placeholder="Login" onChangeText={setEmail}/>
|
||||||
|
</Input>
|
||||||
|
<Input>
|
||||||
|
<InputField type="password" className="py-2" placeholder="Hasło"
|
||||||
|
onChangeText={setPassword}/>
|
||||||
|
</Input>
|
||||||
|
</VStack>
|
||||||
|
<VStack space="lg" className="pt-4">
|
||||||
|
<Button size="sm" onPress={handleInternalLogin}>
|
||||||
|
<ButtonText>Zaloguj się</ButtonText>
|
||||||
|
</Button>
|
||||||
|
</VStack>
|
||||||
|
|
||||||
|
<HStack alignItems="center" space="sm" className="pt-6 pb-6">
|
||||||
|
<Divider flex={1}/>
|
||||||
|
<Text fontSize="$sm" className="text-gray-300">
|
||||||
|
lub
|
||||||
|
</Text>
|
||||||
|
<Divider flex={1}/>
|
||||||
|
</HStack>
|
||||||
|
<Button size="sm" onPress={() => promptAsync()}>
|
||||||
|
<Ionicons name="logo-google" color="#fff"/>
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Center>
|
||||||
|
</SafeAreaView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: 20,
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: '#ddd',
|
||||||
|
borderRadius: 5,
|
||||||
|
marginBottom: 15,
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
|
errorText: {
|
||||||
|
color: 'red',
|
||||||
|
marginBottom: 10,
|
||||||
|
},
|
||||||
|
signupbutton: {
|
||||||
|
fontWeight: '300',
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,142 +1,256 @@
|
|||||||
import { useState } from "react";
|
import {useState, useEffect} from "react";
|
||||||
import { Button, ButtonText } from "@/components/ui/button";
|
import {Image, StyleSheet} from "react-native";
|
||||||
import { FormControl } from "@/components/ui/form-control";
|
import {Button, ButtonText} from "@/components/ui/button";
|
||||||
import { Input, InputField } from "@/components/ui/input";
|
import {FormControl} from "@/components/ui/form-control";
|
||||||
import { Text } from "@/components/ui/text";
|
import {Input, InputField} from "@/components/ui/input";
|
||||||
import { VStack } from "@/components/ui/vstack";
|
import {Text} from "@/components/ui/text";
|
||||||
import { Textarea, TextareaInput } from "@/components/ui/textarea";
|
import {VStack} from "@/components/ui/vstack";
|
||||||
|
import {Textarea, TextareaInput} from "@/components/ui/textarea";
|
||||||
|
import {ScrollView} from '@gluestack-ui/themed';
|
||||||
|
import * as ImagePicker from 'expo-image-picker';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectInput,
|
SelectInput,
|
||||||
SelectIcon,
|
SelectIcon,
|
||||||
SelectPortal,
|
SelectPortal,
|
||||||
SelectBackdrop,
|
SelectBackdrop,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
SelectDragIndicator,
|
SelectItem,
|
||||||
SelectDragIndicatorWrapper,
|
SelectScrollView,
|
||||||
SelectItem,
|
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
|
|
||||||
import { ChevronDownIcon } from "@/components/ui/icon";
|
import {ChevronDownIcon} from "@/components/ui/icon";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import {useNoticesStore} from "@/store/noticesStore";
|
||||||
import { createNotice } from "@/api/notices";
|
import {listCategories} from "@/api/categories";
|
||||||
|
import {useRouter} from "expo-router";
|
||||||
|
|
||||||
export default function CreateNotice() {
|
export default function CreateNotice() {
|
||||||
const [title, setTitle] = useState("");
|
const router = useRouter();
|
||||||
const [description, setDescription] = useState("");
|
const {addNotice, fetchNotices} = useNoticesStore();
|
||||||
const [price, setPrice] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [category, setCategory] = useState("");
|
const [description, setDescription] = useState("");
|
||||||
const [error, setError] = useState({
|
const [price, setPrice] = useState("");
|
||||||
title: false,
|
const [category, setCategory] = useState("");
|
||||||
description: false,
|
const [image, setImage] = useState([]);
|
||||||
price: false,
|
const [selectItems, setSelectItems] = useState([]);
|
||||||
category: false,
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
});
|
|
||||||
|
|
||||||
const noticeMutation = useMutation({
|
useEffect(() => {
|
||||||
mutationFn: () =>
|
let isMounted = true;
|
||||||
createNotice({
|
|
||||||
title: title,
|
|
||||||
clientId: 1,
|
|
||||||
description: description,
|
|
||||||
price: parseFloat(price),
|
|
||||||
category: category,
|
|
||||||
status: "ACTIVE",
|
|
||||||
}),
|
|
||||||
onSuccess: () => {
|
|
||||||
console.log("Notice created successfully");
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
console.error("Error creating notice");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const addNotice = () => {
|
const fetchSelectItems = async () => {
|
||||||
setError({
|
try {
|
||||||
title: !title,
|
let data = await listCategories();
|
||||||
description: !description,
|
if (isMounted && Array.isArray(data)) {
|
||||||
price: !price,
|
setSelectItems(data);
|
||||||
category: !category,
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching select items:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchSelectItems();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const [error, setError] = useState({
|
||||||
|
title: false,
|
||||||
|
description: false,
|
||||||
|
price: false,
|
||||||
|
category: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!title || !description || !price || !category) {
|
const styles = StyleSheet.create({
|
||||||
console.log("Error in form");
|
container: {
|
||||||
return;
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleAddNotice = async () => {
|
||||||
|
setError({
|
||||||
|
title: !title,
|
||||||
|
description: !description,
|
||||||
|
price: !price,
|
||||||
|
category: !category,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!title || !description || !price || !category) {
|
||||||
|
console.log("Error in form");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const result = await addNotice({
|
||||||
|
title: title,
|
||||||
|
clientId: 1,
|
||||||
|
description: description,
|
||||||
|
price: price,
|
||||||
|
category: category,
|
||||||
|
status: "ACTIVE",
|
||||||
|
image: image
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
console.log("Notice created successfully with ID: ", result.noticeId);
|
||||||
|
await fetchNotices();
|
||||||
|
clearForm();
|
||||||
|
router.push("/(tabs)/notices");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error creating notice. Error message: ", error.message);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const takePicture = async () => {
|
||||||
|
const {status} = await ImagePicker.requestCameraPermissionsAsync();
|
||||||
|
if (status !== 'granted') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await ImagePicker.launchCameraAsync({
|
||||||
|
allowsEditing: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.canceled && result.assets) {
|
||||||
|
setImage(result.assets.map(asset => asset.uri));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
noticeMutation.mutate();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
const pickImage = async () => {
|
||||||
<FormControl className="p-4 border rounded-lg border-outline-300">
|
let result = await ImagePicker.launchImageLibraryAsync({
|
||||||
<VStack space="xl">
|
mediaTypes: 'images',
|
||||||
<VStack space="xs">
|
selectionLimit: 8,
|
||||||
<Text className="text-typography-500">Tytuł</Text>
|
allowsEditing: false,
|
||||||
<Input className="min-w-[250px]" isInvalid={error.title}>
|
allowsMultipleSelection: true,
|
||||||
<InputField
|
aspect: [4, 3],
|
||||||
type="text"
|
quality: 0.5,
|
||||||
value={title}
|
});
|
||||||
onChangeText={(value) => setTitle(value)}
|
|
||||||
/>
|
|
||||||
</Input>
|
|
||||||
</VStack>
|
|
||||||
|
|
||||||
<VStack space="xs">
|
if (!result.canceled) {
|
||||||
<Text className="text-typography-500">Opis</Text>
|
setImage(result.assets.map(asset => asset.uri));
|
||||||
<Textarea
|
}
|
||||||
size="md"
|
};
|
||||||
className="min-w-[250px] "
|
|
||||||
isInvalid={error.description}
|
|
||||||
>
|
|
||||||
<TextareaInput
|
|
||||||
placeholder="Opisz produkt"
|
|
||||||
value={description}
|
|
||||||
onChangeText={(value) => setDescription(value)}
|
|
||||||
/>
|
|
||||||
</Textarea>
|
|
||||||
</VStack>
|
|
||||||
|
|
||||||
<VStack space="xs">
|
const clearForm = () => {
|
||||||
<Text className="text-typography-500">Cena</Text>
|
setTitle("");
|
||||||
<Input className="min-w-[250px]" isInvalid={error.price}>
|
setDescription("");
|
||||||
<InputField
|
setPrice("");
|
||||||
type="text"
|
setCategory("");
|
||||||
value={price}
|
setImage([]);
|
||||||
onChangeText={(value) => setPrice(value)}
|
setError({
|
||||||
/>
|
title: false,
|
||||||
</Input>
|
description: false,
|
||||||
</VStack>
|
price: false,
|
||||||
<VStack space="xs">
|
category: false,
|
||||||
<Text className="text-typography-500">Kategoria</Text>
|
})
|
||||||
<Select
|
}
|
||||||
onValueChange={(value) => setCategory(value)}
|
|
||||||
isInvalid={error.category}
|
return (
|
||||||
>
|
<ScrollView h="$80" w="$80">
|
||||||
<SelectTrigger variant="outline" size="md">
|
<FormControl className="p-4 border rounded-lg border-outline-300">
|
||||||
<SelectInput placeholder="Wybierz kategorię" />
|
<VStack space="xl">
|
||||||
<SelectIcon className="mr-3" as={ChevronDownIcon} />
|
<VStack space="md">
|
||||||
</SelectTrigger>
|
<Text className="text-typography-500">Zdjęcia</Text>
|
||||||
<SelectPortal>
|
<Button onPress={pickImage}>
|
||||||
<SelectBackdrop />
|
<ButtonText>
|
||||||
<SelectContent>
|
Wybierz zdjęcia
|
||||||
<SelectDragIndicatorWrapper>
|
</ButtonText>
|
||||||
<SelectDragIndicator />
|
</Button>
|
||||||
</SelectDragIndicatorWrapper>
|
<Button onPress={takePicture}>
|
||||||
<SelectItem label="Meble" value="Furniture" />
|
<ButtonText>Zrób zdjęcie</ButtonText>
|
||||||
<SelectItem label="Biżuteria" value="Jewelry" />
|
</Button>
|
||||||
<SelectItem label="Ceramika" value="Ceramics" />
|
<Text size="sm"
|
||||||
</SelectContent>
|
bold="true"
|
||||||
</SelectPortal>
|
>
|
||||||
</Select>
|
Pierwsze zdjęcie będzie zdjęciem głównym</Text>
|
||||||
</VStack>
|
{image && image.length > 0 && (
|
||||||
<Button
|
<VStack space="xs" className="flex-row flex-wrap">
|
||||||
className="ml-auto"
|
{image.map((img, index) => (
|
||||||
onPress={() => addNotice()}
|
<Image key={index} source={{uri: img}} style={styles.image} className="m-1"/>
|
||||||
disabled={noticeMutation.isLoading}
|
))}
|
||||||
>
|
</VStack>
|
||||||
<ButtonText className="text-typography-0">Save</ButtonText>
|
)}
|
||||||
</Button>
|
</VStack>
|
||||||
</VStack>
|
|
||||||
</FormControl>
|
<VStack space="xs">
|
||||||
);
|
<Text className="text-typography-500">Tytuł</Text>
|
||||||
}
|
<Input className="min-w-[250px]" isInvalid={error.title}>
|
||||||
|
<InputField
|
||||||
|
type="text"
|
||||||
|
value={title}
|
||||||
|
onChangeText={(value) => setTitle(value)}
|
||||||
|
/>
|
||||||
|
</Input>
|
||||||
|
</VStack>
|
||||||
|
|
||||||
|
<VStack space="xs">
|
||||||
|
<Text className="text-typography-500">Opis</Text>
|
||||||
|
<Textarea
|
||||||
|
size="md"
|
||||||
|
className="min-w-[250px] "
|
||||||
|
isInvalid={error.description}
|
||||||
|
>
|
||||||
|
<TextareaInput
|
||||||
|
placeholder="Opisz produkt"
|
||||||
|
value={description}
|
||||||
|
onChangeText={(value) => setDescription(value)}
|
||||||
|
/>
|
||||||
|
</Textarea>
|
||||||
|
</VStack>
|
||||||
|
|
||||||
|
<VStack space="xs">
|
||||||
|
<Text className="text-typography-500">Cena</Text>
|
||||||
|
<Input className="min-w-[250px]" isInvalid={error.price}>
|
||||||
|
<InputField
|
||||||
|
type="text"
|
||||||
|
value={price}
|
||||||
|
onChangeText={(value) => setPrice(value)}
|
||||||
|
/>
|
||||||
|
</Input>
|
||||||
|
</VStack>
|
||||||
|
<VStack space="xs">
|
||||||
|
<Text className="text-typography-500">Kategoria</Text>
|
||||||
|
<Select
|
||||||
|
onValueChange={(value) => setCategory(value)}
|
||||||
|
isInvalid={error.category}
|
||||||
|
>
|
||||||
|
<SelectTrigger variant="outline" size="md">
|
||||||
|
<SelectInput placeholder="Wybierz kategorię"/>
|
||||||
|
<SelectIcon className="mr-3" as={ChevronDownIcon}/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectPortal>
|
||||||
|
<SelectBackdrop/>
|
||||||
|
<SelectContent style={{maxHeight: 400}}>
|
||||||
|
<SelectScrollView>
|
||||||
|
{selectItems.map((item) => (
|
||||||
|
<SelectItem key={item.value} label={item.label} value={item.value}/>
|
||||||
|
))}
|
||||||
|
</SelectScrollView>
|
||||||
|
</SelectContent>
|
||||||
|
</SelectPortal>
|
||||||
|
</Select>
|
||||||
|
</VStack>
|
||||||
|
<Button
|
||||||
|
className="mt-5 w-full"
|
||||||
|
onPress={handleAddNotice}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<ButtonText className="text-typography-0">Dodaj</ButtonText>
|
||||||
|
</Button>
|
||||||
|
</VStack>
|
||||||
|
</FormControl>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,30 +1,65 @@
|
|||||||
import { FlatList, Text, ActivityIndicator } from "react-native";
|
import {FlatList, Text, ActivityIndicator, RefreshControl} from "react-native";
|
||||||
import { listNotices } from "@/api/notices";
|
import {useState, useEffect} from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import {useNoticesStore} from "@/store/noticesStore";
|
||||||
import { NoticeCard } from "@/components/NoticeCard";
|
import {NoticeCard} from "@/components/NoticeCard";
|
||||||
|
|
||||||
export default function Notices() {
|
export default function Notices() {
|
||||||
const { data, isLoading, error } = useQuery({
|
const {notices, fetchNotices} = useNoticesStore();
|
||||||
queryKey: ["notices"],
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
queryFn: listNotices,
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
});
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
if (isLoading) {
|
useEffect(() => {
|
||||||
return <ActivityIndicator />;
|
loadData();
|
||||||
}
|
}, []);
|
||||||
|
|
||||||
if (error) {
|
const loadData = async () => {
|
||||||
return <Text>Błąd, spróbuj ponownie póżniej</Text>;
|
setIsLoading(true);
|
||||||
}
|
try {
|
||||||
|
await fetchNotices();
|
||||||
|
setError(null);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
const onRefresh = async () => {
|
||||||
<FlatList
|
setRefreshing(true);
|
||||||
key={2}
|
try {
|
||||||
data={data}
|
await fetchNotices();
|
||||||
numColumns={2}
|
} catch (err) {
|
||||||
columnContainerClassName="m-2"
|
setError(err);
|
||||||
columnWrapperClassName="gap-2 m-2"
|
} finally {
|
||||||
renderItem={({ item }) => <NoticeCard notice={item} />}
|
setRefreshing(false);
|
||||||
/>
|
}
|
||||||
);
|
};
|
||||||
}
|
|
||||||
|
if (isLoading && !refreshing) {
|
||||||
|
return <ActivityIndicator/>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <Text>Nie udało sie pobrać listy. {error.message}</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlatList
|
||||||
|
key={2}
|
||||||
|
data={notices}
|
||||||
|
numColumns={2}
|
||||||
|
columnContainerClassName="m-2"
|
||||||
|
columnWrapperClassName="gap-2 m-2"
|
||||||
|
renderItem={({item}) => <NoticeCard notice={item}/>}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={refreshing}
|
||||||
|
onRefresh={onRefresh}
|
||||||
|
colors={["#3b82f6"]}
|
||||||
|
tintColor="#3b82f6"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Tabs, Stack } from "expo-router";
|
import { Stack } from "expo-router";
|
||||||
import "@/global.css";
|
import "@/global.css";
|
||||||
import { GluestackUIProvider } from "@/components/ui/gluestack-ui-provider";
|
import { GluestackUIProvider } from "@/components/ui/gluestack-ui-provider";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
|||||||
@@ -1,67 +1,133 @@
|
|||||||
import { Stack, useLocalSearchParams } from "expo-router";
|
import {Stack, useLocalSearchParams} from "expo-router";
|
||||||
import { Box } from "@/components/ui/box";
|
import {Box} from "@/components/ui/box";
|
||||||
import { Button, ButtonText } from "@/components/ui/button";
|
import {Card} from "@/components/ui/card";
|
||||||
import { Card } from "@/components/ui/card";
|
import {Heading} from "@/components/ui/heading";
|
||||||
import { Heading } from "@/components/ui/heading";
|
import {Image} from "@/components/ui/image";
|
||||||
import { Image } from "@/components/ui/image";
|
import {Text} from "@/components/ui/text";
|
||||||
import { Text } from "@/components/ui/text";
|
import {VStack} from "@/components/ui/vstack";
|
||||||
import { VStack } from "@/components/ui/vstack";
|
import {Ionicons} from "@expo/vector-icons";
|
||||||
import { Icon, FavouriteIcon } from "@/components/ui/icon";
|
import {ActivityIndicator} from "react-native";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import {useEffect, useState} from "react";
|
||||||
import { getNoticeById } from "@/api/notices";
|
import {useNoticesStore} from "@/store/noticesStore";
|
||||||
import { ActivityIndicator } from "react-native";
|
import {useWishlist} from "@/store/wishlistStore";
|
||||||
|
import {Pressable} from "react-native";
|
||||||
|
|
||||||
export default function NoticeDetails() {
|
export default function NoticeDetails() {
|
||||||
const { id } = useLocalSearchParams();
|
const {id} = useLocalSearchParams();
|
||||||
|
const [image, setImage] = useState(null);
|
||||||
|
const [isImageLoading, setIsImageLoading] = useState(true);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const [notice, setNotice] = useState(null);
|
||||||
|
|
||||||
const {
|
const {getNoticeById, getAllImagesByNoticeId} = useNoticesStore();
|
||||||
data: notice,
|
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||||
isLoading,
|
const removeNoticeFromWishlist = useWishlist((state) => state.removeNoticeFromWishlist);
|
||||||
error,
|
const isInWishlist = useWishlist((state) =>
|
||||||
} = useQuery({
|
notice ? state.wishlistNotices.some((item) => item.noticeId === notice.noticeId) : false
|
||||||
queryKey: ["notices", id],
|
);
|
||||||
queryFn: () => getNoticeById(Number(id)),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isLoading) {
|
useEffect(() => {
|
||||||
return <ActivityIndicator />;
|
const fetchNotice = async () => {
|
||||||
}
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const noticeData = getNoticeById(Number(id));
|
||||||
|
if (noticeData) {
|
||||||
|
setNotice(noticeData);
|
||||||
|
setError(null);
|
||||||
|
} else {
|
||||||
|
setError(new Error(`Notice with ID ${id} not found.`));
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (error) {
|
fetchNotice();
|
||||||
return <Text>Błąd, spróbuj ponownie póżniej</Text>;
|
}, [id]);
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
useEffect(() => {
|
||||||
<Card className="p-0 rounded-lg m-3 flex-1">
|
const fetchImage = async () => {
|
||||||
<Stack.Screen
|
setIsImageLoading(true);
|
||||||
options={{
|
if (notice) {
|
||||||
title: notice.title,
|
try {
|
||||||
}}
|
const images = await getAllImagesByNoticeId(notice.noticeId);
|
||||||
/>
|
setImage(images && images.length > 0 ? images[0] : "https://http.cat/404.jpg");
|
||||||
<Image
|
} catch (err) {
|
||||||
source={{
|
console.error("Error while loading images:", err);
|
||||||
uri: "https://gluestack.github.io/public-blog-video-assets/saree.png",
|
setImage("https://http.cat/404.jpg");
|
||||||
}}
|
} finally {
|
||||||
className=" h-auto w-full rounded-md aspect-[1/1]"
|
setIsImageLoading(false);
|
||||||
alt="image"
|
}
|
||||||
resizeMode="cover"
|
}
|
||||||
/>
|
};
|
||||||
|
|
||||||
<VStack className="p-2">
|
if (notice) {
|
||||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
fetchImage();
|
||||||
{notice.title}
|
}
|
||||||
</Text>
|
}, [notice]);
|
||||||
<Box className="flex-row items-center">
|
|
||||||
<Heading size="md" className="flex-1">
|
if (isLoading) {
|
||||||
{notice.price}zł
|
return <ActivityIndicator/>;
|
||||||
</Heading>
|
}
|
||||||
<Icon
|
|
||||||
as={FavouriteIcon}
|
if (error) {
|
||||||
size="sm"
|
return <Text>Błąd, spróbuj ponownie póżniej: {error.message}</Text>;
|
||||||
className="text-primary-500 w-6 h-6"
|
}
|
||||||
/>
|
|
||||||
</Box>
|
if (!notice) {
|
||||||
</VStack>
|
return <Text>Nie znaleziono ogłoszenia</Text>;
|
||||||
</Card>
|
}
|
||||||
);
|
|
||||||
}
|
return (
|
||||||
|
<Card className="p-0 rounded-lg m-3 flex-1">
|
||||||
|
<Stack.Screen
|
||||||
|
options={{
|
||||||
|
title: notice.title,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{isImageLoading ? (
|
||||||
|
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
|
||||||
|
<ActivityIndicator size="large" color="#3b82f6" />
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
source={{
|
||||||
|
uri: image,
|
||||||
|
}}
|
||||||
|
className="h-auto w-full rounded-md aspect-[1/1]"
|
||||||
|
alt="image"
|
||||||
|
resizeMode="cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<VStack className="p-2">
|
||||||
|
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||||
|
{notice.title}
|
||||||
|
</Text>
|
||||||
|
<Box className="flex-row items-center">
|
||||||
|
<Heading size="md" className="flex-1">
|
||||||
|
{notice.price}zł
|
||||||
|
</Heading>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => {
|
||||||
|
if (isInWishlist) {
|
||||||
|
removeNoticeFromWishlist(notice.noticeId);
|
||||||
|
} else {
|
||||||
|
addNoticeToWishlist(notice);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name={isInWishlist ? "heart" : "heart-outline"}
|
||||||
|
size={24}
|
||||||
|
color={"primary-heading-500"}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
</Box>
|
||||||
|
</VStack>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
96
ArtisanConnect/app/registration.jsx
Normal file
96
ArtisanConnect/app/registration.jsx
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import React, {useState} from 'react';
|
||||||
|
import {StyleSheet, ActivityIndicator, SafeAreaView, View} from 'react-native';
|
||||||
|
import {useAuthStore} from '@/store/authStore';
|
||||||
|
import {useRouter} from 'expo-router';
|
||||||
|
|
||||||
|
import {Box} from "@/components/ui/box"
|
||||||
|
import {Button, ButtonText} from "@/components/ui/button"
|
||||||
|
import {Center} from "@/components/ui/center"
|
||||||
|
import {Heading} from "@/components/ui/heading"
|
||||||
|
import {Input, InputField} from "@/components/ui/input"
|
||||||
|
import {VStack} from "@/components/ui/vstack"
|
||||||
|
|
||||||
|
export default function Registration() {
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [firstName, setFirstName] = useState('');
|
||||||
|
const [lastName, setLastName] = useState('');
|
||||||
|
const {signUp, isLoading} = useAuthStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleInternalRegistration = async () => {
|
||||||
|
if (!email || !password || !firstName || !lastName) {
|
||||||
|
alert('Proszę uzupełnić wszystkie pola');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await signUp({email, password, firstName, lastName});
|
||||||
|
alert(`Zalogowano jako ${email}`);
|
||||||
|
router.replace('/');
|
||||||
|
} catch (e) {
|
||||||
|
alert("Błąd logowania: " + (e.response?.data?.message || e.message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<ActivityIndicator size="large"/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SafeAreaView style={styles.container}>
|
||||||
|
<Center>
|
||||||
|
<Box className="p-5 w-[80%] border border-background-300 rounded-lg">
|
||||||
|
<VStack className="pb-4" space="xs">
|
||||||
|
<Heading className="leading-[30px]">Rejestracja</Heading>
|
||||||
|
</VStack>
|
||||||
|
<VStack space="xl" className="py-2">
|
||||||
|
<Input>
|
||||||
|
<InputField type="email" className="py-2" placeholder="E-mail" onChangeText={setEmail}/>
|
||||||
|
</Input>
|
||||||
|
<Input>
|
||||||
|
<InputField className="py-2" placeholder="Imię" onChangeText={setFirstName}/>
|
||||||
|
</Input>
|
||||||
|
<Input>
|
||||||
|
<InputField className="py-2" placeholder="Nazwisko" onChangeText={setLastName}/>
|
||||||
|
</Input>
|
||||||
|
<Input>
|
||||||
|
<InputField type="password" className="py-2" placeholder="Hasło"
|
||||||
|
onChangeText={setPassword}/>
|
||||||
|
</Input>
|
||||||
|
</VStack>
|
||||||
|
<VStack space="lg" className="pt-4">
|
||||||
|
<Button size="sm" onPress={handleInternalRegistration}>
|
||||||
|
<ButtonText>Zarejestruj się</ButtonText>
|
||||||
|
</Button>
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
</Center>
|
||||||
|
</SafeAreaView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
formContainer: {
|
||||||
|
width: '80%',
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: '#ddd',
|
||||||
|
borderRadius: 5,
|
||||||
|
marginBottom: 15,
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
|
errorText: {
|
||||||
|
color: 'red',
|
||||||
|
marginBottom: 10,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,62 +1,116 @@
|
|||||||
import { Box } from "@/components/ui/box";
|
import {Box} from "@/components/ui/box";
|
||||||
import { Card } from "@/components/ui/card";
|
import {Card} from "@/components/ui/card";
|
||||||
import { Heading } from "@/components/ui/heading";
|
import {Heading} from "@/components/ui/heading";
|
||||||
import { Image } from "@/components/ui/image";
|
import {Image} from "@/components/ui/image";
|
||||||
import { Text } from "@/components/ui/text";
|
import {Text} from "@/components/ui/text";
|
||||||
import { VStack } from "@/components/ui/vstack";
|
import {VStack} from "@/components/ui/vstack";
|
||||||
import { Link } from "expo-router";
|
import {Link} from "expo-router";
|
||||||
import { Pressable } from "react-native";
|
import {Pressable, ActivityIndicator, View} from "react-native";
|
||||||
import { useWishlist } from "@/store/wishlistStore";
|
import {useWishlist} from "@/store/wishlistStore";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import {useNoticesStore} from "@/store/noticesStore";
|
||||||
|
import {Ionicons} from "@expo/vector-icons";
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
export function NoticeCard({ notice }) {
|
export function NoticeCard({notice}) {
|
||||||
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
const noticeId = notice?.noticeId;
|
||||||
const removeNoticeFromWishlist = useWishlist(
|
|
||||||
(state) => state.removeNoticeFromWishlist
|
|
||||||
);
|
|
||||||
const isInWishlist = useWishlist((state) =>
|
|
||||||
state.wishlistNotices.some((item) => item.noticeId == notice.noticeId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||||
<Link href={`/notice/${notice.noticeId}`} asChild>
|
const removeNoticeFromWishlist = useWishlist((state) => state.removeNoticeFromWishlist);
|
||||||
<Pressable className="flex-1">
|
const isInWishlist = useWishlist((state) =>
|
||||||
<Card className="p-0 rounded-lg max-w-[460px] flex-1">
|
noticeId ? state.wishlistNotices.some((item) => item.noticeId === noticeId) : false
|
||||||
<Image
|
);
|
||||||
source={{
|
|
||||||
uri: "https://gluestack.github.io/public-blog-video-assets/saree.png",
|
const [image, setImage] = useState(null);
|
||||||
}}
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
className=" h-auto w-full rounded-md aspect-[1/1]"
|
|
||||||
alt="image"
|
const {getAllImagesByNoticeId} = useNoticesStore();
|
||||||
resizeMode="cover"
|
|
||||||
/>
|
useEffect(() => {
|
||||||
<VStack className="p-2">
|
let isMounted = true;
|
||||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
|
||||||
{notice.title}
|
const fetchImage = async () => {
|
||||||
</Text>
|
if (!noticeId) {
|
||||||
<Box className="flex-row items-center">
|
if (isMounted) {
|
||||||
<Heading size="md" className="flex-1">
|
setImage("https://http.cat/404.jpg");
|
||||||
{notice.price}zł
|
setIsLoading(false);
|
||||||
</Heading>
|
}
|
||||||
<Pressable
|
return;
|
||||||
onPress={() => {
|
}
|
||||||
if (isInWishlist) {
|
|
||||||
removeNoticeFromWishlist(notice.noticeId); // Usuń z ulubionych
|
setIsLoading(true);
|
||||||
} else {
|
try {
|
||||||
addNoticeToWishlist(notice); // Dodaj do ulubionych
|
const images = await getAllImagesByNoticeId(noticeId);
|
||||||
}
|
if (isMounted) {
|
||||||
}}
|
setImage(images && images.length > 0 ? images[0] : "https://http.cat/404.jpg");
|
||||||
>
|
}
|
||||||
<Ionicons
|
} catch (error) {
|
||||||
name={isInWishlist ? "heart" : "heart-outline"} // Dynamiczna ikona
|
console.error(`Error while loading image: ${error}`);
|
||||||
size={24} // Rozmiar ikony
|
if (isMounted) {
|
||||||
color={"primary-heading-500"} // Kolor ikony
|
setImage("https://http.cat/404.jpg");
|
||||||
/>
|
}
|
||||||
</Pressable>
|
} finally {
|
||||||
</Box>
|
if (isMounted) {
|
||||||
</VStack>
|
setIsLoading(false);
|
||||||
</Card>
|
}
|
||||||
</Pressable>
|
}
|
||||||
</Link>
|
};
|
||||||
);
|
|
||||||
}
|
fetchImage();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false;
|
||||||
|
};
|
||||||
|
}, [noticeId]);
|
||||||
|
|
||||||
|
if (!notice) {
|
||||||
|
return <View style={{flex: 1}} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link href={`/notice/${noticeId}`} asChild>
|
||||||
|
<Pressable className="flex-1">
|
||||||
|
<Card className="p-0 rounded-lg max-w-[460px] flex-1">
|
||||||
|
{isLoading ? (
|
||||||
|
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
|
||||||
|
<ActivityIndicator size="large" color="#3b82f6" />
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Image
|
||||||
|
source={{
|
||||||
|
uri: image,
|
||||||
|
}}
|
||||||
|
className="h-auto w-full rounded-md aspect-[1/1]"
|
||||||
|
alt="image"
|
||||||
|
resizeMode="cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<VStack className="p-2">
|
||||||
|
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||||
|
{notice.title}
|
||||||
|
</Text>
|
||||||
|
<Box className="flex-row items-center">
|
||||||
|
<Heading size="md" className="flex-1">
|
||||||
|
{notice.price}zł
|
||||||
|
</Heading>
|
||||||
|
<Pressable
|
||||||
|
onPress={() => {
|
||||||
|
if (isInWishlist) {
|
||||||
|
removeNoticeFromWishlist(noticeId);
|
||||||
|
} else {
|
||||||
|
addNoticeToWishlist(notice);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name={isInWishlist ? "heart" : "heart-outline"}
|
||||||
|
size={24}
|
||||||
|
color={"primary-heading-500"}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
</Box>
|
||||||
|
</VStack>
|
||||||
|
</Card>
|
||||||
|
</Pressable>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
21
ArtisanConnect/eas.json
Normal file
21
ArtisanConnect/eas.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"cli": {
|
||||||
|
"version": ">= 16.8.0",
|
||||||
|
"appVersionSource": "remote"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"development": {
|
||||||
|
"developmentClient": true,
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"distribution": "internal"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"autoIncrement": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"submit": {
|
||||||
|
"production": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
12971
ArtisanConnect/package-lock.json
generated
12971
ArtisanConnect/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,9 +11,12 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/html-elements": "^0.4.2",
|
"@expo/html-elements": "^0.4.2",
|
||||||
"@expo/vector-icons": "^14.1.0",
|
"@expo/vector-icons": "^14.1.0",
|
||||||
|
"@gluestack-style/react": "^1.0.57",
|
||||||
"@gluestack-ui/actionsheet": "^0.2.53",
|
"@gluestack-ui/actionsheet": "^0.2.53",
|
||||||
"@gluestack-ui/button": "^1.0.14",
|
"@gluestack-ui/button": "^1.0.14",
|
||||||
|
"@gluestack-ui/divider": "^0.1.10",
|
||||||
"@gluestack-ui/form-control": "^0.1.19",
|
"@gluestack-ui/form-control": "^0.1.19",
|
||||||
|
"@gluestack-ui/hstack": "^0.1.17",
|
||||||
"@gluestack-ui/icon": "^0.1.27",
|
"@gluestack-ui/icon": "^0.1.27",
|
||||||
"@gluestack-ui/image": "^0.1.17",
|
"@gluestack-ui/image": "^0.1.17",
|
||||||
"@gluestack-ui/input": "^0.1.38",
|
"@gluestack-ui/input": "^0.1.38",
|
||||||
@@ -21,32 +24,45 @@
|
|||||||
"@gluestack-ui/overlay": "^0.1.22",
|
"@gluestack-ui/overlay": "^0.1.22",
|
||||||
"@gluestack-ui/select": "^0.1.31",
|
"@gluestack-ui/select": "^0.1.31",
|
||||||
"@gluestack-ui/textarea": "^0.1.25",
|
"@gluestack-ui/textarea": "^0.1.25",
|
||||||
|
"@gluestack-ui/themed": "^1.1.73",
|
||||||
"@gluestack-ui/toast": "^1.0.9",
|
"@gluestack-ui/toast": "^1.0.9",
|
||||||
"@legendapp/motion": "^2.4.0",
|
"@legendapp/motion": "^2.4.0",
|
||||||
|
"@react-native-async-storage/async-storage": "2.1.2",
|
||||||
|
"@react-native-community/cli-link-assets": "^18.0.0",
|
||||||
|
"@react-navigation/drawer": "^7.3.11",
|
||||||
"@tanstack/react-query": "^5.74.4",
|
"@tanstack/react-query": "^5.74.4",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.9.0",
|
||||||
"babel-plugin-module-resolver": "^5.0.2",
|
"babel-plugin-module-resolver": "^5.0.2",
|
||||||
"expo": "~52.0.46",
|
"expo": "^53.0.0",
|
||||||
"expo-constants": "~17.0.8",
|
"expo-auth-session": "~6.1.5",
|
||||||
"expo-linking": "~7.0.5",
|
"expo-camera": "~16.1.6",
|
||||||
"expo-router": "~4.0.20",
|
"expo-constants": "~17.1.6",
|
||||||
"expo-status-bar": "~2.0.1",
|
"expo-image-picker": "~16.1.4",
|
||||||
|
"expo-linking": "~7.1.4",
|
||||||
|
"expo-router": "~5.0.5",
|
||||||
|
"expo-status-bar": "~2.2.3",
|
||||||
|
"expo-web-browser": "~14.1.6",
|
||||||
|
"form-data": "^4.0.2",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
|
"lucide-react-native": "^0.511.0",
|
||||||
"nativewind": "^4.1.23",
|
"nativewind": "^4.1.23",
|
||||||
"react": "18.3.1",
|
"react": "19.0.0",
|
||||||
"react-dom": "18.3.1",
|
"react-dom": "19.0.0",
|
||||||
"react-native": "0.76.9",
|
"react-native": "0.79.2",
|
||||||
"react-native-css-interop": "^0.1.22",
|
"react-native-css-interop": "^0.1.22",
|
||||||
"react-native-reanimated": "^3.17.4",
|
"react-native-gesture-handler": "~2.24.0",
|
||||||
"react-native-safe-area-context": "^5.4.0",
|
"react-native-reanimated": "~3.17.4",
|
||||||
"react-native-screens": "~4.4.0",
|
"react-native-safe-area-context": "5.4.0",
|
||||||
"react-native-svg": "^15.2.0",
|
"react-native-screens": "~4.11.1",
|
||||||
"react-native-web": "~0.19.13",
|
"react-native-svg": "15.11.2",
|
||||||
|
"react-native-web": "~0.20.0",
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"zustand": "^5.0.3"
|
"zustand": "^5.0.3",
|
||||||
|
"expo-crypto": "~14.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.0",
|
"@babel/core": "^7.20.0",
|
||||||
"@types/react": "~18.3.12",
|
"@types/react": "~19.0.10",
|
||||||
"jscodeshift": "^0.15.2"
|
"jscodeshift": "^0.15.2"
|
||||||
},
|
},
|
||||||
"private": true
|
"private": true
|
||||||
|
|||||||
105
ArtisanConnect/store/authStore.jsx
Normal file
105
ArtisanConnect/store/authStore.jsx
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import {create} from "zustand";
|
||||||
|
import {createJSONStorage, persist} from "zustand/middleware";
|
||||||
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||||
|
|
||||||
|
export const useAuthStore = create(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
|
user_id: null,
|
||||||
|
token: null,
|
||||||
|
isLoading: false,
|
||||||
|
error: null,
|
||||||
|
|
||||||
|
signIn: async (email, password) => {
|
||||||
|
set({isLoading: true, error: null});
|
||||||
|
try {
|
||||||
|
const response = await axios.post(`${API_URL}/auth/login`, {
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
});
|
||||||
|
|
||||||
|
const user_id = response.data.user_id;
|
||||||
|
const token = response.data.token;
|
||||||
|
set({user_id: user_id, token: token, isLoading: false});
|
||||||
|
|
||||||
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
|
} catch (error) {
|
||||||
|
set({error: error.response?.data?.message || error.message, isLoading: false});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
signUp: async (userData) => {
|
||||||
|
set({isLoading: true, error: null});
|
||||||
|
try {
|
||||||
|
const response = await axios.post(`${API_URL}/auth/register`, userData, {
|
||||||
|
headers: {'Content-Type': 'application/json'}
|
||||||
|
});
|
||||||
|
|
||||||
|
const user_id = response.data.user_id;
|
||||||
|
const token = response.data.token;
|
||||||
|
set({user_id: user_id, token: token, isLoading: false});
|
||||||
|
|
||||||
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
|
} catch (error) {
|
||||||
|
set({error: error.response?.data?.message || error.message, isLoading: false});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
signInWithGoogle: async (googleToken) => {
|
||||||
|
set({isLoading: true, error: null});
|
||||||
|
try {
|
||||||
|
const response = await axios.post(`${API_URL}/auth/google`, {googleToken: googleToken}, {
|
||||||
|
headers: {'Content-Type': 'application/json'}
|
||||||
|
});
|
||||||
|
const user_id = response.data.user_id;
|
||||||
|
const token = response.data.token;
|
||||||
|
set({user_id: user_id, token: token, isLoading: false});
|
||||||
|
|
||||||
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
|
} catch (error) {
|
||||||
|
set({error: error.response?.data?.message || error.message, isLoading: false});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
signOut: async () => {
|
||||||
|
try {
|
||||||
|
await axios.post(`${API_URL}/auth/logout`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Logout error:", error);
|
||||||
|
} finally {
|
||||||
|
delete axios.defaults.headers.common["Authorization"];
|
||||||
|
set({user_id: null, token: null});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
checkAuth: async () => {
|
||||||
|
const {token} = useAuthStore.getState();
|
||||||
|
if (!token) return null;
|
||||||
|
|
||||||
|
set({isLoading: true});
|
||||||
|
try {
|
||||||
|
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
|
|
||||||
|
const response = await axios.get(`${API_URL}/auth/me`);
|
||||||
|
|
||||||
|
set({user_id: response.data, isLoading: false});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
delete axios.defaults.headers.common["Authorization"];
|
||||||
|
set({user_id: null, token: null, isLoading: false});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: "auth-storage",
|
||||||
|
storage: createJSONStorage(() => AsyncStorage),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
41
ArtisanConnect/store/noticesStore.jsx
Normal file
41
ArtisanConnect/store/noticesStore.jsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import {create} from "zustand";
|
||||||
|
import * as api from "@/api/notices";
|
||||||
|
|
||||||
|
export const useNoticesStore = create((set, get) => ({
|
||||||
|
notices: [],
|
||||||
|
fetchNotices: async () => {
|
||||||
|
set({error: null});
|
||||||
|
try {
|
||||||
|
const data = await api.listNotices();
|
||||||
|
set({notices: data});
|
||||||
|
} catch (error) {
|
||||||
|
set(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
addNotice: async (notice) => {
|
||||||
|
try {
|
||||||
|
const newNotice = await api.createNotice(notice);
|
||||||
|
set((state) => ({
|
||||||
|
notices: [...state.notices, newNotice],
|
||||||
|
}));
|
||||||
|
return newNotice;
|
||||||
|
} catch (error) {
|
||||||
|
set({ error });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getNoticeById: (noticeId) => {
|
||||||
|
return get().notices.find((notice) => String(notice.noticeId) === String(noticeId));
|
||||||
|
},
|
||||||
|
|
||||||
|
getAllImagesByNoticeId: async (noticeId) => {
|
||||||
|
try {
|
||||||
|
return await api.getAllImagesByNoticeId(noticeId);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error while getting images:", error);
|
||||||
|
return ["https://http.cat/404.jpg"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
@@ -9,7 +9,7 @@ export const useWishlist = create((set) => ({
|
|||||||
removeNoticeFromWishlist: (noticeId) =>
|
removeNoticeFromWishlist: (noticeId) =>
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
wishlistNotices: state.wishlistNotices.filter(
|
wishlistNotices: state.wishlistNotices.filter(
|
||||||
(item) => item.noticeId != noticeId
|
(item) => item.noticeId !== noticeId
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user