session-desktop/ts/components/conversation/StagedLinkPreview.tsx
Audric Ackermann c92baad736
Fix path building (#1903)
* Keep line breaks when message has some new lines

Relates #1758 and #1898 and #1901

* fix link preview cropped when received

* make sure we fetch from seed if we end up with not enough snodes

* try to download recent previews if we just trusted a user

* throw if we need to rebuild path while fetching snode list from snode

* fixup no refecthing of snode list while we are fetching them already

* added test for fetch from db or seed

* fetch snode list from snode every hour

also make sure the path building does not try to get more snodes. It
just throws

* do not drop a path if an opengroup room is down and we get errors  back

* do not throw an error if the snode in error in not in any path

* fix tests

* bump to v1.7.11
2021-09-13 17:07:53 +10:00

72 lines
2 KiB
TypeScript

import React from 'react';
import classNames from 'classnames';
import { Image } from './Image';
import { AttachmentType, isImageAttachment } from '../../types/Attachment';
import { SessionSpinner } from '../session/SessionSpinner';
type Props = {
isLoaded: boolean;
title: null | string;
url: null | string;
description: null | string;
domain: null | string;
image?: AttachmentType;
onClose: (url: string) => void;
};
export const StagedLinkPreview = (props: Props) => {
const { isLoaded, onClose, title, image, domain, description, url } = props;
const isImage = image && isImageAttachment(image);
if (isLoaded && !(title && domain)) {
return <></>;
}
const isLoading = !isLoaded;
return (
<div
className={classNames(
'module-staged-link-preview',
isLoading ? 'module-staged-link-preview--is-loading' : null
)}
>
{isLoading ? <SessionSpinner loading={isLoading} /> : null}
{isLoaded && image && isImage ? (
<div className="module-staged-link-preview__icon-container">
<Image
alt={window.i18n('stagedPreviewThumbnail', [domain])}
softCorners={true}
height={72}
width={72}
url={image.url}
attachment={image}
/>
</div>
) : null}
{isLoaded ? (
<div className="module-staged-link-preview__content">
<div className="module-staged-link-preview__title">{title}</div>
{description && (
<div className="module-staged-link-preview__description">{description}</div>
)}
<div className="module-staged-link-preview__footer">
<div className="module-staged-link-preview__location">{domain}</div>
</div>
</div>
) : null}
<button
type="button"
className="module-staged-link-preview__close-button"
onClick={() => {
onClose(url || '');
}}
aria-label={window.i18n('close')}
/>
</div>
);
};