From b950480d36a60ac6b8c20f0d215f7bc8c30c0a08 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:22:59 -0700 Subject: [PATCH] Support url-only link previews in stories --- stylesheets/components/StagedLinkPreview.scss | 4 ++ ts/components/TextStoryCreator.tsx | 14 +++--- .../conversation/StagedLinkPreview.tsx | 47 +++++++++++++------ ts/services/LinkPreview.ts | 33 ++++++++++--- ts/state/ducks/linkPreviews.ts | 10 ++-- ts/state/smart/ForwardMessageModal.tsx | 2 +- ts/types/LinkPreview.ts | 11 ++++- ts/views/conversation_view.tsx | 8 ++-- 8 files changed, 92 insertions(+), 37 deletions(-) diff --git a/stylesheets/components/StagedLinkPreview.scss b/stylesheets/components/StagedLinkPreview.scss index 5524e414ec52..240cf8e309ab 100644 --- a/stylesheets/components/StagedLinkPreview.scss +++ b/stylesheets/components/StagedLinkPreview.scss @@ -52,6 +52,10 @@ display: flex; flex-direction: column; margin-right: 20px; + + &--only-url { + justify-content: center; + } } .module-staged-link-preview__title { @include font-body-1-bold; diff --git a/ts/components/TextStoryCreator.tsx b/ts/components/TextStoryCreator.tsx index 22bbd33efb65..67709dbe3a67 100644 --- a/ts/components/TextStoryCreator.tsx +++ b/ts/components/TextStoryCreator.tsx @@ -14,6 +14,7 @@ import type { TextAttachmentType } from '../types/Attachment'; import { Button, ButtonVariant } from './Button'; import { ContextMenu } from './ContextMenu'; import { LinkPreviewSourceType, findLinks } from '../types/LinkPreview'; +import type { MaybeGrabLinkPreviewOptionsType } from '../types/LinkPreview'; import { Input } from './Input'; import { Slider } from './Slider'; import { StagedLinkPreview } from './conversation/StagedLinkPreview'; @@ -31,7 +32,8 @@ import { handleOutsideClick } from '../util/handleOutsideClick'; export type PropsType = { debouncedMaybeGrabLinkPreview: ( message: string, - source: LinkPreviewSourceType + source: LinkPreviewSourceType, + options?: MaybeGrabLinkPreviewOptionsType ) => unknown; i18n: LocalizerType; linkPreview?: LinkPreviewType; @@ -178,7 +180,10 @@ export const TextStoryCreator = ({ } debouncedMaybeGrabLinkPreview( linkPreviewInputValue, - LinkPreviewSourceType.StoryCreator + LinkPreviewSourceType.StoryCreator, + { + mode: 'story', + } ); }, [ debouncedMaybeGrabLinkPreview, @@ -525,12 +530,9 @@ export const TextStoryCreator = ({ {linkPreview ? ( <>