[Glitch] Add support for editing media description and focus point of already-posted statuses
Port 4b92e59f4f
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
pull/53/head
parent
9b4afb320a
commit
b5c6a116a7
|
@ -181,6 +181,18 @@ export function submitCompose(routerHistory) {
|
||||||
|
|
||||||
dispatch(submitComposeRequest());
|
dispatch(submitComposeRequest());
|
||||||
|
|
||||||
|
// If we're editing a post with media attachments, those have not
|
||||||
|
// necessarily been changed on the server. Do it now in the same
|
||||||
|
// API call.
|
||||||
|
let media_attributes;
|
||||||
|
if (statusId !== null) {
|
||||||
|
media_attributes = media.map(item => ({
|
||||||
|
id: item.get('id'),
|
||||||
|
description: item.get('description'),
|
||||||
|
focus: item.get('focus'),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
api(getState).request({
|
api(getState).request({
|
||||||
url: statusId === null ? '/api/v1/statuses' : `/api/v1/statuses/${statusId}`,
|
url: statusId === null ? '/api/v1/statuses' : `/api/v1/statuses/${statusId}`,
|
||||||
method: statusId === null ? 'post' : 'put',
|
method: statusId === null ? 'post' : 'put',
|
||||||
|
@ -189,6 +201,7 @@ export function submitCompose(routerHistory) {
|
||||||
content_type: getState().getIn(['compose', 'content_type']),
|
content_type: getState().getIn(['compose', 'content_type']),
|
||||||
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
|
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
|
||||||
media_ids: media.map(item => item.get('id')),
|
media_ids: media.map(item => item.get('id')),
|
||||||
|
media_attributes,
|
||||||
sensitive: getState().getIn(['compose', 'sensitive']) || (spoilerText.length > 0 && media.size !== 0),
|
sensitive: getState().getIn(['compose', 'sensitive']) || (spoilerText.length > 0 && media.size !== 0),
|
||||||
spoiler_text: spoilerText,
|
spoiler_text: spoilerText,
|
||||||
visibility: getState().getIn(['compose', 'privacy']),
|
visibility: getState().getIn(['compose', 'privacy']),
|
||||||
|
@ -415,11 +428,31 @@ export function changeUploadCompose(id, params) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(changeUploadComposeRequest());
|
dispatch(changeUploadComposeRequest());
|
||||||
|
|
||||||
api(getState).put(`/api/v1/media/${id}`, params).then(response => {
|
let media = getState().getIn(['compose', 'media_attachments']).find((item) => item.get('id') === id);
|
||||||
dispatch(changeUploadComposeSuccess(response.data));
|
|
||||||
}).catch(error => {
|
// Editing already-attached media is deferred to editing the post itself.
|
||||||
dispatch(changeUploadComposeFail(id, error));
|
// For simplicity's sake, fake an API reply.
|
||||||
});
|
if (media && !media.get('unattached')) {
|
||||||
|
let { description, focus } = params;
|
||||||
|
const data = media.toJS();
|
||||||
|
|
||||||
|
if (description) {
|
||||||
|
data.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (focus) {
|
||||||
|
focus = focus.split(',');
|
||||||
|
data.meta = { focus: { x: parseFloat(focus[0]), y: parseFloat(focus[1]) } };
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(changeUploadComposeSuccess(data, true));
|
||||||
|
} else {
|
||||||
|
api(getState).put(`/api/v1/media/${id}`, params).then(response => {
|
||||||
|
dispatch(changeUploadComposeSuccess(response.data, false));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(changeUploadComposeFail(id, error));
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -430,10 +463,11 @@ export function changeUploadComposeRequest() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function changeUploadComposeSuccess(media) {
|
export function changeUploadComposeSuccess(media, attached) {
|
||||||
return {
|
return {
|
||||||
type: COMPOSE_UPLOAD_CHANGE_SUCCESS,
|
type: COMPOSE_UPLOAD_CHANGE_SUCCESS,
|
||||||
media: media,
|
media: media,
|
||||||
|
attached: attached,
|
||||||
skipLoading: true,
|
skipLoading: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,13 +43,13 @@ export default class Upload extends ImmutablePureComponent {
|
||||||
{({ scale }) => (
|
{({ scale }) => (
|
||||||
<div className='compose-form__upload-thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})`, backgroundPosition: `${x}% ${y}%` }}>
|
<div className='compose-form__upload-thumbnail' style={{ transform: `scale(${scale})`, backgroundImage: `url(${media.get('preview_url')})`, backgroundPosition: `${x}% ${y}%` }}>
|
||||||
<div className='compose-form__upload__actions'>
|
<div className='compose-form__upload__actions'>
|
||||||
<button className='icon-button' onClick={this.handleUndoClick}><Icon id='times' /> <FormattedMessage id='upload_form.undo' defaultMessage='Delete' /></button>
|
<button type='button' className='icon-button' onClick={this.handleUndoClick}><Icon id='times' /> <FormattedMessage id='upload_form.undo' defaultMessage='Delete' /></button>
|
||||||
{!!media.get('unattached') && (<button className='icon-button' onClick={this.handleFocalPointClick}><Icon id='pencil' /> <FormattedMessage id='upload_form.edit' defaultMessage='Edit' /></button>)}
|
<button type='button' className='icon-button' onClick={this.handleFocalPointClick}><Icon id='pencil' /> <FormattedMessage id='upload_form.edit' defaultMessage='Edit' /></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{(media.get('description') || '').length === 0 && !!media.get('unattached') && (
|
{(media.get('description') || '').length === 0 && (
|
||||||
<div className='compose-form__upload__warning'>
|
<div className='compose-form__upload__warning'>
|
||||||
<button className='icon-button' onClick={this.handleFocalPointClick}><Icon id='info-circle' /> <FormattedMessage id='upload_form.description_missing' defaultMessage='No description added' /></button>
|
<button type='button' className='icon-button' onClick={this.handleFocalPointClick}><Icon id='info-circle' /> <FormattedMessage id='upload_form.description_missing' defaultMessage='No description added' /></button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -320,7 +320,7 @@ class FocalPointModal extends ImmutablePureComponent {
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<label className='setting-text-label' htmlFor='upload-modal__thumbnail'><FormattedMessage id='upload_form.thumbnail' defaultMessage='Change thumbnail' /></label>
|
<label className='setting-text-label' htmlFor='upload-modal__thumbnail'><FormattedMessage id='upload_form.thumbnail' defaultMessage='Change thumbnail' /></label>
|
||||||
|
|
||||||
<Button disabled={isUploadingThumbnail} text={intl.formatMessage(messages.chooseImage)} onClick={this.handleFileInputClick} />
|
<Button disabled={isUploadingThumbnail || !media.get('unattached')} text={intl.formatMessage(messages.chooseImage)} onClick={this.handleFileInputClick} />
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<span style={{ display: 'none' }}>{intl.formatMessage(messages.chooseImage)}</span>
|
<span style={{ display: 'none' }}>{intl.formatMessage(messages.chooseImage)}</span>
|
||||||
|
|
|
@ -551,7 +551,7 @@ export default function compose(state = initialState, action) {
|
||||||
.setIn(['media_modal', 'dirty'], false)
|
.setIn(['media_modal', 'dirty'], false)
|
||||||
.update('media_attachments', list => list.map(item => {
|
.update('media_attachments', list => list.map(item => {
|
||||||
if (item.get('id') === action.media.id) {
|
if (item.get('id') === action.media.id) {
|
||||||
return fromJS(action.media).set('unattached', true);
|
return fromJS(action.media).set('unattached', !action.attached);
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
|
Loading…
Reference in New Issue