From 37a8bc70837aaaf60b21717e7d4b79c4342ab166 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 10 Apr 2022 17:52:42 -0500 Subject: [PATCH] WIP: embeds --- .../features/status/components/action-bar.tsx | 13 ++++++++----- .../features/ui/components/embed_modal.js | 19 ++++++++++++++----- app/soapbox/utils/features.ts | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/soapbox/features/status/components/action-bar.tsx b/app/soapbox/features/status/components/action-bar.tsx index 1e5efa765..bc9ff3bc8 100644 --- a/app/soapbox/features/status/components/action-bar.tsx +++ b/app/soapbox/features/status/components/action-bar.tsx @@ -368,11 +368,14 @@ class ActionBar extends React.PureComponent { action: this.handleCopy, icon: require('@tabler/icons/icons/link.svg'), }); - // menu.push({ - // text: intl.formatMessage(messages.embed), - // action: this.handleEmbed, - // icon: require('feather-icons/dist/icons/link-2.svg'), - // }); + + if (features.embeds) { + menu.push({ + text: intl.formatMessage(messages.embed), + action: this.handleEmbed, + icon: require('feather-icons/dist/icons/link-2.svg'), + }); + } } if (me) { diff --git a/app/soapbox/features/ui/components/embed_modal.js b/app/soapbox/features/ui/components/embed_modal.js index 6d10ee5bc..dde549af1 100644 --- a/app/soapbox/features/ui/components/embed_modal.js +++ b/app/soapbox/features/ui/components/embed_modal.js @@ -1,10 +1,13 @@ -import axios from 'axios'; import PropTypes from 'prop-types'; import React from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { FormattedMessage, injectIntl } from 'react-intl'; +import { connect } from 'react-redux'; -export default @injectIntl +import api from 'soapbox/api'; + +export default @connect() +@injectIntl class EmbedModal extends ImmutablePureComponent { static propTypes = { @@ -19,12 +22,18 @@ class EmbedModal extends ImmutablePureComponent { oembed: null, }; - componentDidMount() { - const { url } = this.props; + fetchEmbed = () => { + const { dispatch, url } = this.props; + return dispatch((dispatch, getState) => { + return api(getState).get('/api/oembed', { params: { url } }); + }); + } + + componentDidMount() { this.setState({ loading: true }); - axios.post('/api/web/embed', { url }).then(res => { + this.fetchEmbed().then(res => { this.setState({ loading: false, oembed: res.data }); const iframeDocument = this.iframe.contentWindow.document; diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index 93529f21e..39c2df262 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -30,6 +30,7 @@ const getInstanceFeatures = (instance: Instance) => { privacyScopes: v.software !== TRUTHSOCIAL, spoilers: v.software !== TRUTHSOCIAL, filters: v.software !== TRUTHSOCIAL, + embeds: v.software === MASTODON, polls: any([ v.software === MASTODON && gte(v.version, '2.8.0'), v.software === PLEROMA,