Skip to content

Commit

Permalink
Merge pull request #19 from robertd2000/17-perf
Browse files Browse the repository at this point in the history
17 perf
  • Loading branch information
robertd2000 authored Mar 27, 2024
2 parents 49c0f83 + 0182390 commit b2508ba
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/components/Map/FlightsLayer/hooks/useFlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const useFlights = () => {

// const data = flightData;

console.log("len", data.states.length);

if (data && data?.states?.length) {
setflightFeatures(
data?.states.map((i, idx) => {
Expand Down Expand Up @@ -92,7 +94,7 @@ export const useFlights = () => {

return data;
},
refetchInterval: 1500,
refetchInterval: 3000,
refetchOnWindowFocus: false,
});

Expand Down
6 changes: 4 additions & 2 deletions src/components/Map/FlightsLayer/hooks/useSingleFlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const useSingleFlight = (mapRef: RefObject<RMap>) => {
}, []);

const onSetIcao = useCallback(({ icao24 }: { icao24: string }) => {
refetch();

setIcao(icao24);
setIsIcaoSetted(true);
}, []);
Expand All @@ -36,8 +38,8 @@ export const useSingleFlight = (mapRef: RefObject<RMap>) => {
[mapRef]
);

const { error, isLoading } = useQuery({
queryKey: ["getStateByIcao"],
const { error, isLoading, refetch } = useQuery({
queryKey: ["getStateByIcao", icao],
queryFn: async () => {
// const data = flightSingleData;
const data = await getStateByIcao(icao as string);
Expand Down
27 changes: 13 additions & 14 deletions src/components/Map/FlightsLayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { RefObject, memo, useCallback, useRef } from "react";
import { Feature } from "ol";
import { FeatureLike } from "ol/Feature";
import { Style, Icon } from "ol/style";
import { RFeature, RFeatureUIEvent, RLayerCluster, RMap } from "rlayers";
import { FlightInfo } from "@/components/FlightInfo";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { useSingleFlight } from "./hooks/useSingleFlight";
import { useFlights } from "./hooks/useFlights";
import { AircraftCategories } from "@/constants/flights/categories";
import { RefObject, memo, useCallback } from "react";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";

export const FlightsLayer = memo(({ mapRef }: { mapRef: RefObject<RMap> }) => {
const { flightFeatures } = useFlights();
Expand All @@ -24,6 +24,8 @@ export const FlightsLayer = memo(({ mapRef }: { mapRef: RefObject<RMap> }) => {
onSetIcao,
} = useSingleFlight(mapRef);

const flightLayer = useRef<RLayerCluster>(null);

return (
<>
<FlightInfo
Expand All @@ -45,6 +47,7 @@ export const FlightsLayer = memo(({ mapRef }: { mapRef: RefObject<RMap> }) => {
</div>

<RLayerCluster
ref={flightLayer}
distance={30}
style={useCallback(
(feature: FeatureLike, resolution: number) => {
Expand Down Expand Up @@ -81,17 +84,13 @@ export const FlightsLayer = memo(({ mapRef }: { mapRef: RefObject<RMap> }) => {
name: "flights",
}}
zIndex={100}
onClick={useCallback(
(e: RFeatureUIEvent) => {
const { icao24 } =
e.target.getProperties().features[0].values_.data;
onSheetOpen(true);
onSetIcao({
icao24,
});
},
[onSetIcao, onSheetOpen]
)}
onClick={useCallback((e: RFeatureUIEvent) => {
const { icao24 } = e.target.getProperties().features[0].values_.data;
onSheetOpen(true);
onSetIcao({
icao24,
});
}, [])}
>
{flightFeatures
.filter((i) => i != null)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Map/MainMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const MainMap = memo(() => {
<RMap
className={style.mainMap}
initial={view}
minZoom={6}
maxZoom={18}
minZoom={4}
maxZoom={8}
projection={"EPSG:3857"}
view={[view, onSetView]}
ref={mapRef}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/map/useMapCoords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useMapCoords = () => {

setSearchParams(searchParams);
},
[searchParams, setSearchParams]
[searchParams]
);

const getCoords = useCallback(() => {
Expand Down

0 comments on commit b2508ba

Please sign in to comment.