/* Copyright 2020 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 React, { useContext } from 'react'; import classNames from 'classnames'; import { UAContext } from '@quentin-sommer/react-useragent'; import { Client, ClientKind, Platform } from '../clients/types'; import { SafeLink } from '../parser/types'; import Tile from './Tile'; import Button from './Button'; import './ClientTile.scss'; interface IProps { client: Client; link: SafeLink; } const ClientTile: React.FC = ({ client, link }: IProps) => { const inviteLine = client.kind === ClientKind.TEXT_CLIENT ? (

{client.toInviteString(link)}

) : null; const { uaResults } = useContext(UAContext); const className = classNames('clientTile', { clientTileLink: client.kind === ClientKind.LINKED_CLIENT, }); let inviteButton: JSX.Element = <>; let hasNativeClient = false; let installButton = undefined; if (client.kind === ClientKind.LINKED_CLIENT) { const availableClients = client.installLinks.filter((distrib) => { if ((uaResults as any).ios) { return distrib.platform == Platform.iOS; } else if ((uaResults as any).android) { return distrib.platform == Platform.Android; } else { return false; } }); hasNativeClient = availableClients.length > 0; if (hasNativeClient) { inviteButton = ( ); } else { inviteButton = ; } installButton = availableClients.map((distrib) => ( )); } else { const copyString = client.copyString(link); if (copyString !== '') { inviteButton = ( ); } } let clientTile = ( {client.name

{client.name}

{client.description}

{inviteLine} {hasNativeClient && installButton} {inviteButton}
); if (client.kind === ClientKind.LINKED_CLIENT) { if (!hasNativeClient) { clientTile = ( {clientTile} ); } } return clientTile; }; export default ClientTile;