Apply prettier formatting

This commit is contained in:
Michael Weimann
2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
1576 changed files with 65384 additions and 62477 deletions
+4 -3
View File
@@ -36,8 +36,9 @@ export type Bounds = {
* west of Greenwich has a negative longitude, min -180
*/
export const getBeaconBounds = (beacons: Beacon[]): Bounds | undefined => {
const coords = beacons.filter(beacon => !!beacon.latestLocationState)
.map(beacon => parseGeoUri(beacon.latestLocationState.uri));
const coords = beacons
.filter((beacon) => !!beacon.latestLocationState)
.map((beacon) => parseGeoUri(beacon.latestLocationState.uri));
if (!coords.length) {
return;
@@ -51,6 +52,6 @@ export const getBeaconBounds = (beacons: Beacon[]): Bounds | undefined => {
north: sortedByLat[0].latitude,
south: sortedByLat[sortedByLat.length - 1].latitude,
east: sortedByLong[0].longitude,
west: sortedByLong[sortedByLong.length -1].longitude,
west: sortedByLong[sortedByLong.length - 1].longitude,
};
};
+1 -1
View File
@@ -25,7 +25,7 @@ import { Beacon } from "matrix-js-sdk/src/matrix";
* @returns remainingMs
*/
export const msUntilExpiry = (startTimestamp: number, durationMs: number): number =>
Math.max(0, (startTimestamp + durationMs) - Date.now());
Math.max(0, startTimestamp + durationMs - Date.now());
export const getBeaconMsUntilExpiry = (beaconInfo: BeaconInfoState): number =>
msUntilExpiry(beaconInfo.timestamp, beaconInfo.timeout);
+14 -21
View File
@@ -20,15 +20,15 @@ import { logger } from "matrix-js-sdk/src/logger";
// https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError
export enum GeolocationError {
// no navigator.geolocation
Unavailable = 'Unavailable',
Unavailable = "Unavailable",
// The acquisition of the geolocation information failed because the page didn't have the permission to do it.
PermissionDenied = 'PermissionDenied',
PermissionDenied = "PermissionDenied",
// The acquisition of the geolocation failed because at least one internal source of position returned an internal error.
PositionUnavailable = 'PositionUnavailable',
PositionUnavailable = "PositionUnavailable",
// The time allowed to acquire the geolocation was reached before the information was obtained.
Timeout = 'Timeout',
Timeout = "Timeout",
// other unexpected failure
Default = 'Default'
Default = "Default",
}
const GeolocationOptions = {
@@ -37,12 +37,12 @@ const GeolocationOptions = {
};
const isGeolocationPositionError = (error: unknown): error is GeolocationPositionError =>
typeof error === 'object' && !!error['PERMISSION_DENIED'];
typeof error === "object" && !!error["PERMISSION_DENIED"];
/**
* Maps GeolocationPositionError to our GeolocationError enum
*/
export const mapGeolocationError = (error: GeolocationPositionError | Error): GeolocationError => {
logger.error('Geolocation failed', error?.message ?? error);
logger.error("Geolocation failed", error?.message ?? error);
if (isGeolocationPositionError(error)) {
switch (error?.code) {
@@ -83,9 +83,7 @@ export type TimedGeoUri = {
};
export const genericPositionFromGeolocation = (geoPosition: GeolocationPosition): GenericPosition => {
const {
latitude, longitude, altitude, accuracy,
} = geoPosition.coords;
const { latitude, longitude, altitude, accuracy } = geoPosition.coords;
return {
// safari reports geolocation timestamps as Apple Cocoa Core Data timestamp
@@ -93,23 +91,18 @@ export const genericPositionFromGeolocation = (geoPosition: GeolocationPosition)
// they also use local time, not utc
// to simplify, just use Date.now()
timestamp: Date.now(),
latitude, longitude, altitude, accuracy,
latitude,
longitude,
altitude,
accuracy,
};
};
export const getGeoUri = (position: GenericPosition): string => {
const lat = position.latitude;
const lon = position.longitude;
const alt = (
Number.isFinite(position.altitude)
? `,${position.altitude}`
: ""
);
const acc = (
Number.isFinite(position.accuracy)
? `;u=${position.accuracy}`
: ""
);
const alt = Number.isFinite(position.altitude) ? `,${position.altitude}` : "";
const acc = Number.isFinite(position.accuracy) ? `;u=${position.accuracy}` : "";
return `geo:${lat},${lon}${alt}${acc}`;
};
+1 -5
View File
@@ -14,11 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {
MatrixClient,
MatrixEvent,
getBeaconInfoIdentifier,
} from "matrix-js-sdk/src/matrix";
import { MatrixClient, MatrixEvent, getBeaconInfoIdentifier } from "matrix-js-sdk/src/matrix";
/**
* Beacons should only have shareable locations (open in external mapping tool, forward)
+4 -4
View File
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
export * from './duration';
export * from './geolocation';
export * from './useBeacon';
export * from './useOwnLiveBeacons';
export * from "./duration";
export * from "./geolocation";
export * from "./useBeacon";
export * from "./useOwnLiveBeacons";
+3 -6
View File
@@ -21,11 +21,8 @@ import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
* beacon_info events without live property set to true
* should be displayed in the timeline
*/
export const shouldDisplayAsBeaconTile = (event: MatrixEvent): boolean => (
export const shouldDisplayAsBeaconTile = (event: MatrixEvent): boolean =>
M_BEACON_INFO.matches(event.getType()) &&
(
event.getContent()?.live ||
(event.getContent()?.live ||
// redacted beacons should show 'message deleted' tile
event.isRedacted()
)
);
event.isRedacted());
+2 -11
View File
@@ -15,12 +15,7 @@ limitations under the License.
*/
import { useContext, useEffect, useState } from "react";
import {
Beacon,
BeaconEvent,
MatrixEvent,
getBeaconInfoIdentifier,
} from "matrix-js-sdk/src/matrix";
import { Beacon, BeaconEvent, MatrixEvent, getBeaconInfoIdentifier } from "matrix-js-sdk/src/matrix";
import MatrixClientContext from "../../contexts/MatrixClientContext";
import { useEventEmitterState } from "../../hooks/useEventEmitter";
@@ -56,11 +51,7 @@ export const useBeacon = (beaconInfoEvent: MatrixEvent): Beacon | undefined => {
// beacon update will fire when this beacon is superseded
// check the updated event id for equality to the matrix event
const beaconInstanceEventId = useEventEmitterState(
beacon,
BeaconEvent.Update,
() => beacon?.beaconInfoId,
);
const beaconInstanceEventId = useEventEmitterState(beacon, BeaconEvent.Update, () => beacon?.beaconInfoId);
useEffect(() => {
if (beaconInstanceEventId && beaconInstanceEventId !== beaconInfoEvent.getId()) {
+4 -11
View File
@@ -14,12 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import {
Beacon,
Room,
RoomStateEvent,
MatrixClient,
} from "matrix-js-sdk/src/matrix";
import { Beacon, Room, RoomStateEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
import { useEventEmitterState } from "../../hooks/useEventEmitter";
@@ -28,13 +23,11 @@ import { useEventEmitterState } from "../../hooks/useEventEmitter";
*
* Beacons are removed from array when they become inactive
*/
export const useLiveBeacons = (roomId: Room['roomId'], matrixClient: MatrixClient): Beacon[] => {
export const useLiveBeacons = (roomId: Room["roomId"], matrixClient: MatrixClient): Beacon[] => {
const room = matrixClient.getRoom(roomId);
const liveBeacons = useEventEmitterState(
room.currentState,
RoomStateEvent.BeaconLiveness,
() => room.currentState?.liveBeaconIds.map(beaconIdentifier => room.currentState.beacons.get(beaconIdentifier)),
const liveBeacons = useEventEmitterState(room.currentState, RoomStateEvent.BeaconLiveness, () =>
room.currentState?.liveBeaconIds.map((beaconIdentifier) => room.currentState.beacons.get(beaconIdentifier)),
);
return liveBeacons;
+6 -7
View File
@@ -43,15 +43,13 @@ export const useOwnLiveBeacons = (liveBeaconIds: BeaconIdentifier[]): LiveBeacon
const hasLocationPublishError = useEventEmitterState(
OwnBeaconStore.instance,
OwnBeaconStoreEvent.LocationPublishError,
() =>
liveBeaconIds.some(OwnBeaconStore.instance.beaconHasLocationPublishError),
() => liveBeaconIds.some(OwnBeaconStore.instance.beaconHasLocationPublishError),
);
const hasStopSharingError = useEventEmitterState(
OwnBeaconStore.instance,
OwnBeaconStoreEvent.BeaconUpdateError,
() =>
liveBeaconIds.some(id => OwnBeaconStore.instance.beaconUpdateErrors.has(id)),
() => liveBeaconIds.some((id) => OwnBeaconStore.instance.beaconUpdateErrors.has(id)),
);
useEffect(() => {
@@ -66,21 +64,22 @@ export const useOwnLiveBeacons = (liveBeaconIds: BeaconIdentifier[]): LiveBeacon
}, [liveBeaconIds]);
// select the beacon with latest expiry to display expiry time
const beacon = liveBeaconIds.map(beaconId => OwnBeaconStore.instance.getBeaconById(beaconId))
const beacon = liveBeaconIds
.map((beaconId) => OwnBeaconStore.instance.getBeaconById(beaconId))
.sort(sortBeaconsByLatestExpiry)
.shift();
const onStopSharing = async () => {
setStoppingInProgress(true);
try {
await Promise.all(liveBeaconIds.map(beaconId => OwnBeaconStore.instance.stopBeacon(beaconId)));
await Promise.all(liveBeaconIds.map((beaconId) => OwnBeaconStore.instance.stopBeacon(beaconId)));
} catch (error) {
setStoppingInProgress(false);
}
};
const onResetLocationPublishError = () => {
liveBeaconIds.forEach(beaconId => {
liveBeaconIds.forEach((beaconId) => {
OwnBeaconStore.instance.resetLocationPublishError(beaconId);
});
};