few fixes
categories are now pulled from backend
This commit is contained in:
14
ArtisanConnect/api/categories.jsx
Normal file
14
ArtisanConnect/api/categories.jsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
// const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||||
|
const API_URL = "http://10.224.1.86:8080/api/v1";
|
||||||
|
|
||||||
|
export async function listCategories() {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${API_URL}/vars/categories`);
|
||||||
|
console.log("Response", response.data, "status code: ", response.status);
|
||||||
|
return response.data;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Image, StyleSheet } from "react-native";
|
import { Image, StyleSheet } from "react-native";
|
||||||
import { Button, ButtonText } from "@/components/ui/button";
|
import { Button, ButtonText } from "@/components/ui/button";
|
||||||
import { FormControl } from "@/components/ui/form-control";
|
import { FormControl } from "@/components/ui/form-control";
|
||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
import { ChevronDownIcon } from "@/components/ui/icon";
|
import { ChevronDownIcon } from "@/components/ui/icon";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import {createNotice} from "@/api/notices";
|
import {createNotice} from "@/api/notices";
|
||||||
|
import {listCategories} from "@/api/categories";
|
||||||
|
|
||||||
export default function CreateNotice() {
|
export default function CreateNotice() {
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
@@ -30,6 +31,28 @@ export default function CreateNotice() {
|
|||||||
const [price, setPrice] = useState("");
|
const [price, setPrice] = useState("");
|
||||||
const [category, setCategory] = useState("");
|
const [category, setCategory] = useState("");
|
||||||
const [image, setImage] = useState(null);
|
const [image, setImage] = useState(null);
|
||||||
|
const [selectItems, setSelectItems] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let isMounted = true;
|
||||||
|
|
||||||
|
const fetchSelectItems = async () => {
|
||||||
|
try {
|
||||||
|
let data = await listCategories();
|
||||||
|
if (isMounted && Array.isArray(data)) {
|
||||||
|
setSelectItems(data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching select items:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchSelectItems();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isMounted = false;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const [error, setError] = useState({
|
const [error, setError] = useState({
|
||||||
title: false,
|
title: false,
|
||||||
@@ -166,9 +189,9 @@ export default function CreateNotice() {
|
|||||||
<SelectDragIndicatorWrapper>
|
<SelectDragIndicatorWrapper>
|
||||||
<SelectDragIndicator />
|
<SelectDragIndicator />
|
||||||
</SelectDragIndicatorWrapper>
|
</SelectDragIndicatorWrapper>
|
||||||
<SelectItem label="Meble" value="Furniture" />
|
{selectItems.map((item) => (
|
||||||
<SelectItem label="Biżuteria" value="Jewelry" />
|
<SelectItem key={item.value} label={item.label} value={item.value}/>
|
||||||
<SelectItem label="Ceramika" value="Ceramics" />
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</SelectPortal>
|
</SelectPortal>
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {useEffect, useState} from "react";
|
|||||||
|
|
||||||
export default function NoticeDetails() {
|
export default function NoticeDetails() {
|
||||||
const {id} = useLocalSearchParams();
|
const {id} = useLocalSearchParams();
|
||||||
const [image, setImage] = useState(null);
|
const [image, setImage] = useState("https://http.cat/404.jpg");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: notice,
|
data: notice,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function NoticeCard({notice}) {
|
|||||||
const isInWishlist = useWishlist((state) =>
|
const isInWishlist = useWishlist((state) =>
|
||||||
state.wishlistNotices.some((item) => item.noticeId === notice.noticeId)
|
state.wishlistNotices.some((item) => item.noticeId === notice.noticeId)
|
||||||
);
|
);
|
||||||
const [image, setImage] = useState(null);
|
const [image, setImage] = useState("https://http.cat/404.jpg");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchImage = async () => {
|
const fetchImage = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user