diff --git a/app/layout.tsx b/app/layout.tsx index 3410c88..5f1878e 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -7,28 +7,6 @@ import ProgressBarProviders from "@/components/ProgressBar/ProgressBar"; const inter = Inter({ subsets: ["latin"] }); -// mapboxgl.setRTLTextPlugin( -// "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", -// null -// ); - -// mapboxgl.setRTLTextPlugin( -// "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", -// (error) => { -// if (error) { -// console.error('Failed to load RTL text plugin:', error); -// } -// } -// ); - - -// mapboxgl.setRTLTextPlugin( -// "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", -// () => {} -// ); - - - export const metadata: Metadata = { title: "Create Next App", description: "Generated by create next app", diff --git a/components/RecentRequest/OnMapRequests.tsx b/components/RecentRequest/OnMapRequests.tsx index 22ef1db..d3de889 100644 --- a/components/RecentRequest/OnMapRequests.tsx +++ b/components/RecentRequest/OnMapRequests.tsx @@ -5,8 +5,6 @@ import { useQuery } from "@tanstack/react-query"; import { ThreeDots } from "react-loader-spinner"; import ReactMapboxGl, { Marker, ZoomControl } from "react-mapbox-gl"; import marker from "@/assets/images/location.svg"; -import RequestCard from "../Requests/RequestCard"; -import { cn } from "@/lib/utils"; import mapboxgl from "mapbox-gl"; const accessToken = process.env.REACT_APP_ACCESS_TOKEN || ""; @@ -18,7 +16,6 @@ const MapContainer = ReactMapboxGl({ accessToken: accessToken, minZoom: 8, maxZoom: 15, - // zoom: 9, }); interface MyItemType { @@ -32,74 +29,58 @@ interface MyItemType { latitude: number; longitude: number; } -const OnMapRequests = () => { + +interface LocationData { + reportId: number; + longitude: number; + latitude: number; +} + +const OnMapRequests: React.FC = () => { const [selected, setSelected] = useState(null); - const [citizenInstance, setCitizenInstance] = useState( - null - ); - const [locations, setLocations] = useState(null); + const [citizenInstance, setCitizenInstance] = useState(null); + const [locations, setLocations] = useState(null); useEffect(() => { const CtizenInstances = localStorage.getItem("SH_CT_INSTANCE"); - if (CtizenInstances) { - const parsedItem = JSON.parse(CtizenInstances); + const parsedItem: MyItemType = JSON.parse(CtizenInstances); setCitizenInstance(parsedItem); } - }, [citizenInstance]); + }, []); // Remove citizenInstance from the dependency array const defaultCoords = { latitude: citizenInstance?.latitude || 0, longitude: citizenInstance?.longitude || 0, }; - // refs - const detailsRef = useRef(null); - const wrappersRef = useRef(null); - // hooks - // const [detailsClicked, setDetailsClicked] = useClick({ - // element: detailsRef, - // // whitelists, - // }); + const detailsRef = useRef(null); + const wrappersRef = useRef(null); - // functions - // const showDetails = (request) => { - // setSelected(request); - // setDetailsClicked(true); - // }; - - const showDetails = () => { - // setSelected(request); - // setDetailsClicked(true); - }; - - // const onMapClicked = (e, x) => { - // setSelected(null); - // }; + const showDetails = () => {}; const { - data: LocationData, + data: locationData, isLoading, isError, isSuccess, refetch, } = useQuery({ queryKey: ["Locations"], - queryFn: () => getLocations(), + queryFn: getLocations, refetchOnWindowFocus: false, }); useEffect(() => { - if (LocationData) { - setLocations(LocationData?.data?.locations[0]?.locations); + if (locationData) { + setLocations(locationData?.data?.locations[0]?.locations); } - }, [isSuccess]); - + }, [locationData]); // Use locationData instead of isSuccess return (
{isLoading ? ( -
+
{ - {locations?.map((d: any) => ( - - - {/* showDetails(d)} /> */} + {locations?.map((d: LocationData) => ( + + location marker ))} - - {/* Open CardData */} - {/* -
- {selected && } -
-
*/} -
)} @@ -152,44 +118,4 @@ const OnMapRequests = () => { ); }; -export default OnMapRequests; -// return ( -//
-// -//
-// ); -// } - -// if (isError) { -// return

Map Failed

; -// } - -// return ( -//
-// -// {locations?.map((d: any) => ( -// -// -// -// ))} -// -// -//
-// ); -// }; - -// export default OnMapRequests; \ No newline at end of file +export default OnMapRequests; diff --git a/components/RecentRequest/RecentRequests.tsx b/components/RecentRequest/RecentRequests.tsx index 33133b2..8e5baa1 100644 --- a/components/RecentRequest/RecentRequests.tsx +++ b/components/RecentRequest/RecentRequests.tsx @@ -6,11 +6,15 @@ import NearestRequests from "./NearestRequests"; import { TabRequests } from "./TabRequests"; import { useQuery } from "@tanstack/react-query"; import { getInstances } from "@/utils/CitizenCommon"; +import dynamic from 'next/dynamic' // import UserContainer from "../User/UserContainer"; // import { useRouter } from "next/navigation"; // import { useMutation } from "@tanstack/react-query"; // import { deleteCookie, getCookie } from "cookies-next"; + +const ComponentMap = dynamic(() => import('./OnMapRequests'), { ssr: false }) + function RecentRequests() { const [citizenInstance, setCitizenInstance] = useState(null); @@ -42,6 +46,7 @@ function RecentRequests() {
{/* */} +
diff --git a/components/Requests/RequestCard.tsx b/components/Requests/RequestCard.tsx index 24d8be4..89302b9 100644 --- a/components/Requests/RequestCard.tsx +++ b/components/Requests/RequestCard.tsx @@ -33,6 +33,7 @@ interface RequestItem { medias: Media[]; isLiked: boolean; likes: number; + commentsCount:number; } interface RequestCardProps { @@ -109,7 +110,7 @@ const RequestCard: React.FC = ({ item, isSelfRequest }) => { initialIsLiked={item.isLiked} initialLikes={item.likes} /> - +
diff --git a/components/Requests/RequestComments.tsx b/components/Requests/RequestComments.tsx index 7e5ff72..818131b 100644 --- a/components/Requests/RequestComments.tsx +++ b/components/Requests/RequestComments.tsx @@ -1,13 +1,117 @@ -import React from "react"; +"use client"; +import { getComments } from "@/utils/CitizenReport"; +import { useQuery } from "@tanstack/react-query"; +import React, { useState } from "react"; import { FaRegComment } from "react-icons/fa"; +import { + Drawer, + DrawerClose, + DrawerContent, + DrawerDescription, + DrawerFooter, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from "@/components/ui/drawer"; +import { Button } from "../ui/button"; +import { MdSend } from "react-icons/md"; +import { Textarea } from "../ui/textarea"; + +// Define types for props +interface RequestCommentsProps { + reportId: string; + commentsCount: number; +} + +const RequestComments: React.FC = ({ + reportId, + commentsCount, +}) => { + // Component state + const [commentsCounts, setCommentsCounts] = useState(commentsCount); + const [comment, setComment] = useState(""); + + const { data, isLoading, isError, isSuccess, refetch } = useQuery({ + queryKey: ["Comments"], + queryFn: () => getComments(reportId), + // refetchOnWindowFocus: false, + }); + + const handleSubmit = async (event: React.FormEvent) => { + event.preventDefault(); + + const requestBody = { + comment: comment, + }; + + try { + const response = await fetch(`/api/comments/${reportId}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(requestBody), + }); + + if (!response.ok) { + throw new Error("Network response was not ok"); + } + + // Handle success (e.g., clear the input, show a success message, etc.) + setComment(""); + console.log("Comment submitted successfully!"); + } catch (error) { + // Handle error + console.error("There was an error submitting the comment:", error); + } + }; -const RequestComments = () => { return ( <> - + + e.stopPropagation()}> + + + + +

+ هنوز نظری برای این درخواست ثبت نشده است. +

+
+
+ +