Files
element-web/src/components/views/beacon/displayStatus.ts
Kerry 2bdb4d396a Live location share - show loading UI for beacons with start timestamp in the future (PSF-1081) (#8775)
* check for beacons that are yet to start and show loading ui

Signed-off-by: Kerry Archibald <kerrya@element.io>

* update snapshots for js-sdk rename

Signed-off-by: Kerry Archibald <kerrya@element.io>

* remove debug

Signed-off-by: Kerry Archibald <kerrya@element.io>

* Update test/components/views/messages/MBeaconBody-test.tsx

Co-authored-by: Travis Ralston <travisr@matrix.org>

* Update src/components/views/beacon/displayStatus.ts

Co-authored-by: Travis Ralston <travisr@matrix.org>

Co-authored-by: Travis Ralston <travisr@matrix.org>
2022-06-09 13:25:30 +01:00

47 lines
1.3 KiB
TypeScript

/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { BeaconLocationState } from "matrix-js-sdk/src/content-helpers";
export enum BeaconDisplayStatus {
Loading = 'Loading',
Error = 'Error',
Stopped = 'Stopped',
Active = 'Active',
}
export const getBeaconDisplayStatus = (
isLive: boolean,
latestLocationState?: BeaconLocationState,
error?: Error,
waitingToStart?: boolean,
): BeaconDisplayStatus => {
if (error) {
return BeaconDisplayStatus.Error;
}
if (waitingToStart) {
return BeaconDisplayStatus.Loading;
}
if (!isLive) {
return BeaconDisplayStatus.Stopped;
}
if (!latestLocationState) {
return BeaconDisplayStatus.Loading;
}
if (latestLocationState) {
return BeaconDisplayStatus.Active;
}
};