From 6f38b19b5bb1fed3c020d1395d6f34cd5c6c53bd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 21 Aug 2022 11:21:25 -0400 Subject: [PATCH] Restore using embeds from the API --- app/soapbox/components/status-action-bar.tsx | 14 +++-- .../features/ui/components/embed_modal.tsx | 59 ++++++++++++++++--- app/soapbox/utils/features.ts | 6 ++ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/app/soapbox/components/status-action-bar.tsx b/app/soapbox/components/status-action-bar.tsx index 8e8cf17bf..64ac67406 100644 --- a/app/soapbox/components/status-action-bar.tsx +++ b/app/soapbox/components/status-action-bar.tsx @@ -284,7 +284,7 @@ const StatusActionBar: React.FC = ({ const handleEmbed = () => { dispatch(openModal('EMBED', { - status, + url: status.get('url'), onError: (error: any) => dispatch(showAlertForError(error)), })); }; @@ -362,11 +362,13 @@ const StatusActionBar: React.FC = ({ icon: require('@tabler/icons/link.svg'), }); - menu.push({ - text: intl.formatMessage(messages.embed), - action: handleEmbed, - icon: require('@tabler/icons/share.svg'), - }); + if (features.embeds) { + menu.push({ + text: intl.formatMessage(messages.embed), + action: handleEmbed, + icon: require('@tabler/icons/share.svg'), + }); + } } if (!me) { diff --git a/app/soapbox/features/ui/components/embed_modal.tsx b/app/soapbox/features/ui/components/embed_modal.tsx index 6a1127686..0b3be1bc1 100644 --- a/app/soapbox/features/ui/components/embed_modal.tsx +++ b/app/soapbox/features/ui/components/embed_modal.tsx @@ -1,17 +1,52 @@ -import React from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { FormattedMessage } from 'react-intl'; +import api from 'soapbox/api'; import { Modal, Stack, Text, Input } from 'soapbox/components/ui'; +import { useAppDispatch } from 'soapbox/hooks'; -import type { Status } from 'soapbox/types/entities'; +import type { RootState } from 'soapbox/store'; + +const fetchEmbed = (url: string) => { + return (dispatch: any, getState: () => RootState) => { + return api(getState).get('/api/oembed', { params: { url } }); + }; +}; interface IEmbedModal { - status: Status, + url: string, + onError: (error: any) => void, } -const EmbedModal: React.FC = ({ status }) => { - const url = `${location.origin}/embed/${status.id}`; - const embed = `