Skip to content

Commit 1f12f1f

Browse files
committed
add disable button changes
1 parent fae9956 commit 1f12f1f

File tree

17 files changed

+439
-389
lines changed

17 files changed

+439
-389
lines changed

src/components/Button/Button.jsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1+
import React from "react";
12
import classNames from "classnames";
23
import PropTypes from "prop-types";
3-
import { Component } from "react";
44

5-
class Button extends Component {
6-
render() {
7-
return (
8-
<button {...this.props} className={classNames("mr-button", this.props.className)}>
9-
{this.props.children}
10-
</button>
11-
);
12-
}
5+
/**
6+
* Basic button component that includes proper styling for disabled state
7+
*/
8+
export default function Button({ className, disabled = false, children, ...otherProps }) {
9+
return (
10+
<button
11+
className={classNames("mr-button", className, {
12+
"mr-opacity-50 mr-cursor-not-allowed": disabled,
13+
})}
14+
disabled={disabled}
15+
{...otherProps}
16+
>
17+
{children}
18+
</button>
19+
);
1320
}
1421

1522
Button.propTypes = {
1623
className: PropTypes.string,
1724
children: PropTypes.node.isRequired,
25+
disabled: PropTypes.bool,
1826
};
19-
20-
export default Button;

src/components/HOCs/WithChallengeTaskClusters/WithChallengeTaskClusters.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export const WithChallengeTaskClusters = function (
7979
const showAsClusters =
8080
((this.props.criteria?.zoom ?? 0) < MAX_ZOOM &&
8181
(wantToShowAsClusters || this.state.taskCount > UNCLUSTER_THRESHOLD)) ||
82-
!this.props.criteria.boundingBox;
82+
!this.props.criteria.boundingBox ||
83+
(!this.props.createTaskBundle && this.state.taskCount > UNCLUSTER_THRESHOLD);
8384

8485
const currentFetchId = _uniqueId();
8586

src/components/HOCs/WithCurrentTask/WithCurrentTask.jsx

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { TaskLoadMethod } from "../../../services/Task/TaskLoadMethod/TaskLoadMe
3939
import { fetchTaskForReview } from "../../../services/Task/TaskReview/TaskReview";
4040
import { fetchUser } from "../../../services/User/User";
4141
import { renewVirtualChallenge } from "../../../services/VirtualChallenge/VirtualChallenge";
42+
import { waitFor } from "@testing-library/react";
4243

4344
const CHALLENGE_STALE = 300000; // 5 minutes
4445
const PROJECT_STALE = 300000; // 5 minutes
@@ -165,7 +166,7 @@ export const mapDispatchToProps = (dispatch, ownProps) => {
165166
/**
166167
* Invoke to mark a task as complete with the given status
167168
*/
168-
completeTask: (
169+
completeTask: async (
169170
task,
170171
challengeId,
171172
taskStatus,
@@ -183,77 +184,79 @@ export const mapDispatchToProps = (dispatch, ownProps) => {
183184
const taskId = task.id;
184185

185186
// Work to be done after the status is set
186-
const doAfter = () => {
187-
if (_isString(comment) && comment.length > 0) {
188-
if (taskBundle) {
189-
dispatch(
190-
addTaskBundleComment(
191-
taskBundle.bundleId,
192-
AsMappableBundle(taskBundle).primaryTaskId() || taskId,
193-
comment,
194-
taskStatus,
195-
),
196-
);
197-
} else {
198-
dispatch(addTaskComment(taskId, comment, taskStatus));
187+
const doAfter = () =>
188+
new Promise(async (resolve) => {
189+
if (_isString(comment) && comment.length > 0) {
190+
if (taskBundle) {
191+
await dispatch(
192+
addTaskBundleComment(
193+
taskBundle.bundleId,
194+
AsMappableBundle(taskBundle).primaryTaskId() || taskId,
195+
comment,
196+
taskStatus,
197+
),
198+
);
199+
} else {
200+
await dispatch(addTaskComment(taskId, comment, taskStatus));
201+
}
199202
}
200-
}
201203

202-
// Update the user in the background to get their latest score
203-
setTimeout(() => dispatch(fetchUser(userId)), 100);
204+
// Update the user in the background to get their latest score
205+
await dispatch(fetchUser(userId));
204206

205-
// Updating the challenge actions will allow us to show more accurate
206-
// completion progress, but this can be done in the background
207-
setTimeout(() => dispatch(fetchChallengeActions(challengeId)), 500);
207+
// Updating the challenge actions will allow us to show more accurate
208+
// completion progress
209+
await dispatch(fetchChallengeActions(challengeId));
208210

209-
// If working on a virtual challenge, renew it (extend its expiration)
210-
// since we've seen some activity, but this can be done in the
211-
// background
212-
if (_isFinite(ownProps.virtualChallengeId)) {
213-
setTimeout(() => dispatch(renewVirtualChallenge(ownProps.virtualChallengeId)), 1000);
214-
}
211+
// If working on a virtual challenge, renew it (extend its expiration)
212+
if (_isFinite(ownProps.virtualChallengeId)) {
213+
await dispatch(renewVirtualChallenge(ownProps.virtualChallengeId));
214+
}
215215

216-
if (taskLoadBy) {
217-
// Start loading the next task from the challenge.
218-
const loadNextTask = _isFinite(requestedNextTask)
219-
? nextRequestedTask(dispatch, ownProps, requestedNextTask)
220-
: nextRandomTask(dispatch, ownProps, taskId, taskLoadBy);
216+
if (taskLoadBy) {
217+
// Start loading the next task from the challenge.
218+
const loadNextTask = _isFinite(requestedNextTask)
219+
? await nextRequestedTask(dispatch, ownProps, requestedNextTask)
220+
: await nextRandomTask(dispatch, ownProps, taskId, taskLoadBy);
221221

222-
return loadNextTask
223-
.then((newTask) => visitNewTask(dispatch, ownProps, taskId, newTask))
224-
.catch(() => {
222+
try {
223+
await visitNewTask(dispatch, ownProps, taskId, loadNextTask);
224+
} catch (error) {
225225
ownProps.history.push(`/browse/challenges/${challengeId}`);
226-
});
227-
}
228-
};
226+
}
227+
}
228+
resolve();
229+
});
229230

230231
let cooperativeWorkSummary = null;
231232
if (AsCooperativeWork(task).isTagType()) {
232233
cooperativeWorkSummary = AsCooperativeWork(task).tagChangeSummary(tagEdits);
233234
}
234235

235-
return dispatch(
236-
taskBundle
237-
? completeTaskBundle(
238-
taskBundle.bundleId,
239-
AsMappableBundle(taskBundle).primaryTaskId() || taskId,
240-
taskStatus,
241-
needsReview,
242-
tags,
243-
cooperativeWorkSummary,
244-
osmComment,
245-
completionResponses,
246-
)
247-
: completeTask(
248-
taskId,
249-
taskStatus,
250-
needsReview,
251-
tags,
252-
cooperativeWorkSummary,
253-
osmComment,
254-
completionResponses,
255-
),
256-
).then(() => doAfter());
236+
const completeAction = taskBundle
237+
? await completeTaskBundle(
238+
taskBundle.bundleId,
239+
AsMappableBundle(taskBundle).primaryTaskId() || taskId,
240+
taskStatus,
241+
needsReview,
242+
tags,
243+
cooperativeWorkSummary,
244+
osmComment,
245+
completionResponses,
246+
)
247+
: await completeTask(
248+
taskId,
249+
taskStatus,
250+
needsReview,
251+
tags,
252+
cooperativeWorkSummary,
253+
osmComment,
254+
completionResponses,
255+
);
256+
257+
await dispatch(completeAction);
258+
const afterResult = await doAfter();
259+
return afterResult;
257260
},
258261

259262
/**
@@ -393,16 +396,25 @@ export const visitNewTask = function (dispatch, props, currentTaskId, newTask) {
393396
// If challenge is complete, redirect home with note to congratulate user
394397
if (_isFinite(props.virtualChallengeId)) {
395398
// We don't get a status for virtual challenges, so just assume we're done
396-
props.history.push("/browse/challenges", { congratulate: true, warn: false });
399+
props.history.push("/browse/challenges", {
400+
congratulate: true,
401+
warn: false,
402+
});
397403
return Promise.resolve();
398404
} else {
399405
const challengeId = challengeIdFromRoute(props, props.challengeId);
400406
return dispatch(fetchChallenge(challengeId)).then((normalizedResults) => {
401407
const challenge = normalizedResults.entities.challenges[normalizedResults.result];
402408
if (challenge.status === CHALLENGE_STATUS_FINISHED) {
403-
props.history.push("/browse/challenges", { congratulate: true, warn: false });
409+
props.history.push("/browse/challenges", {
410+
congratulate: true,
411+
warn: false,
412+
});
404413
} else {
405-
props.history.push("/browse/challenges", { warn: true, congratulate: false });
414+
props.history.push("/browse/challenges", {
415+
warn: true,
416+
congratulate: false,
417+
});
406418
}
407419
});
408420
}

src/components/TaskClusterMap/TaskClusterMap.jsx

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -62,66 +62,6 @@ export const TaskClusterMap = (props) => {
6262
const [currentBounds, setCurrentBounds] = useState(null);
6363
const [searchOpen, setSearchOpen] = useState(false);
6464
const [currentZoom, setCurrentZoom] = useState();
65-
const prevProps = useRef({
66-
showAsClusters: props.showAsClusters,
67-
loading: props.loading,
68-
});
69-
const timerHandle = useRef(null);
70-
const [displayTaskCount, setDisplayTaskCount] = useState(false);
71-
72-
useEffect(() => {
73-
// Check condition for toggling showAsClusters
74-
if (
75-
!props.showAsClusters &&
76-
props.totalTaskCount > UNCLUSTER_THRESHOLD &&
77-
!props.createTaskBundle
78-
) {
79-
props.toggleShowAsClusters();
80-
} else if (
81-
props.showAsClusters &&
82-
props.totalTaskCount <= UNCLUSTER_THRESHOLD &&
83-
props.createTaskBundle
84-
) {
85-
props.toggleShowAsClusters();
86-
}
87-
88-
// Handle loading state changes
89-
if (!props.loading && prevProps.current.loading) {
90-
// No longer loading. Kick off timer to hide task count message
91-
if (timerHandle.current) {
92-
clearTimeout(timerHandle.current);
93-
}
94-
timerHandle.current = setTimeout(() => {
95-
setDisplayTaskCount(false);
96-
}, 3000);
97-
setDisplayTaskCount(true);
98-
} else if (props.loading && displayTaskCount) {
99-
setDisplayTaskCount(false);
100-
if (timerHandle.current) {
101-
clearTimeout(timerHandle.current);
102-
timerHandle.current = null;
103-
}
104-
}
105-
106-
// Update previous props
107-
prevProps.current = {
108-
showAsClusters: props.showAsClusters,
109-
loading: props.loading,
110-
};
111-
112-
// Clean up timer on component unmount
113-
return () => {
114-
if (timerHandle.current) {
115-
clearTimeout(timerHandle.current);
116-
}
117-
};
118-
}, [
119-
props.showAsClusters,
120-
props.totalTaskCount,
121-
props.toggleShowAsClusters,
122-
props.loading,
123-
displayTaskCount,
124-
]);
12565

12666
let overlayLayers = buildLayerSources(
12767
props.visibleOverlays,
@@ -343,7 +283,7 @@ export const TaskClusterMap = (props) => {
343283
</div>
344284
</div>
345285
)}
346-
{displayTaskCount && !props.mapZoomedOut && (
286+
{props.displayTaskCount && !props.mapZoomedOut && (
347287
<div className="mr-absolute mr-top-0 mr-mt-3 mr-z-5 mr-w-full mr-flex mr-justify-center">
348288
<div className="mr-flex-col mr-items-center mr-bg-black-40 mr-text-white mr-rounded">
349289
<div className="mr-py-2 mr-px-3 mr-text-center">

0 commit comments

Comments
 (0)