Permalink
Browse files

Fixed #134

storage.js now rejects the promise. Only noticable difference should be rejected promises in the console instead of warnings.
block-location uses the rejected promise.
  • Loading branch information...
Kadauchi committed Sep 8, 2018
1 parent d93e54a commit 026c69f0d2f88d11db5fb471ed403eac345898e4
Showing with 32 additions and 16 deletions.
  1. +2 −3 js/storage.js
  2. +30 −13 mturk/block-list-on-mturk.js
View
@@ -9,11 +9,10 @@ async function StorageGetKey(key) {
// eslint-disable-next-line no-unused-vars
function Enabled(name) {
return new Promise(async resolve => {
return new Promise(async (resolve, reject) => {
const options = await StorageGetKey(`options`);
if (options[name]) resolve();
else
window.console.warn(`"${name}" did not resolve because it is disabled.`);
else reject()
});
}
@@ -63,31 +63,48 @@ async function updateBlockList(blockList) {
}
(async function blockListOnMturk() {
const [blockList, element, props, blockLocation] = await Promise.all([
const [blockList, element, props] = await Promise.all([
StorageGetKey(`blockList`),
ReactDOM(`HitSetTable`),
ReactProps(`HitSetTable`),
Enabled(`blockLocation`),
Enabled(`blockListOnMturk`)
]);
const blockLocation = await new Promise(async r => {
try {
await Enabled(`blockLocation`);
r(true);
} catch (err) {
r(false);
}
});
const data = props.bodyData;
if (blockLocation) {
// from all Hits with requirements, get the ones with location requirement not met
const with_location_requitement_not_meet = data.filter(d => d.project_requirements.length > 0)
.filter(
d => d.project_requirements.some(
r => r.qualification_type_id == "00000000000000000071" && !r.caller_meets_requirements
)
const with_location_requitement_not_meet = data
.filter(d => d.project_requirements.length > 0)
.filter(d =>
d.project_requirements.some(
r =>
r.qualification_type_id == "00000000000000000071" &&
!r.caller_meets_requirements
)
);
const extra_blockList = with_location_requitement_not_meet.reduce(
(result, h) => {
result[h.hit_set_id] = {
match: h.hit_set_id,
name: h.title,
strict: true
};
return result;
},
{}
);
const extra_blockList = with_location_requitement_not_meet.reduce((result, h) => {
result[h.hit_set_id] = {
'match': h.hit_set_id, 'name': h.title, 'strict': true
}; return result
},{});
for (const attrname in extra_blockList) {
blockList[attrname] = extra_blockList[attrname];
}

0 comments on commit 026c69f

Please sign in to comment.