From b21615e9579a6f33ed1cdf6fc37fc8a1ff24a0d5 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 29 Oct 2018 14:56:53 +0100 Subject: [Glitch] Fix dimensions of preview cards, fix crash in web UI, fix warning Port 9c38c5daa3d7298f02c763a84a74680dcc89dac2 to glitch-soc --- app/javascript/flavours/glitch/actions/cards.js | 52 ---------------------- app/javascript/flavours/glitch/actions/statuses.js | 2 - .../glitch/features/status/components/card.js | 8 ++-- .../features/status/components/detailed_status.js | 4 +- .../features/status/containers/card_container.js | 8 ---- app/javascript/flavours/glitch/reducers/cards.js | 14 ------ .../flavours/glitch/reducers/statuses.js | 5 --- 7 files changed, 6 insertions(+), 87 deletions(-) delete mode 100644 app/javascript/flavours/glitch/actions/cards.js delete mode 100644 app/javascript/flavours/glitch/features/status/containers/card_container.js delete mode 100644 app/javascript/flavours/glitch/reducers/cards.js (limited to 'app/javascript') diff --git a/app/javascript/flavours/glitch/actions/cards.js b/app/javascript/flavours/glitch/actions/cards.js deleted file mode 100644 index c897daf58..000000000 --- a/app/javascript/flavours/glitch/actions/cards.js +++ /dev/null @@ -1,52 +0,0 @@ -import api from 'flavours/glitch/util/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/flavours/glitch/actions/statuses.js b/app/javascript/flavours/glitch/actions/statuses.js index fa8845002..6183f3c03 100644 --- a/app/javascript/flavours/glitch/actions/statuses.js +++ b/app/javascript/flavours/glitch/actions/statuses.js @@ -1,7 +1,6 @@ import api from 'flavours/glitch/util/api'; import { deleteFromTimelines } from './timelines'; -import { fetchStatusCard } from './cards'; export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST'; export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS'; @@ -38,7 +37,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/flavours/glitch/features/status/components/card.js b/app/javascript/flavours/glitch/features/status/components/card.js index 9a87f7a3f..743fe779a 100644 --- a/app/javascript/flavours/glitch/features/status/components/card.js +++ b/app/javascript/flavours/glitch/features/status/components/card.js @@ -59,7 +59,7 @@ export default class Card extends React.PureComponent { card: ImmutablePropTypes.map, maxDescription: PropTypes.number, onOpenMedia: PropTypes.func.isRequired, - compact: PropTypes.boolean, + compact: PropTypes.bool, }; static defaultProps = { @@ -120,7 +120,7 @@ export default class Card extends React.PureComponent { const content = { __html: addAutoPlay(card.get('html')) }; const { width } = this.state; const ratio = card.get('width') / card.get('height'); - const height = card.get('width') > 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/flavours/glitch/features/status/components/detailed_status.js b/app/javascript/flavours/glitch/features/status/components/detailed_status.js index 2e61e6d8c..1fe0c069d 100644 --- a/app/javascript/flavours/glitch/features/status/components/detailed_status.js +++ b/app/javascript/flavours/glitch/features/status/components/detailed_status.js @@ -8,7 +8,7 @@ import MediaGallery from 'flavours/glitch/components/media_gallery'; import AttachmentList from 'flavours/glitch/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 'flavours/glitch/features/video'; import VisibilityIcon from 'flavours/glitch/components/status_visibility_icon'; @@ -83,7 +83,7 @@ export default class DetailedStatus extends ImmutablePureComponent { ); mediaIcon = 'picture-o'; } - } else media = ; + } else media = ; if (status.get('application')) { applicationLink = ยท {status.getIn(['application', 'name'])}; diff --git a/app/javascript/flavours/glitch/features/status/containers/card_container.js b/app/javascript/flavours/glitch/features/status/containers/card_container.js deleted file mode 100644 index 6170d9fd8..000000000 --- a/app/javascript/flavours/glitch/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/flavours/glitch/reducers/cards.js b/app/javascript/flavours/glitch/reducers/cards.js deleted file mode 100644 index 92ecfd086..000000000 --- a/app/javascript/flavours/glitch/reducers/cards.js +++ /dev/null @@ -1,14 +0,0 @@ -import { STATUS_CARD_FETCH_SUCCESS } from 'flavours/glitch/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/flavours/glitch/reducers/statuses.js b/app/javascript/flavours/glitch/reducers/statuses.js index 4c6387461..617d96e5d 100644 --- a/app/javascript/flavours/glitch/reducers/statuses.js +++ b/app/javascript/flavours/glitch/reducers/statuses.js @@ -23,9 +23,6 @@ import { STATUS_MUTE_SUCCESS, STATUS_UNMUTE_SUCCESS, } from 'flavours/glitch/actions/statuses'; -import { - STATUS_CARD_FETCH_SUCCESS -} from 'flavours/glitch/actions/cards'; import { TIMELINE_UPDATE, TIMELINE_DELETE, @@ -146,8 +143,6 @@ export default function statuses(state = initialState, action) { return normalizeStatuses(state, action.statuses); 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; } -- cgit