diff --git a/app/soapbox/actions/media.js b/app/soapbox/actions/media.js index daf31c019..1d5a540ce 100644 --- a/app/soapbox/actions/media.js +++ b/app/soapbox/actions/media.js @@ -1,11 +1,34 @@ import api from '../api'; +import { getFeatures } from 'soapbox/utils/features'; const noOp = () => {}; -export function uploadMedia(data, onUploadProgress = noOp) { - return function(dispatch, getState) { +export function uploadMediaV1(data, onUploadProgress = noOp) { + return (dispatch, getState) => { return api(getState).post('/api/v1/media', data, { onUploadProgress: onUploadProgress, }); }; } + +export function uploadMediaV2(data, onUploadProgress = noOp) { + return (dispatch, getState) => { + return api(getState).post('/api/v2/media', data, { + onUploadProgress: onUploadProgress, + }); + }; +} + +export function uploadMedia(data, onUploadProgress = noOp) { + return (dispatch, getState) => { + const state = getState(); + const instance = state.get('instance'); + const features = getFeatures(instance); + + if (features.mediaV2) { + return dispatch(uploadMediaV2(data, onUploadProgress)); + } else { + return dispatch(uploadMediaV1(data, onUploadProgress)); + } + }; +} diff --git a/app/soapbox/components/icon_button.js b/app/soapbox/components/icon_button.js index e892903d7..d7c036f12 100644 --- a/app/soapbox/components/icon_button.js +++ b/app/soapbox/components/icon_button.js @@ -140,7 +140,7 @@ export default class IconButton extends React.PureComponent { ? - {text && {text}} + {text && {text}} ); } @@ -169,7 +169,7 @@ export default class IconButton extends React.PureComponent { ? - {text && {text}} + {text && {text}} )} diff --git a/app/soapbox/features/compose/components/upload.js b/app/soapbox/features/compose/components/upload.js index 4e03d1268..d0d150ca7 100644 --- a/app/soapbox/features/compose/components/upload.js +++ b/app/soapbox/features/compose/components/upload.js @@ -7,6 +7,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import classNames from 'classnames'; import Icon from 'soapbox/components/icon'; +import IconButton from 'soapbox/components/icon_button'; import Blurhash from 'soapbox/components/blurhash'; const MIMETYPE_ICONS = { @@ -153,8 +154,20 @@ class Upload extends ImmutablePureComponent { backgroundPosition: `${x}% ${y}%` }} >
- - {mediaType !== 'unknown' && } + } + /> + + {/* Only display the "Preview" button for a valid attachment with a URL */} + {(mediaType !== 'unknown' && Boolean(media.get('url'))) && ( + } + /> + )}
diff --git a/app/soapbox/utils/features.js b/app/soapbox/utils/features.js index 12ae342f1..4db3dbf6b 100644 --- a/app/soapbox/utils/features.js +++ b/app/soapbox/utils/features.js @@ -26,6 +26,10 @@ export const getFeatures = createSelector([ suggestions: v.software === MASTODON && gte(v.compatVersion, '2.4.3'), suggestionsV2: v.software === MASTODON && gte(v.compatVersion, '3.4.0'), trends: v.software === MASTODON && gte(v.compatVersion, '3.0.0'), + mediaV2: any([ + v.software === MASTODON && gte(v.compatVersion, '3.1.3'), + v.software === PLEROMA && gte(v.version, '2.1.0'), + ]), emojiReacts: v.software === PLEROMA && gte(v.version, '2.0.0'), emojiReactsRGI: v.software === PLEROMA && gte(v.version, '2.2.49'), attachmentLimit: v.software === PLEROMA ? Infinity : 4, diff --git a/app/styles/components/detailed-status.scss b/app/styles/components/detailed-status.scss index bd0ae82a3..094dce139 100644 --- a/app/styles/components/detailed-status.scss +++ b/app/styles/components/detailed-status.scss @@ -86,7 +86,7 @@ display: inline-flex; align-items: center; - .icon_button__text { + &__text { font-size: 14px; padding-left: 5px; } diff --git a/app/styles/ui.scss b/app/styles/ui.scss index 1173bfbca..dfac97c09 100644 --- a/app/styles/ui.scss +++ b/app/styles/ui.scss @@ -1,5 +1,6 @@ .icon-button { - display: inline-block; + display: inline-flex; + align-items: center; padding: 0; color: var(--primary-text-color); border: 0; @@ -12,6 +13,10 @@ margin: 0; } + &__text { + padding-left: 2px; + } + &:hover, &:active, &:focus {