import React, { ReactNode } from 'react'; import { Box, Text, IconButton, Icon, Icons, Scroll } from 'folds'; import { Page, PageContent, PageHeader } from '../../../components/page'; import { SequenceCard } from '../../../components/sequence-card'; import { SequenceCardStyle } from '../styles.css'; import { SettingTile } from '../../../components/setting-tile'; import { useDeviceIds, useDeviceList, useSplitCurrentDevice } from '../../../hooks/useDeviceList'; import { useMatrixClient } from '../../../hooks/useMatrixClient'; import { LocalBackup } from './LocalBackup'; import { DeviceLogoutBtn, DeviceKeyDetails, DeviceTile, DeviceTilePlaceholder } from './DeviceTile'; import { OtherDevices } from './OtherDevices'; import { DeviceVerificationOptions, EnableVerification, VerificationStatusBadge, VerifyCurrentDeviceTile, } from './Verification'; import { useDeviceVerificationStatus, useUnverifiedDeviceCount, VerificationStatus, } from '../../../hooks/useDeviceVerificationStatus'; import { useSecretStorageDefaultKeyId, useSecretStorageKeyContent, } from '../../../hooks/useSecretStorage'; import { useCrossSigningActive } from '../../../hooks/useCrossSigning'; import { BackupRestoreTile } from '../../../components/BackupRestore'; function DevicesPlaceholder() { return ( ); } type DevicesProps = { requestClose: () => void; /** [Gitea #459] Shown as the page title (the menu entry's name). */ title?: string; /** [Gitea #459] Sections shown above this page's own. */ before?: ReactNode; }; export function Devices({ requestClose, title, before }: DevicesProps) { const mx = useMatrixClient(); const crypto = mx.getCrypto(); const crossSigningActive = useCrossSigningActive(); const [devices, refreshDeviceList] = useDeviceList(); const [currentDevice, otherDevices] = useSplitCurrentDevice(devices); const verificationStatus = useDeviceVerificationStatus( crypto, mx.getSafeUserId(), currentDevice?.device_id, ); const otherDevicesId = useDeviceIds(otherDevices); const unverifiedDeviceCount = useUnverifiedDeviceCount( crypto, mx.getSafeUserId(), otherDevicesId, ); const defaultSecretStorageKeyId = useSecretStorageDefaultKeyId(); const defaultSecretStorageKeyContent = useSecretStorageKeyContent( defaultSecretStorageKeyId ?? '', ); return ( {title ?? 'Devices'} {before} Security {crossSigningActive && ( )} } /> Current {currentDevice ? ( } > {crypto && } {crossSigningActive && verificationStatus === VerificationStatus.Unverified && defaultSecretStorageKeyId && defaultSecretStorageKeyContent && ( )} {crypto && verificationStatus === VerificationStatus.Verified && ( )} ) : ( )} {devices === undefined && } {otherDevices && ( )} ); }