/* Copyright 2024 New Vector Ltd. Copyright 2022 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import { Beacon } from "matrix-js-sdk/src/matrix"; import React, { HTMLProps } from "react"; import { _t } from "../../../languageHandler"; import { useOwnLiveBeacons } from "../../../utils/beacon"; import { preventDefaultWrapper } from "../../../utils/NativeEventUtils"; import BeaconStatus from "./BeaconStatus"; import { BeaconDisplayStatus } from "./displayStatus"; import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton"; interface Props { displayStatus: BeaconDisplayStatus; className?: string; beacon?: Beacon; withIcon?: boolean; } /** * Wraps BeaconStatus with more capabilities * for errors and actions available for users own live beacons */ const OwnBeaconStatus: React.FC> = ({ beacon, displayStatus, ...rest }) => { const { hasLocationPublishError, hasStopSharingError, stoppingInProgress, onStopSharing, onResetLocationPublishError, } = useOwnLiveBeacons(beacon?.identifier ? [beacon?.identifier] : []); // combine display status with errors that only occur for user's own beacons const ownDisplayStatus = hasLocationPublishError || hasStopSharingError ? BeaconDisplayStatus.Error : displayStatus; return ( {ownDisplayStatus === BeaconDisplayStatus.Active && ( (onStopSharing)} className="mx_OwnBeaconStatus_button mx_OwnBeaconStatus_destructiveButton" disabled={stoppingInProgress} > {_t("action|stop")} )} {hasLocationPublishError && ( {_t("action|retry")} )} {hasStopSharingError && ( {_t("action|retry")} )} ); }; export default OwnBeaconStatus;