From fdbc53bbb2922c40bef646cba7e552a8467551c4 Mon Sep 17 00:00:00 2001 From: CollinBeczak Date: Mon, 28 Oct 2024 15:47:38 -0500 Subject: [PATCH] formatting --- .../HOCs/WithTaskBundle/WithTaskBundle.js | 17 +- .../TaskBundleWidget/TaskBundleWidget.js | 224 +++++++++--------- 2 files changed, 122 insertions(+), 119 deletions(-) diff --git a/src/components/HOCs/WithTaskBundle/WithTaskBundle.js b/src/components/HOCs/WithTaskBundle/WithTaskBundle.js index 9fa3f52b9..bd9ba7831 100644 --- a/src/components/HOCs/WithTaskBundle/WithTaskBundle.js +++ b/src/components/HOCs/WithTaskBundle/WithTaskBundle.js @@ -100,8 +100,11 @@ export function WithTaskBundle(WrappedComponent) { } } - unlockTasks = async (initialBundle, taskBundle) => { - const tasksToUnlock = initialBundle.taskIds.filter(taskId => !taskBundle.taskIds.includes(taskId)) + unlockTasks = async (taskBundle,initialBundle) => { + const tasksToUnlock = taskBundle.taskIds + if(initialBundle){ + tasksToUnlock.filter(taskId => !initialBundle.taskIds.includes(taskId)) + } await Promise.all(tasksToUnlock.map(taskId => this.props.releaseTask(taskId).then(() => { setTimeout(() => localStorage.removeItem(`lock-${taskId}`), 1500) @@ -116,6 +119,8 @@ export function WithTaskBundle(WrappedComponent) { return task.entities.tasks[taskId] } catch (error) { console.error(`Failed to lock task ${taskId}:`, error) + dispatch(addError(`Failed to lock task ${taskId}:`, error)) + dispatch(addError(AppErrors.challenge.rebuildFailure)); throw error } } @@ -161,9 +166,11 @@ export function WithTaskBundle(WrappedComponent) { this.setState({ taskBundle: updatedTaskBundle }) } - clearActiveTaskBundle = () => { - this.setState({ - selectedTasks: [], + clearActiveTaskBundle = async () => { + const { taskBundle, initialBundle } = this.state + await this.unlockTasks(taskBundle, initialBundle) + this.setState({ + selectedTasks: [], taskBundle: null, }) this.resetSelectedTasks() diff --git a/src/components/Widgets/TaskBundleWidget/TaskBundleWidget.js b/src/components/Widgets/TaskBundleWidget/TaskBundleWidget.js index 75480b635..4d49ca3e8 100644 --- a/src/components/Widgets/TaskBundleWidget/TaskBundleWidget.js +++ b/src/components/Widgets/TaskBundleWidget/TaskBundleWidget.js @@ -11,16 +11,14 @@ import _pick from 'lodash/pick' import _map from 'lodash/map' import bbox from '@turf/bbox' import { point, featureCollection } from '@turf/helpers' -import { WidgetDataTarget, registerWidgetType } - from '../../../services/Widget/Widget' - import { buildSearchURL } from '../../../services/SearchCriteria/SearchCriteria' +import { WidgetDataTarget, registerWidgetType } from '../../../services/Widget/Widget' +import { buildSearchURL } from '../../../services/SearchCriteria/SearchCriteria' import MapPane from '../../EnhancedMap/MapPane/MapPane' import TaskClusterMap from '../../TaskClusterMap/TaskClusterMap' import TaskPropertyFilter from '../../TaskFilters/TaskPropertyFilter' import TaskPriorityFilter from '../../TaskFilters/TaskPriorityFilter' import TaskStatusFilter from '../../TaskFilters/TaskStatusFilter' -import WithSelectedClusteredTasks - from '../../HOCs/WithSelectedClusteredTasks/WithSelectedClusteredTasks' +import WithSelectedClusteredTasks from '../../HOCs/WithSelectedClusteredTasks/WithSelectedClusteredTasks' import WithBrowsedChallenge from '../../HOCs/WithBrowsedChallenge/WithBrowsedChallenge' import WithNearbyTasks from '../../HOCs/WithNearbyTasks/WithNearbyTasks' import WithTaskClusterMarkers from '../../HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers' @@ -29,13 +27,11 @@ import WithClusteredTasks from '../../HOCs/WithClusteredTasks/WithClusteredTasks import WithFilterCriteria from '../../HOCs/WithFilterCriteria/WithFilterCriteria' import WithTaskPropertyKeys from '../../HOCs/WithTaskPropertyKeys/WithTaskPropertyKeys' import WithBoundedTasks from '../../HOCs/WithBoundedTasks/WithBoundedTasks' -import WithFilteredClusteredTasks - from '../../HOCs/WithFilteredClusteredTasks/WithFilteredClusteredTasks' +import WithFilteredClusteredTasks from '../../HOCs/WithFilteredClusteredTasks/WithFilteredClusteredTasks' import WithSavedFilters from '../../HOCs/WithSavedFilters/WithSavedFilters' import AsMappableTask from '../../../interactions/Task/AsMappableTask' import AsCooperativeWork from '../../../interactions/Task/AsCooperativeWork' -import WithWebSocketSubscriptions - from '../../HOCs/WithWebSocketSubscriptions/WithWebSocketSubscriptions' +import WithWebSocketSubscriptions from '../../HOCs/WithWebSocketSubscriptions/WithWebSocketSubscriptions' import { toLatLngBounds } from '../../../services/MapBounds/MapBounds' import QuickWidget from '../../QuickWidget/QuickWidget' import BusySpinner from '../../BusySpinner/BusySpinner' @@ -74,26 +70,9 @@ export default class TaskBundleWidget extends Component { shortcutActive: false, } - bundleTasks = () => { - if(_get(this.props, 'taskBundle.tasks.length', 0) > 0 || this.props.bundleEditsDisabled){ - return - } - - const selectedArray = Array.from(this.props.selectedTasks.selected.values()); - const isCooperative = AsCooperativeWork(this.props.task).isCooperative(); - - selectedArray.forEach(item => { - if (AsCooperativeWork(item).isCooperative() !== isCooperative) { - throw new Error("Bundle type mismatch, not all tasks are of the same type"); - } - }); - - this.props.createTaskBundle([...this.props.selectedTasks.selected.keys()]); - } - handleKeyboardShortcuts = (event) => { const { activeKeyboardShortcuts, textInputActive, taskReadOnly, keyboardShortcutGroups } = this.props; - + // Return early if any of the following conditions are met: // - Shortcut group is not active // - Typing in inputs @@ -112,18 +91,12 @@ export default class TaskBundleWidget extends Component { } } - unbundleTask = (task) => { - const taskId = task.id ?? task.taskId - this.props.removeTaskFromBundle(taskId) - this.props.toggleTaskSelection(task) - } - /** * Initialize the cluster filters to include tasks from the current challenge * and initially within bounds of "nearby" tasks as a starting point for the * widget map */ - initializeClusterFilters(prevProps={}) { + initializeClusterFilters(prevProps = {}) { // If the nearby tasks loaded, update bounds if (_get(this.props, 'nearbyTasks.tasks.length', 0) > 0 && !_isEqual(this.props.nearbyTasks, prevProps.nearbyTasks)) { @@ -131,16 +104,35 @@ export default class TaskBundleWidget extends Component { } } - initializeWebsocketSubscription(prevProps={}) { + initializeWebsocketSubscription(prevProps = {}) { const challengeId = _get(this.props.task, 'parent.id') if (_isFinite(challengeId) && - (challengeId !== _get(prevProps.task, 'parent.id'))) { + (challengeId !== _get(prevProps.task, 'parent.id'))) { this.props.subscribeToChallengeTaskMessages(challengeId) } } - updateBounds = (challengeId, bounds, zoom) => { - this.props.updateTaskFilterBounds(bounds, zoom) + bundleTasks = () => { + if (this.props.taskBundle || this.props.bundleEditsDisabled) { + return + } + + const selectedArray = Array.from(this.props.selectedTasks.selected.values()); + const isCooperative = AsCooperativeWork(this.props.task).isCooperative(); + + selectedArray.forEach(item => { + if (AsCooperativeWork(item).isCooperative() !== isCooperative) { + throw new Error("Bundle type mismatch, not all tasks are of the same type"); + } + }); + + this.props.createTaskBundle([...this.props.selectedTasks.selected.keys()]); + } + + unbundleTask = (task) => { + const taskId = task.id ?? task.taskId + this.props.removeTaskFromBundle(taskId) + this.props.toggleTaskSelection(task) } setBoundsToNearbyTask = () => { @@ -153,7 +145,7 @@ export default class TaskBundleWidget extends Component { if (taskList) { taskList?.push(mappableTask) } - + if (!taskList || taskList.length === 0) { return } @@ -166,18 +158,18 @@ export default class TaskBundleWidget extends Component { } saveFilters = () => { - if(!this.props.criteria) return + if (!this.props.criteria) return const searchURL = buildSearchURL(this.props.criteria) - this.props.updateUserAppSetting(this.props.user.id, {'taskBundleFilters': searchURL}) + this.props.updateUserAppSetting(this.props.user.id, { 'taskBundleFilters': searchURL }) } revertFilters = () => { - if(this.props.clearAllFilters) { + if (this.props.clearAllFilters) { this.props.clearAllFilters() } - - if(this.props.updateUserAppSetting) { - this.props.updateUserAppSetting(this.props.user.id, {'taskBundleFilters': ''}) + + if (this.props.updateUserAppSetting) { + this.props.updateUserAppSetting(this.props.user.id, { 'taskBundleFilters': '' }) } } @@ -190,13 +182,13 @@ export default class TaskBundleWidget extends Component { if (this.props.task && this.props.selectedTasks && !this.props.isTaskSelected(this.props.task.id)) { this.props.selectTasks([this.props.task]) } - if(this.props.taskBundle) { + if (this.props.taskBundle) { this.props.selectTasks(this.props.taskBundle.tasks) this.setBoundsToNearbyTask() } } - async componentDidUpdate (prevProps) { + async componentDidUpdate(prevProps) { if (!this.props.taskBundle) { this.initializeClusterFilters(prevProps) this.initializeWebsocketSubscription(prevProps) @@ -209,10 +201,9 @@ export default class TaskBundleWidget extends Component { _pick(this.props.keyboardShortcutGroups.taskEditing, 'completeTogether'), this.handleKeyboardShortcuts ) - } else if (this.state.shortcutActive === true && this.props.selectedTaskCount(this.props.taskInfo.totalCount) <= 1){ + } else if (this.state.shortcutActive === true && this.props.selectedTaskCount(this.props.taskInfo.totalCount) <= 1) { this.setState({ shortcutActive: false }) - this.props.deactivateKeyboardShortcut(shortcutGroup, 'completeTogether', - this.handleKeyboardShortcuts) + this.props.deactivateKeyboardShortcut(shortcutGroup, 'completeTogether', this.handleKeyboardShortcuts) } if (_isFinite(_get(this.props, 'task.id')) && @@ -220,14 +211,13 @@ export default class TaskBundleWidget extends Component { this.props.task.id !== prevProps.task.id) { this.props.resetSelectedTasks() this.setBoundsToNearbyTask() - } - else if (this.props.task && this.props.selectedTasks && !this.props.isTaskSelected(this.props.task.id)) { + } else if (this.props.task && this.props.selectedTasks && !this.props.isTaskSelected(this.props.task.id)) { this.props.selectTasks([this.props.task]) } - if(this.props.taskBundle && this.props.taskBundle !== prevProps.taskBundle) { + if (this.props.taskBundle && this.props.taskBundle !== prevProps.taskBundle) { await this.props.resetSelectedTasks() this.props.selectTasks(this.props.taskBundle.tasks) - if(!prevProps.taskBundle){ + if (!prevProps.taskBundle) { this.setBoundsToNearbyTask() } } @@ -240,13 +230,11 @@ export default class TaskBundleWidget extends Component { this.props.unsubscribeFromChallengeTaskMessages(challengeId) } - this.props.deactivateKeyboardShortcut(shortcutGroup, 'completeTogether', - this.handleKeyboardShortcuts) + this.props.deactivateKeyboardShortcut(shortcutGroup, 'completeTogether', this.handleKeyboardShortcuts) } render() { - const WidgetContent = this.props.taskBundle ? - ActiveBundle : BuildBundle + const WidgetContent = this.props.taskBundle ? ActiveBundle : BuildBundle return ( { const ActiveBundle = props => { const showMarkerPopup = markerData => { return ( - +
{ const bundleCenter = toLatLngBounds( bbox({ type: 'FeatureCollection', - features: _map(props.taskBundle.tasks, task => - ({ - type: 'Feature', - geometry: { - type: 'Point', - coordinates: [task.location.coordinates[0], task.location.coordinates[1]] - } - }) - ) + features: _map(props.taskBundle.tasks, task => ({ + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [task.location.coordinates[0], task.location.coordinates[1]] + } + })) }) ); @@ -330,7 +315,7 @@ const ActiveBundle = props => { { defaultPageSize={5} /> ) - +console.log(props) return (
-
+
{props.loading ? ( ) : ( {map} )} +

+ +

-

- -

- {props.initialBundle && - -} + + )}
{ const totalTaskCount = _get(props, 'taskInfo.totalCount') || _get(props, 'taskInfo.tasks.length') const bundleButton = !props.taskReadOnly && props.selectedTaskCount(totalTaskCount) > 1 && !props.bundleEditsDisabled ? ( - + ) : null const showMarkerPopup = (markerData) => { return ( - +
{ ) } - const map = + const map = ( { fitbBoundsControl showSelectMarkersInView /> + ) return (
-
+
{props.loading ? : {map} @@ -522,6 +509,15 @@ const BuildBundle = props => {
+ {props.initialBundle && ( + + )}

@@ -538,11 +534,11 @@ const BuildBundle = props => {

- +
- {} + {} (