Don't clear manually applied link preview
This commit is contained in:
parent
8899ca9724
commit
a040330d89
1 changed files with 33 additions and 6 deletions
|
@ -38,6 +38,12 @@ export type PropsType = {
|
||||||
onDone: (textAttachment: TextAttachmentType) => unknown;
|
onDone: (textAttachment: TextAttachmentType) => unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum LinkPreviewApplied {
|
||||||
|
None = 'None',
|
||||||
|
Automatic = 'Automatic',
|
||||||
|
Manual = 'Manual',
|
||||||
|
}
|
||||||
|
|
||||||
enum TextStyle {
|
enum TextStyle {
|
||||||
Default,
|
Default,
|
||||||
Regular,
|
Regular,
|
||||||
|
@ -152,25 +158,38 @@ export const TextStoryCreator = ({
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const [hasLinkPreviewApplied, setHasLinkPreviewApplied] = useState(false);
|
const [linkPreviewApplied, setLinkPreviewApplied] = useState(
|
||||||
|
LinkPreviewApplied.None
|
||||||
|
);
|
||||||
|
const hasLinkPreviewApplied = linkPreviewApplied !== LinkPreviewApplied.None;
|
||||||
const [linkPreviewInputValue, setLinkPreviewInputValue] = useState('');
|
const [linkPreviewInputValue, setLinkPreviewInputValue] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!linkPreviewInputValue) {
|
if (!linkPreviewInputValue) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (linkPreviewApplied === LinkPreviewApplied.Manual) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
debouncedMaybeGrabLinkPreview(
|
debouncedMaybeGrabLinkPreview(
|
||||||
linkPreviewInputValue,
|
linkPreviewInputValue,
|
||||||
LinkPreviewSourceType.StoryCreator
|
LinkPreviewSourceType.StoryCreator
|
||||||
);
|
);
|
||||||
}, [debouncedMaybeGrabLinkPreview, linkPreviewInputValue]);
|
}, [
|
||||||
|
debouncedMaybeGrabLinkPreview,
|
||||||
|
linkPreviewApplied,
|
||||||
|
linkPreviewInputValue,
|
||||||
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (linkPreviewApplied === LinkPreviewApplied.Manual) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
debouncedMaybeGrabLinkPreview(text, LinkPreviewSourceType.StoryCreator);
|
debouncedMaybeGrabLinkPreview(text, LinkPreviewSourceType.StoryCreator);
|
||||||
}, [debouncedMaybeGrabLinkPreview, text]);
|
}, [debouncedMaybeGrabLinkPreview, linkPreviewApplied, text]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!linkPreview || !text) {
|
if (!linkPreview || !text) {
|
||||||
|
@ -180,7 +199,15 @@ export const TextStoryCreator = ({
|
||||||
const links = findLinks(text);
|
const links = findLinks(text);
|
||||||
|
|
||||||
const shouldApplyLinkPreview = links.includes(linkPreview.url);
|
const shouldApplyLinkPreview = links.includes(linkPreview.url);
|
||||||
setHasLinkPreviewApplied(shouldApplyLinkPreview);
|
setLinkPreviewApplied(oldValue => {
|
||||||
|
if (oldValue === LinkPreviewApplied.Manual) {
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
if (shouldApplyLinkPreview) {
|
||||||
|
return LinkPreviewApplied.Automatic;
|
||||||
|
}
|
||||||
|
return LinkPreviewApplied.None;
|
||||||
|
});
|
||||||
}, [linkPreview, text]);
|
}, [linkPreview, text]);
|
||||||
|
|
||||||
const [isLinkPreviewInputShowing, setIsLinkPreviewInputShowing] =
|
const [isLinkPreviewInputShowing, setIsLinkPreviewInputShowing] =
|
||||||
|
@ -286,7 +313,7 @@ export const TextStoryCreator = ({
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onRemoveLinkPreview={() => {
|
onRemoveLinkPreview={() => {
|
||||||
setHasLinkPreviewApplied(false);
|
setLinkPreviewApplied(LinkPreviewApplied.None);
|
||||||
}}
|
}}
|
||||||
textAttachment={textAttachment}
|
textAttachment={textAttachment}
|
||||||
/>
|
/>
|
||||||
|
@ -495,7 +522,7 @@ export const TextStoryCreator = ({
|
||||||
<Button
|
<Button
|
||||||
className="StoryCreator__link-preview-button"
|
className="StoryCreator__link-preview-button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setHasLinkPreviewApplied(true);
|
setLinkPreviewApplied(LinkPreviewApplied.Manual);
|
||||||
setIsLinkPreviewInputShowing(false);
|
setIsLinkPreviewInputShowing(false);
|
||||||
}}
|
}}
|
||||||
theme={Theme.Dark}
|
theme={Theme.Dark}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue