"use client"; import React, { useEffect, useRef, useState } from "react"; import { getLocations } from "@/utils/CitizenReport"; 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 || ""; mapboxgl.setRTLTextPlugin( "https://cdn.parsimap.ir/third-party/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js", () => {} ); const MapContainer = ReactMapboxGl({ accessToken: accessToken, minZoom: 8, maxZoom: 15, // zoom: 9, }); interface MyItemType { id: number; name: string; description: string; abbreviation: string; cityId: number; city: string; englishName: string; latitude: number; longitude: number; } const OnMapRequests = () => { const [selected, setSelected] = 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); setCitizenInstance(parsedItem); } }, [citizenInstance]); 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, // }); // functions // const showDetails = (request) => { // setSelected(request); // setDetailsClicked(true); // }; const showDetails = () => { // setSelected(request); // setDetailsClicked(true); }; // const onMapClicked = (e, x) => { // setSelected(null); // }; const { data: LocationData, isLoading, isError, isSuccess, refetch, } = useQuery({ queryKey: ["Locations"], queryFn: () => getLocations(), refetchOnWindowFocus: false, }); useEffect(() => { if (LocationData) { setLocations(LocationData?.data?.locations[0]?.locations); } }, [isSuccess]); return (
{isLoading ? (
) : ( {locations?.map((d: any) => ( {/* showDetails(d)} /> */} ))} {/* Open CardData */} {/*
{selected && }
*/}
)} {isError &&

Map Failed

}
); }; export default OnMapRequests; // return ( //
// //
// ); // } // if (isError) { // return

Map Failed

; // } // return ( //
// // {locations?.map((d: any) => ( // // // // ))} // // //
// ); // }; // export default OnMapRequests;