[Glitch] Fixes being unable to edit an attachment twice without submitting
Port 3109a5a4d8612ba2d9468a2151cafbe738598099 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
5dfb14f518
commit
ddfb2ea968
@ -64,10 +64,6 @@ export const COMPOSE_LANGUAGE_CHANGE = 'COMPOSE_LANGUAGE_CHANGE';
|
|||||||
|
|
||||||
export const COMPOSE_EMOJI_INSERT = 'COMPOSE_EMOJI_INSERT';
|
export const COMPOSE_EMOJI_INSERT = 'COMPOSE_EMOJI_INSERT';
|
||||||
|
|
||||||
export const COMPOSE_UPLOAD_CHANGE_REQUEST = 'COMPOSE_UPLOAD_UPDATE_REQUEST';
|
|
||||||
export const COMPOSE_UPLOAD_CHANGE_SUCCESS = 'COMPOSE_UPLOAD_UPDATE_SUCCESS';
|
|
||||||
export const COMPOSE_UPLOAD_CHANGE_FAIL = 'COMPOSE_UPLOAD_UPDATE_FAIL';
|
|
||||||
|
|
||||||
export const COMPOSE_DOODLE_SET = 'COMPOSE_DOODLE_SET';
|
export const COMPOSE_DOODLE_SET = 'COMPOSE_DOODLE_SET';
|
||||||
|
|
||||||
export const COMPOSE_POLL_ADD = 'COMPOSE_POLL_ADD';
|
export const COMPOSE_POLL_ADD = 'COMPOSE_POLL_ADD';
|
||||||
@ -495,58 +491,6 @@ export function onChangeMediaFocus(focusX, focusY) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeUploadCompose(id, params) {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
dispatch(changeUploadComposeRequest());
|
|
||||||
|
|
||||||
let media = getState().getIn(['compose', 'media_attachments']).find((item) => item.get('id') === id);
|
|
||||||
|
|
||||||
// Editing already-attached media is deferred to editing the post itself.
|
|
||||||
// For simplicity's sake, fake an API reply.
|
|
||||||
if (media && !media.get('unattached')) {
|
|
||||||
const { focus, ...other } = params;
|
|
||||||
const data = { ...media.toJS(), ...other };
|
|
||||||
|
|
||||||
if (focus) {
|
|
||||||
const [x, y] = focus.split(',');
|
|
||||||
data.meta = { focus: { x: parseFloat(x), y: parseFloat(y) } };
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(changeUploadComposeSuccess(data, true));
|
|
||||||
} else {
|
|
||||||
api().put(`/api/v1/media/${id}`, params).then(response => {
|
|
||||||
dispatch(changeUploadComposeSuccess(response.data, false));
|
|
||||||
}).catch(error => {
|
|
||||||
dispatch(changeUploadComposeFail(id, error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeUploadComposeRequest() {
|
|
||||||
return {
|
|
||||||
type: COMPOSE_UPLOAD_CHANGE_REQUEST,
|
|
||||||
skipLoading: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeUploadComposeSuccess(media, attached) {
|
|
||||||
return {
|
|
||||||
type: COMPOSE_UPLOAD_CHANGE_SUCCESS,
|
|
||||||
media: media,
|
|
||||||
attached: attached,
|
|
||||||
skipLoading: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeUploadComposeFail(error) {
|
|
||||||
return {
|
|
||||||
type: COMPOSE_UPLOAD_CHANGE_FAIL,
|
|
||||||
error: error,
|
|
||||||
skipLoading: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function uploadComposeRequest() {
|
export function uploadComposeRequest() {
|
||||||
return {
|
return {
|
||||||
type: COMPOSE_UPLOAD_REQUEST,
|
type: COMPOSE_UPLOAD_REQUEST,
|
||||||
|
|||||||
@ -49,7 +49,7 @@ const messages = defineMessages({
|
|||||||
});
|
});
|
||||||
|
|
||||||
type SimulatedMediaAttachmentJSON = ApiMediaAttachmentJSON & {
|
type SimulatedMediaAttachmentJSON = ApiMediaAttachmentJSON & {
|
||||||
unattached?: boolean;
|
attached?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const simulateModifiedApiResponse = (
|
const simulateModifiedApiResponse = (
|
||||||
@ -67,7 +67,8 @@ const simulateModifiedApiResponse = (
|
|||||||
y: parseFloat(y ?? '0'),
|
y: parseFloat(y ?? '0'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as unknown as SimulatedMediaAttachmentJSON;
|
attached: true,
|
||||||
|
} as SimulatedMediaAttachmentJSON;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
@ -137,7 +138,7 @@ export const changeUploadCompose = createDataLoadingThunk(
|
|||||||
(media: SimulatedMediaAttachmentJSON) => {
|
(media: SimulatedMediaAttachmentJSON) => {
|
||||||
return {
|
return {
|
||||||
media,
|
media,
|
||||||
attached: typeof media.unattached !== 'undefined' && !media.unattached,
|
attached: typeof media.attached !== 'undefined' && media.attached,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user