Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
||||
import React, { useCallback, useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Beacon,
|
||||
BeaconEvent,
|
||||
|
@ -22,30 +22,32 @@ import {
|
|||
MatrixEventEvent,
|
||||
MatrixClient,
|
||||
RelationType,
|
||||
} from 'matrix-js-sdk/src/matrix';
|
||||
import { BeaconLocationState } from 'matrix-js-sdk/src/content-helpers';
|
||||
import { randomString } from 'matrix-js-sdk/src/randomstring';
|
||||
import { M_BEACON } from 'matrix-js-sdk/src/@types/beacon';
|
||||
import classNames from 'classnames';
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { BeaconLocationState } from "matrix-js-sdk/src/content-helpers";
|
||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { M_BEACON } from "matrix-js-sdk/src/@types/beacon";
|
||||
import classNames from "classnames";
|
||||
|
||||
import MatrixClientContext from '../../../contexts/MatrixClientContext';
|
||||
import { useEventEmitterState } from '../../../hooks/useEventEmitter';
|
||||
import { _t } from '../../../languageHandler';
|
||||
import Modal from '../../../Modal';
|
||||
import { isBeaconWaitingToStart, useBeacon } from '../../../utils/beacon';
|
||||
import { isSelfLocation, LocationShareError } from '../../../utils/location';
|
||||
import { BeaconDisplayStatus, getBeaconDisplayStatus } from '../beacon/displayStatus';
|
||||
import BeaconStatus from '../beacon/BeaconStatus';
|
||||
import OwnBeaconStatus from '../beacon/OwnBeaconStatus';
|
||||
import Map from '../location/Map';
|
||||
import { MapError } from '../location/MapError';
|
||||
import MapFallback from '../location/MapFallback';
|
||||
import SmartMarker from '../location/SmartMarker';
|
||||
import { GetRelationsForEvent } from '../rooms/EventTile';
|
||||
import BeaconViewDialog from '../beacon/BeaconViewDialog';
|
||||
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||
import { useEventEmitterState } from "../../../hooks/useEventEmitter";
|
||||
import { _t } from "../../../languageHandler";
|
||||
import Modal from "../../../Modal";
|
||||
import { isBeaconWaitingToStart, useBeacon } from "../../../utils/beacon";
|
||||
import { isSelfLocation, LocationShareError } from "../../../utils/location";
|
||||
import { BeaconDisplayStatus, getBeaconDisplayStatus } from "../beacon/displayStatus";
|
||||
import BeaconStatus from "../beacon/BeaconStatus";
|
||||
import OwnBeaconStatus from "../beacon/OwnBeaconStatus";
|
||||
import Map from "../location/Map";
|
||||
import { MapError } from "../location/MapError";
|
||||
import MapFallback from "../location/MapFallback";
|
||||
import SmartMarker from "../location/SmartMarker";
|
||||
import { GetRelationsForEvent } from "../rooms/EventTile";
|
||||
import BeaconViewDialog from "../beacon/BeaconViewDialog";
|
||||
import { IBodyProps } from "./IBodyProps";
|
||||
|
||||
const useBeaconState = (beaconInfoEvent: MatrixEvent): {
|
||||
const useBeaconState = (
|
||||
beaconInfoEvent: MatrixEvent,
|
||||
): {
|
||||
beacon?: Beacon;
|
||||
description?: string;
|
||||
latestLocationState?: BeaconLocationState;
|
||||
|
@ -54,15 +56,13 @@ const useBeaconState = (beaconInfoEvent: MatrixEvent): {
|
|||
} => {
|
||||
const beacon = useBeacon(beaconInfoEvent);
|
||||
|
||||
const isLive = useEventEmitterState(
|
||||
beacon,
|
||||
BeaconEvent.LivenessChange,
|
||||
() => beacon?.isLive);
|
||||
const isLive = useEventEmitterState(beacon, BeaconEvent.LivenessChange, () => beacon?.isLive);
|
||||
|
||||
const latestLocationState = useEventEmitterState(
|
||||
beacon,
|
||||
BeaconEvent.LocationUpdate,
|
||||
() => beacon?.latestLocationState);
|
||||
() => beacon?.latestLocationState,
|
||||
);
|
||||
|
||||
if (!beacon) {
|
||||
return {};
|
||||
|
@ -104,20 +104,23 @@ const useHandleBeaconRedaction = (
|
|||
matrixClient: MatrixClient,
|
||||
getRelationsForEvent?: GetRelationsForEvent,
|
||||
): void => {
|
||||
const onBeforeBeaconInfoRedaction = useCallback((_event: MatrixEvent, redactionEvent: MatrixEvent) => {
|
||||
const relations = getRelationsForEvent ?
|
||||
getRelationsForEvent(event.getId(), RelationType.Reference, M_BEACON.name) :
|
||||
undefined;
|
||||
const onBeforeBeaconInfoRedaction = useCallback(
|
||||
(_event: MatrixEvent, redactionEvent: MatrixEvent) => {
|
||||
const relations = getRelationsForEvent
|
||||
? getRelationsForEvent(event.getId(), RelationType.Reference, M_BEACON.name)
|
||||
: undefined;
|
||||
|
||||
relations?.getRelations()?.forEach(locationEvent => {
|
||||
matrixClient.redactEvent(
|
||||
locationEvent.getRoomId(),
|
||||
locationEvent.getId(),
|
||||
undefined,
|
||||
redactionEvent.getContent(),
|
||||
);
|
||||
});
|
||||
}, [event, matrixClient, getRelationsForEvent]);
|
||||
relations?.getRelations()?.forEach((locationEvent) => {
|
||||
matrixClient.redactEvent(
|
||||
locationEvent.getRoomId(),
|
||||
locationEvent.getId(),
|
||||
undefined,
|
||||
redactionEvent.getContent(),
|
||||
);
|
||||
});
|
||||
},
|
||||
[event, matrixClient, getRelationsForEvent],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
event.addListener(MatrixEventEvent.BeforeRedaction, onBeforeBeaconInfoRedaction);
|
||||
|
@ -128,17 +131,13 @@ const useHandleBeaconRedaction = (
|
|||
};
|
||||
|
||||
const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent, getRelationsForEvent }, ref) => {
|
||||
const {
|
||||
beacon,
|
||||
isLive,
|
||||
latestLocationState,
|
||||
waitingToStart,
|
||||
} = useBeaconState(mxEvent);
|
||||
const { beacon, isLive, latestLocationState, waitingToStart } = useBeaconState(mxEvent);
|
||||
const mapId = useUniqueId(mxEvent.getId());
|
||||
|
||||
const matrixClient = useContext(MatrixClientContext);
|
||||
const [error, setError] = useState<Error>();
|
||||
const isMapDisplayError = error?.message === LocationShareError.MapStyleUrlNotConfigured ||
|
||||
const isMapDisplayError =
|
||||
error?.message === LocationShareError.MapStyleUrlNotConfigured ||
|
||||
error?.message === LocationShareError.MapStyleUrlNotReachable;
|
||||
const displayStatus = getBeaconDisplayStatus(
|
||||
isLive,
|
||||
|
@ -173,15 +172,15 @@ const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent, getRelati
|
|||
|
||||
let map: JSX.Element;
|
||||
if (displayStatus === BeaconDisplayStatus.Active && !isMapDisplayError) {
|
||||
map = <Map
|
||||
id={mapId}
|
||||
centerGeoUri={latestLocationState.uri}
|
||||
onError={setError}
|
||||
onClick={onClick}
|
||||
className="mx_MBeaconBody_map"
|
||||
>
|
||||
{
|
||||
({ map }) =>
|
||||
map = (
|
||||
<Map
|
||||
id={mapId}
|
||||
centerGeoUri={latestLocationState.uri}
|
||||
onError={setError}
|
||||
onClick={onClick}
|
||||
className="mx_MBeaconBody_map"
|
||||
>
|
||||
{({ map }) => (
|
||||
<SmartMarker
|
||||
map={map}
|
||||
id={`${mapId}-marker`}
|
||||
|
@ -189,52 +188,52 @@ const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent, getRelati
|
|||
roomMember={markerRoomMember}
|
||||
useMemberColor
|
||||
/>
|
||||
}
|
||||
</Map>;
|
||||
)}
|
||||
</Map>
|
||||
);
|
||||
} else if (isMapDisplayError) {
|
||||
map = <MapError
|
||||
error={error.message as LocationShareError}
|
||||
onClick={onClick}
|
||||
className={classNames(
|
||||
'mx_MBeaconBody_mapError',
|
||||
// set interactive class when maximised map can be opened
|
||||
{ 'mx_MBeaconBody_mapErrorInteractive':
|
||||
displayStatus === BeaconDisplayStatus.Active,
|
||||
},
|
||||
)}
|
||||
isMinimised
|
||||
/>;
|
||||
map = (
|
||||
<MapError
|
||||
error={error.message as LocationShareError}
|
||||
onClick={onClick}
|
||||
className={classNames(
|
||||
"mx_MBeaconBody_mapError",
|
||||
// set interactive class when maximised map can be opened
|
||||
{ mx_MBeaconBody_mapErrorInteractive: displayStatus === BeaconDisplayStatus.Active },
|
||||
)}
|
||||
isMinimised
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
map = <MapFallback
|
||||
isLoading={displayStatus === BeaconDisplayStatus.Loading}
|
||||
className='mx_MBeaconBody_map mx_MBeaconBody_mapFallback'
|
||||
/>;
|
||||
map = (
|
||||
<MapFallback
|
||||
isLoading={displayStatus === BeaconDisplayStatus.Loading}
|
||||
className="mx_MBeaconBody_map mx_MBeaconBody_mapFallback"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className='mx_MBeaconBody'
|
||||
ref={ref}
|
||||
>
|
||||
{ map }
|
||||
{ isOwnBeacon ?
|
||||
<div className="mx_MBeaconBody" ref={ref}>
|
||||
{map}
|
||||
{isOwnBeacon ? (
|
||||
<OwnBeaconStatus
|
||||
className='mx_MBeaconBody_chin'
|
||||
className="mx_MBeaconBody_chin"
|
||||
beacon={beacon}
|
||||
displayStatus={displayStatus}
|
||||
withIcon
|
||||
/> :
|
||||
<BeaconStatus
|
||||
className='mx_MBeaconBody_chin'
|
||||
beacon={beacon}
|
||||
displayStatus={displayStatus}
|
||||
label={_t('View live location')}
|
||||
withIcon
|
||||
/>
|
||||
}
|
||||
) : (
|
||||
<BeaconStatus
|
||||
className="mx_MBeaconBody_chin"
|
||||
beacon={beacon}
|
||||
displayStatus={displayStatus}
|
||||
label={_t("View live location")}
|
||||
withIcon
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export default MBeaconBody;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue