Eliminate the use of MatrixClientPeg in utils (#10910)
This commit is contained in:
committed by
GitHub
parent
a0c2676c38
commit
30429df948
@@ -15,6 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import SdkConfig from "../../SdkConfig";
|
||||
import { getTileServerWellKnown } from "../WellKnownUtils";
|
||||
@@ -25,8 +26,8 @@ import { LocationShareError } from "./LocationShareErrors";
|
||||
* .well-known location, or, failing that, in our local config, or, failing
|
||||
* that, defaults to the same tile server listed by matrix.org.
|
||||
*/
|
||||
export function findMapStyleUrl(): string {
|
||||
const mapStyleUrl = getTileServerWellKnown()?.map_style_url ?? SdkConfig.get().map_style_url;
|
||||
export function findMapStyleUrl(matrixClient: MatrixClient): string {
|
||||
const mapStyleUrl = getTileServerWellKnown(matrixClient)?.map_style_url ?? SdkConfig.get().map_style_url;
|
||||
|
||||
if (!mapStyleUrl) {
|
||||
logger.error("'map_style_url' missing from homeserver .well-known area, and missing from from config.json.");
|
||||
|
||||
@@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import * as maplibregl from "maplibre-gl";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { M_LOCATION } from "matrix-js-sdk/src/@types/location";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
@@ -24,9 +24,14 @@ import { parseGeoUri } from "./parseGeoUri";
|
||||
import { findMapStyleUrl } from "./findMapStyleUrl";
|
||||
import { LocationShareError } from "./LocationShareErrors";
|
||||
|
||||
export const createMap = (interactive: boolean, bodyId: string, onError?: (error: Error) => void): maplibregl.Map => {
|
||||
export const createMap = (
|
||||
client: MatrixClient,
|
||||
interactive: boolean,
|
||||
bodyId: string,
|
||||
onError?: (error: Error) => void,
|
||||
): maplibregl.Map => {
|
||||
try {
|
||||
const styleUrl = findMapStyleUrl();
|
||||
const styleUrl = findMapStyleUrl(client);
|
||||
|
||||
const map = new maplibregl.Map({
|
||||
container: bodyId,
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useEffect, useState } from "react";
|
||||
import { Map as MapLibreMap } from "maplibre-gl";
|
||||
|
||||
import { createMap } from "./map";
|
||||
import { useMatrixClientContext } from "../../contexts/MatrixClientContext";
|
||||
|
||||
interface UseMapProps {
|
||||
bodyId: string;
|
||||
@@ -32,12 +33,13 @@ interface UseMapProps {
|
||||
* As map is recreated on changes to it
|
||||
*/
|
||||
export const useMap = ({ interactive, bodyId, onError }: UseMapProps): MapLibreMap | undefined => {
|
||||
const cli = useMatrixClientContext();
|
||||
const [map, setMap] = useState<MapLibreMap>();
|
||||
|
||||
useEffect(
|
||||
() => {
|
||||
try {
|
||||
setMap(createMap(!!interactive, bodyId, onError));
|
||||
setMap(createMap(cli, !!interactive, bodyId, onError));
|
||||
} catch (error) {
|
||||
onError?.(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user