Add maps, Bluetooth config & fixes

This commit is contained in:
Sacha Weatherstone
2022-08-19 18:18:48 +09:30
parent b8877f8a63
commit 9f1d3498ea
44 changed files with 611 additions and 1064 deletions
+32
View File
@@ -0,0 +1,32 @@
import type React from "react";
import { useEffect, useState } from "react";
import { Map, MapOptions } from "maplibre-gl";
export interface useMapboxProps {
ref: React.RefObject<HTMLDivElement>;
style: string;
options?: Partial<MapOptions>;
}
export function useCreateMapbox({
ref,
style,
options,
}: useMapboxProps): Map | undefined {
const [mapInstance, setMapInstance] = useState<Map>();
useEffect(() => {
const container = ref.current as HTMLDivElement;
if (mapInstance || !container) {
return;
}
const map = new Map({
container,
style,
...options,
});
setMapInstance(map);
}, []);
return mapInstance;
}
+13
View File
@@ -0,0 +1,13 @@
import { createContext, useContext } from "react";
import type { Device } from "../stores/deviceStore.js";
export const DeviceContext = createContext<Device | undefined>(undefined);
export const useDevice = (): Device => {
const context = useContext(DeviceContext);
if (context === undefined) {
throw new Error("useDevice must be used within a ConnectionProvider");
}
return context;
};
+14
View File
@@ -0,0 +1,14 @@
import { createContext, useContext } from "react";
import type { Map } from "maplibre-gl";
export interface MapContextValue {
ref: React.Ref<HTMLDivElement>;
map?: Map;
}
export const MapContext = createContext<MapContextValue>({} as MapContextValue);
export const useMap = (): MapContextValue => {
return useContext(MapContext);
};