diff --git a/ArtisanConnect/api/notices.jsx b/ArtisanConnect/api/notices.jsx index 4a7190d..84a1867 100644 --- a/ArtisanConnect/api/notices.jsx +++ b/ArtisanConnect/api/notices.jsx @@ -42,8 +42,10 @@ export async function createNotice(notice) { for (const image of notice.image) { if (notice.image.indexOf(image) === 0) { await uploadImage(response.data.noticeId, image, true); + } else { + await uploadImage(response.data.noticeId, image, false); } - await uploadImage(response.data.noticeId, image, false); + console.log("Image uploaded successfully"); } } @@ -125,7 +127,7 @@ export const uploadImage = async (noticeId, imageObj, isFirst) => { headers: headers, } ); - console.info("Upload successful:", response.data); + console.log("Upload successful:", response.data); return response.data; } catch (error) { console.error( @@ -180,7 +182,7 @@ export const editNotice = async (noticeId, notice) => { if (response.data && notice.image && notice.image.length > 0) { for (let i = 0; i < notice.image.length; i++) { const image = notice.image[i]; - const isFirst = i == 0; + const isFirst = i === 0; if (typeof image === "string" && !image.startsWith("http")) { await uploadImage(noticeId, image, isFirst); diff --git a/ArtisanConnect/app/(tabs)/index.jsx b/ArtisanConnect/app/(tabs)/index.jsx index 63d8a26..7ee4629 100644 --- a/ArtisanConnect/app/(tabs)/index.jsx +++ b/ArtisanConnect/app/(tabs)/index.jsx @@ -15,21 +15,21 @@ export default function Home() { const [isReady, setIsReady] = useState(false); const fetchNotices = useNoticesStore((state) => state.fetchNotices); - // useEffect(() => { - // setIsReady(true); - // }, []); + useEffect(() => { + setIsReady(true); + }, []); - // useEffect(() => { - // if (isReady && !token) { - // router.replace("/login"); - // } - // }, [isReady, token, router]); + useEffect(() => { + if (isReady && !token) { + router.replace("/login"); + } + }, [isReady, token, router]); useEffect(() => { if (token) { fetchNotices(); } - }, [token, fetchNotices]); + }, [token]); const notices = useNoticesStore((state) => state.notices); diff --git a/ArtisanConnect/components/UserSection.jsx b/ArtisanConnect/components/UserSection.jsx index cf4008f..578c56d 100644 --- a/ArtisanConnect/components/UserSection.jsx +++ b/ArtisanConnect/components/UserSection.jsx @@ -20,7 +20,9 @@ export function UserSection({ notices, title }) { } }; - fetchUsers(); + if (token) { + fetchUsers(); + } }, [token]); const usersWithNoticeCount =