mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 01:42:25 -05:00 
			
		
		
		
	[bugfix] fix 'steal this look' form, uncheck entries after processing (#1454)
This commit is contained in:
		
					parent
					
						
							
								4e4da19720
							
						
					
				
			
			
				commit
				
					
						52fbb3e584
					
				
			
		
					 4 changed files with 27 additions and 6 deletions
				
			
		|  | @ -115,12 +115,26 @@ function CopyEmojiForm({ localEmojiCodes, type, emojiList }) { | ||||||
| 	const form = { | 	const form = { | ||||||
| 		selectedEmoji: useCheckListInput("selectedEmoji", { | 		selectedEmoji: useCheckListInput("selectedEmoji", { | ||||||
| 			entries: emojiList, | 			entries: emojiList, | ||||||
| 			uniqueKey: "shortcode" | 			uniqueKey: "id" | ||||||
| 		}), | 		}), | ||||||
| 		category: useComboBoxInput("category") | 		category: useComboBoxInput("category") | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	const [formSubmit, result] = useFormSubmit(form, query.usePatchRemoteEmojisMutation(), { changedOnly: false }); | 	const [formSubmit, result] = useFormSubmit( | ||||||
|  | 		form, | ||||||
|  | 		query.usePatchRemoteEmojisMutation(), | ||||||
|  | 		{ | ||||||
|  | 			changedOnly: false, | ||||||
|  | 			onFinish: ({ data }) => { | ||||||
|  | 				if (data != undefined) { | ||||||
|  | 					form.selectedEmoji.updateMultiple( | ||||||
|  | 						// uncheck all successfully processed emoji
 | ||||||
|  | 						data.map(([id]) => [id, { checked: false }]) | ||||||
|  | 					); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	); | ||||||
| 
 | 
 | ||||||
| 	const buttonsInactive = form.selectedEmoji.someSelected | 	const buttonsInactive = form.selectedEmoji.someSelected | ||||||
| 		? {} | 		? {} | ||||||
|  |  | ||||||
|  | @ -171,7 +171,7 @@ module.exports = function useCheckListInput({ name }, { entries, uniqueKey = "ke | ||||||
| 			onChange, | 			onChange, | ||||||
| 			selectedValues, | 			selectedValues, | ||||||
| 			reset, | 			reset, | ||||||
| 			someSelected: state.someChecked, | 			someSelected: state.selectedEntries.size > 0, | ||||||
| 			updateMultiple, | 			updateMultiple, | ||||||
| 			toggleAll: { | 			toggleAll: { | ||||||
| 				ref: toggleAllRef, | 				ref: toggleAllRef, | ||||||
|  |  | ||||||
|  | @ -18,10 +18,11 @@ | ||||||
| 
 | 
 | ||||||
| "use strict"; | "use strict"; | ||||||
| 
 | 
 | ||||||
|  | const Promise = require("bluebird"); | ||||||
| const React = require("react"); | const React = require("react"); | ||||||
| const syncpipe = require("syncpipe"); | const syncpipe = require("syncpipe"); | ||||||
| 
 | 
 | ||||||
| module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = true } = {}) { | module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = true, onFinish } = {}) { | ||||||
| 	if (!Array.isArray(mutationQuery)) { | 	if (!Array.isArray(mutationQuery)) { | ||||||
| 		throw new ("useFormSubmit: mutationQuery was not an Array. Is a valid useMutation RTK Query provided?"); | 		throw new ("useFormSubmit: mutationQuery was not an Array. Is a valid useMutation RTK Query provided?"); | ||||||
| 	} | 	} | ||||||
|  | @ -64,7 +65,13 @@ module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = tru | ||||||
| 
 | 
 | ||||||
| 			mutationData.action = action; | 			mutationData.action = action; | ||||||
| 
 | 
 | ||||||
| 			return runMutation(mutationData); | 			return Promise.try(() => { | ||||||
|  | 				return runMutation(mutationData); | ||||||
|  | 			}).then((res) => { | ||||||
|  | 				if (onFinish) { | ||||||
|  | 					return onFinish(res); | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			...result, | 			...result, | ||||||
|  |  | ||||||
|  | @ -149,7 +149,7 @@ module.exports = (build) => ({ | ||||||
| 						body: body | 						body: body | ||||||
| 					}).then(unwrapRes); | 					}).then(unwrapRes); | ||||||
| 				}).then((res) => { | 				}).then((res) => { | ||||||
| 					data.push([emoji.shortcode, res]); | 					data.push([emoji.id, res]); | ||||||
| 				}).catch((e) => { | 				}).catch((e) => { | ||||||
| 					let msg = e.message ?? e; | 					let msg = e.message ?? e; | ||||||
| 					if (e.data.error) { | 					if (e.data.error) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue