apply strictnullchecks to src/components/views/beacon/* (#10272)
This commit is contained in:
parent
ffa047be68
commit
de6a1a661c
11 changed files with 48 additions and 30 deletions
|
@ -42,14 +42,14 @@ const BeaconListItem: React.FC<Props & HTMLProps<HTMLLIElement>> = ({ beacon, ..
|
|||
const matrixClient = useContext(MatrixClientContext);
|
||||
const room = matrixClient.getRoom(beacon.roomId);
|
||||
|
||||
if (!latestLocationState || !beacon.isLive) {
|
||||
if (!latestLocationState || !beacon.isLive || !room) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isSelfLocation = beacon.beaconInfo.assetType === LocationAssetType.Self;
|
||||
const beaconMember = isSelfLocation ? room.getMember(beacon.beaconInfoOwner) : undefined;
|
||||
const isSelfLocation = beacon.beaconInfo?.assetType === LocationAssetType.Self;
|
||||
const beaconMember = isSelfLocation ? room.getMember(beacon.beaconInfoOwner) : null;
|
||||
|
||||
const humanizedUpdateTime = humanizeTime(latestLocationState.timestamp);
|
||||
const humanizedUpdateTime = (latestLocationState.timestamp && humanizeTime(latestLocationState.timestamp)) || "";
|
||||
|
||||
return (
|
||||
<li className="mx_BeaconListItem" {...rest}>
|
||||
|
@ -62,7 +62,7 @@ const BeaconListItem: React.FC<Props & HTMLProps<HTMLLIElement>> = ({ beacon, ..
|
|||
<BeaconStatus
|
||||
className="mx_BeaconListItem_status"
|
||||
beacon={beacon}
|
||||
label={beaconMember?.name || beacon.beaconInfo.description || beacon.beaconInfoOwner}
|
||||
label={beaconMember?.name || beacon.beaconInfo?.description || beacon.beaconInfoOwner}
|
||||
displayStatus={BeaconDisplayStatus.Active}
|
||||
>
|
||||
{/* eat events from interactive share buttons
|
||||
|
|
|
@ -27,11 +27,11 @@ interface Props {
|
|||
beacon: Beacon;
|
||||
}
|
||||
|
||||
const useBeaconName = (beacon: Beacon): string => {
|
||||
const useBeaconName = (beacon: Beacon): string | undefined => {
|
||||
const matrixClient = useContext(MatrixClientContext);
|
||||
|
||||
if (beacon.beaconInfo.assetType !== LocationAssetType.Self) {
|
||||
return beacon.beaconInfo.description;
|
||||
if (beacon.beaconInfo?.assetType !== LocationAssetType.Self) {
|
||||
return beacon.beaconInfo?.description;
|
||||
}
|
||||
const room = matrixClient.getRoom(beacon.roomId);
|
||||
const member = room?.getMember(beacon.beaconInfoOwner);
|
||||
|
|
|
@ -54,7 +54,7 @@ interface FocusedBeaconState {
|
|||
beacon?: Beacon;
|
||||
}
|
||||
|
||||
const getBoundsCenter = (bounds: Bounds): string | undefined => {
|
||||
const getBoundsCenter = (bounds?: Bounds): string | undefined => {
|
||||
if (!bounds) {
|
||||
return;
|
||||
}
|
||||
|
@ -70,10 +70,10 @@ const useMapPosition = (
|
|||
{ beacon, ts }: FocusedBeaconState,
|
||||
): {
|
||||
bounds?: Bounds;
|
||||
centerGeoUri: string;
|
||||
centerGeoUri?: string;
|
||||
} => {
|
||||
const [bounds, setBounds] = useState<Bounds | undefined>(getBeaconBounds(liveBeacons));
|
||||
const [centerGeoUri, setCenterGeoUri] = useState<string>(
|
||||
const [centerGeoUri, setCenterGeoUri] = useState<string | undefined>(
|
||||
beacon?.latestLocationState?.uri || getBoundsCenter(bounds),
|
||||
);
|
||||
|
||||
|
|
|
@ -45,12 +45,12 @@ const DialogOwnBeaconStatus: React.FC<Props> = ({ roomId }) => {
|
|||
const matrixClient = useContext(MatrixClientContext);
|
||||
const room = matrixClient.getRoom(roomId);
|
||||
|
||||
if (!beacon?.isLive) {
|
||||
if (!beacon?.isLive || !room) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isSelfLocation = beacon.beaconInfo.assetType === LocationAssetType.Self;
|
||||
const beaconMember = isSelfLocation ? room.getMember(beacon.beaconInfoOwner) : undefined;
|
||||
const isSelfLocation = beacon.beaconInfo?.assetType === LocationAssetType.Self;
|
||||
const beaconMember = isSelfLocation ? room.getMember(beacon.beaconInfoOwner) : null;
|
||||
|
||||
return (
|
||||
<div className="mx_DialogOwnBeaconStatus">
|
||||
|
|
|
@ -25,7 +25,7 @@ import { Icon as LiveLocationIcon } from "../../../../res/img/location/live-loca
|
|||
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
||||
import { Action } from "../../../dispatcher/actions";
|
||||
import dispatcher from "../../../dispatcher/dispatcher";
|
||||
import AccessibleButton from "../elements/AccessibleButton";
|
||||
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
|
||||
|
||||
interface Props {
|
||||
isMinimized?: boolean;
|
||||
|
@ -121,7 +121,7 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
|
|||
);
|
||||
|
||||
const onWarningClick = relevantBeacon
|
||||
? () => {
|
||||
? (_e: ButtonEvent) => {
|
||||
dispatcher.dispatch<ViewRoomPayload>({
|
||||
action: Action.ViewRoom,
|
||||
room_id: relevantBeacon.roomId,
|
||||
|
@ -131,7 +131,7 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
|
|||
highlighted: true,
|
||||
});
|
||||
}
|
||||
: undefined;
|
||||
: null;
|
||||
|
||||
const label = getLabel(hasStoppingErrors, hasLocationPublishErrors);
|
||||
|
||||
|
|
|
@ -40,13 +40,19 @@ const getUpdateInterval = (ms: number): number => {
|
|||
const useMsRemaining = (beacon: Beacon): number => {
|
||||
const beaconInfo = useEventEmitterState(beacon, BeaconEvent.Update, () => beacon.beaconInfo);
|
||||
|
||||
const [msRemaining, setMsRemaining] = useState(() => getBeaconMsUntilExpiry(beaconInfo));
|
||||
const [msRemaining, setMsRemaining] = useState(() => (beaconInfo ? getBeaconMsUntilExpiry(beaconInfo) : 0));
|
||||
|
||||
useEffect(() => {
|
||||
if (!beaconInfo) {
|
||||
return;
|
||||
}
|
||||
setMsRemaining(getBeaconMsUntilExpiry(beaconInfo));
|
||||
}, [beaconInfo]);
|
||||
|
||||
const updateMsRemaining = useCallback(() => {
|
||||
if (!beaconInfo) {
|
||||
return;
|
||||
}
|
||||
const ms = getBeaconMsUntilExpiry(beaconInfo);
|
||||
setMsRemaining(ms);
|
||||
}, [beaconInfo]);
|
||||
|
|
|
@ -42,7 +42,7 @@ const OwnBeaconStatus: React.FC<Props & HTMLProps<HTMLDivElement>> = ({ beacon,
|
|||
stoppingInProgress,
|
||||
onStopSharing,
|
||||
onResetLocationPublishError,
|
||||
} = useOwnLiveBeacons([beacon?.identifier]);
|
||||
} = 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;
|
||||
|
|
|
@ -28,9 +28,9 @@ interface Props {
|
|||
}
|
||||
|
||||
const ShareLatestLocation: React.FC<Props> = ({ latestLocationState }) => {
|
||||
const [coords, setCoords] = useState(null);
|
||||
const [coords, setCoords] = useState<GeolocationCoordinates | undefined>();
|
||||
useEffect(() => {
|
||||
if (!latestLocationState) {
|
||||
if (!latestLocationState?.uri) {
|
||||
return;
|
||||
}
|
||||
const coords = parseGeoUri(latestLocationState.uri);
|
||||
|
|
|
@ -40,7 +40,5 @@ export const getBeaconDisplayStatus = (
|
|||
if (!latestLocationState) {
|
||||
return BeaconDisplayStatus.Loading;
|
||||
}
|
||||
if (latestLocationState) {
|
||||
return BeaconDisplayStatus.Active;
|
||||
}
|
||||
return BeaconDisplayStatus.Active;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue