|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React, { HTMLProps } from 'react'; |
| 18 | +import classNames from 'classnames'; |
| 19 | +import { Beacon } from 'matrix-js-sdk/src/matrix'; |
| 20 | + |
| 21 | +import StyledLiveBeaconIcon from './StyledLiveBeaconIcon'; |
| 22 | +import { _t } from '../../../languageHandler'; |
| 23 | +import AccessibleButton from '../elements/AccessibleButton'; |
| 24 | +import LiveTimeRemaining from './LiveTimeRemaining'; |
| 25 | +import { BeaconDisplayStatus } from './displayStatus'; |
| 26 | + |
| 27 | +interface Props { |
| 28 | + displayStatus: BeaconDisplayStatus; |
| 29 | + beacon?: Beacon; |
| 30 | + label?: string; |
| 31 | + // assumes permission to stop was checked by parent |
| 32 | + stopBeacon?: () => void; |
| 33 | +} |
| 34 | + |
| 35 | +const BeaconStatus: React.FC<Props & HTMLProps<HTMLDivElement>> = |
| 36 | + ({ beacon, displayStatus, label, stopBeacon, className, ...rest }) => { |
| 37 | + const isIdle = displayStatus === BeaconDisplayStatus.Loading || |
| 38 | + displayStatus === BeaconDisplayStatus.Stopped; |
| 39 | + |
| 40 | + return <div |
| 41 | + {...rest} |
| 42 | + className={classNames('mx_BeaconStatus', `mx_BeaconStatus_${displayStatus}`, className)} |
| 43 | + > |
| 44 | + <StyledLiveBeaconIcon |
| 45 | + className='mx_BeaconStatus_icon' |
| 46 | + withError={displayStatus === BeaconDisplayStatus.Error} |
| 47 | + isIdle={isIdle} |
| 48 | + /> |
| 49 | + { displayStatus === BeaconDisplayStatus.Loading && <span>{ _t('Loading live location...') }</span> } |
| 50 | + { displayStatus === BeaconDisplayStatus.Stopped && <span>{ _t('Live location ended') }</span> } |
| 51 | + |
| 52 | + { /* TODO error */ } |
| 53 | + |
| 54 | + { displayStatus === BeaconDisplayStatus.Active && beacon && <> |
| 55 | + <div className='mx_BeaconStatus_activeDescription'> |
| 56 | + { label } |
| 57 | + <LiveTimeRemaining beacon={beacon} /> |
| 58 | + </div> |
| 59 | + { stopBeacon && <AccessibleButton |
| 60 | + data-test-id='beacon-status-stop-beacon' |
| 61 | + kind='link' |
| 62 | + onClick={stopBeacon} |
| 63 | + className='mx_BeaconStatus_stopButton' |
| 64 | + >{ _t('Stop') }</AccessibleButton> |
| 65 | + } |
| 66 | + </> |
| 67 | + } |
| 68 | + </div>; |
| 69 | + }; |
| 70 | + |
| 71 | +export default BeaconStatus; |
0 commit comments