From 9c38c5daa3d7298f02c763a84a74680dcc89dac2 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 29 Oct 2018 04:42:07 +0100 Subject: [PATCH] Fix dimensions of preview cards, fix crash in web UI, fix warning (#9133) --- app/javascript/mastodon/actions/cards.js | 52 ------------------- app/javascript/mastodon/actions/statuses.js | 2 - .../mastodon/components/status_content.js | 3 +- .../features/status/components/card.js | 8 +-- .../status/components/detailed_status.js | 4 +- .../status/containers/card_container.js | 8 --- app/javascript/mastodon/reducers/cards.js | 14 ----- app/javascript/mastodon/reducers/statuses.js | 3 -- 8 files changed, 8 insertions(+), 86 deletions(-) delete mode 100644 app/javascript/mastodon/actions/cards.js delete mode 100644 app/javascript/mastodon/features/status/containers/card_container.js delete mode 100644 app/javascript/mastodon/reducers/cards.js diff --git a/app/javascript/mastodon/actions/cards.js b/app/javascript/mastodon/actions/cards.js deleted file mode 100644 index baf04833a..000000000 --- a/app/javascript/mastodon/actions/cards.js +++ /dev/null @@ -1,52 +0,0 @@ -import api from '../api'; - -export const STATUS_CARD_FETCH_REQUEST = 'STATUS_CARD_FETCH_REQUEST'; -export const STATUS_CARD_FETCH_SUCCESS = 'STATUS_CARD_FETCH_SUCCESS'; -export const STATUS_CARD_FETCH_FAIL = 'STATUS_CARD_FETCH_FAIL'; - -export function fetchStatusCard(id) { - return (dispatch, getState) => { - if (getState().getIn(['cards', id], null) !== null) { - return; - } - - dispatch(fetchStatusCardRequest(id)); - - api(getState).get(`/api/v1/statuses/${id}/card`).then(response => { - if (!response.data.url) { - return; - } - - dispatch(fetchStatusCardSuccess(id, response.data)); - }).catch(error => { - dispatch(fetchStatusCardFail(id, error)); - }); - }; -}; - -export function fetchStatusCardRequest(id) { - return { - type: STATUS_CARD_FETCH_REQUEST, - id, - skipLoading: true, - }; -}; - -export function fetchStatusCardSuccess(id, card) { - return { - type: STATUS_CARD_FETCH_SUCCESS, - id, - card, - skipLoading: true, - }; -}; - -export function fetchStatusCardFail(id, error) { - return { - type: STATUS_CARD_FETCH_FAIL, - id, - error, - skipLoading: true, - skipAlert: true, - }; -}; diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 8d5e72bec..e7c89b4ba 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -3,7 +3,6 @@ import openDB from '../storage/db'; import { evictStatus } from '../storage/modifier'; import { deleteFromTimelines } from './timelines'; -import { fetchStatusCard } from './cards'; import { importFetchedStatus, importFetchedStatuses, importAccount, importStatus } from './importer'; export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST'; @@ -86,7 +85,6 @@ export function fetchStatus(id) { const skipLoading = getState().getIn(['statuses', id], null) !== null; dispatch(fetchContext(id)); - dispatch(fetchStatusCard(id)); if (skipLoading) { return; diff --git a/app/javascript/mastodon/components/status_content.js b/app/javascript/mastodon/components/status_content.js index eda7d6ac3..5e3365618 100644 --- a/app/javascript/mastodon/components/status_content.js +++ b/app/javascript/mastodon/components/status_content.js @@ -159,7 +159,7 @@ export default class StatusContent extends React.PureComponent { } const readMoreButton = ( - ); @@ -197,6 +197,7 @@ export default class StatusContent extends React.PureComponent {
card.get('height') ? (width / ratio) : (width * ratio); + const height = width / ratio; return (
{card.get('title')} : {card.get('title')}; - const ratio = compact ? 16 / 9 : card.get('width') / card.get('height'); - const height = card.get('width') > card.get('height') ? (width / ratio) : (width * ratio); + const ratio = card.get('width') / card.get('height'); + const height = (compact && !embedded) ? (width / (16 / 9)) : (width / ratio); const description = (
diff --git a/app/javascript/mastodon/features/status/components/detailed_status.js b/app/javascript/mastodon/features/status/components/detailed_status.js index b4bbda161..b0dea8817 100644 --- a/app/javascript/mastodon/features/status/components/detailed_status.js +++ b/app/javascript/mastodon/features/status/components/detailed_status.js @@ -8,7 +8,7 @@ import MediaGallery from '../../../components/media_gallery'; import AttachmentList from '../../../components/attachment_list'; import { Link } from 'react-router-dom'; import { FormattedDate, FormattedNumber } from 'react-intl'; -import CardContainer from '../containers/card_container'; +import Card from './card'; import ImmutablePureComponent from 'react-immutable-pure-component'; import Video from '../../video'; @@ -80,7 +80,7 @@ export default class DetailedStatus extends ImmutablePureComponent { ); } } else if (status.get('spoiler_text').length === 0) { - media = ; + media = ; } if (status.get('application')) { diff --git a/app/javascript/mastodon/features/status/containers/card_container.js b/app/javascript/mastodon/features/status/containers/card_container.js deleted file mode 100644 index 6170d9fd8..000000000 --- a/app/javascript/mastodon/features/status/containers/card_container.js +++ /dev/null @@ -1,8 +0,0 @@ -import { connect } from 'react-redux'; -import Card from '../components/card'; - -const mapStateToProps = (state, { statusId }) => ({ - card: state.getIn(['statuses', statusId, 'card'], null), -}); - -export default connect(mapStateToProps)(Card); diff --git a/app/javascript/mastodon/reducers/cards.js b/app/javascript/mastodon/reducers/cards.js deleted file mode 100644 index 4d86b0d7e..000000000 --- a/app/javascript/mastodon/reducers/cards.js +++ /dev/null @@ -1,14 +0,0 @@ -import { STATUS_CARD_FETCH_SUCCESS } from '../actions/cards'; - -import { Map as ImmutableMap, fromJS } from 'immutable'; - -const initialState = ImmutableMap(); - -export default function cards(state = initialState, action) { - switch(action.type) { - case STATUS_CARD_FETCH_SUCCESS: - return state.set(action.id, fromJS(action.card)); - default: - return state; - } -}; diff --git a/app/javascript/mastodon/reducers/statuses.js b/app/javascript/mastodon/reducers/statuses.js index 2c58969f3..6e3d830da 100644 --- a/app/javascript/mastodon/reducers/statuses.js +++ b/app/javascript/mastodon/reducers/statuses.js @@ -10,7 +10,6 @@ import { STATUS_REVEAL, STATUS_HIDE, } from '../actions/statuses'; -import { STATUS_CARD_FETCH_SUCCESS } from '../actions/cards'; import { TIMELINE_DELETE } from '../actions/timelines'; import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer'; import { Map as ImmutableMap, fromJS } from 'immutable'; @@ -66,8 +65,6 @@ export default function statuses(state = initialState, action) { }); case TIMELINE_DELETE: return deleteStatus(state, action.id, action.references); - case STATUS_CARD_FETCH_SUCCESS: - return state.setIn([action.id, 'card'], fromJS(action.card)); default: return state; }