Skip to content

Commit b073f07

Browse files
committed
add rebuild method for prebundling
1 parent 7339bdf commit b073f07

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

src/components/AdminPane/HOCs/WithChallengeManagement/WithChallengeManagement.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ const WithChallengeManagement = WrappedComponent =>
4444
), 'deletingTasks'
4545
)
4646

47+
/**
48+
* Method used to direct remote or local data structures into line-by-line GeoJson format
49+
* if a taskBundleIdProperty is provided. Any errors will be treated silently and return false
50+
* to allow parent methods to continue other processes.
51+
*
52+
* @private
53+
*/
54+
async function rebuildPrebundle(challenge, localFile) {
55+
try {
56+
if (challenge.taskBundleIdProperty) {
57+
if (localFile) {
58+
const data = await new Response(localFile).text()
59+
60+
const bundled = bundleByTaskBundleId(
61+
JSON.parse(data).features,
62+
challenge.taskBundleIdProperty
63+
);
64+
65+
return createBlob(bundled);
66+
}
67+
}
68+
69+
return false;
70+
} catch (e) {
71+
console.log(e);
72+
return false;
73+
}
74+
}
75+
4776
/**
4877
* Method used to direct remote or local data structures into line-by-line GeoJson format
4978
* if a taskBundleIdProperty is provided. Any errors will be treated silently and return false
@@ -63,17 +92,13 @@ const WithChallengeManagement = WrappedComponent =>
6392
} else if (challenge.localGeoJSON) {
6493
data = JSON.parse(challenge.localGeoJSON);
6594
}
66-
67-
debugger;
6895

6996
if (data.features) {
7097
const bundled = bundleByTaskBundleId(
7198
data.features,
7299
challenge.taskBundleIdProperty
73100
);
74101

75-
debugger;
76-
77102
return bundled;
78103
}
79104
}
@@ -210,12 +235,16 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
210235
rebuildChallenge: async (challenge, localFile, dataOriginDate) => {
211236
ownProps.updateCreatingTasksProgress(true)
212237

238+
const prebundle = await rebuildPrebundle(challenge, localFile);
239+
213240
try {
214241
// For local files we need to figure out if it's line-by-line to
215242
// decide which service call to use
216-
if (localFile) {
217-
if (await AsValidatableGeoJSON(localFile).isLineByLine()) {
218-
await uploadLineByLine(dispatch, ownProps, challenge, localFile, dataOriginDate)
243+
const fileData = prebundle || localFile;
244+
245+
if (fileData) {
246+
if (await AsValidatableGeoJSON(fileData).isLineByLine()) {
247+
await uploadLineByLine(dispatch, ownProps, challenge, fileData, dataOriginDate)
219248
}
220249
else {
221250
await dispatch(

0 commit comments

Comments
 (0)