Skip to content

Commit

Permalink
Add support for preference strengths
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Dec 17, 2023
1 parent b759e43 commit f514858
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/bolt/chores.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ app.view('chores-rank-callback', async ({ ack, body }) => {
const houseId = body.team.id;

const direction = body.view.private_metadata;
const targetChore = JSON.parse(common.getInputBlock(body, -2).chores.selected_option.value);
const sourceChores = common.getInputBlock(body, -1).chores.selected_options
const targetChore = JSON.parse(common.getInputBlock(body, -3).chores.selected_option.value);
const sourceChores = common.getInputBlock(body, -2).chores.selected_options
.map(option => JSON.parse(option.value));

const strength = 100 / 200 + 0.5; // Scale (0, 100) -> (0.5, 1.0)
const { strength } = JSON.parse(common.getInputBlock(body, -1).strength.selected_option.value);
const preference = (direction === 'faster') ? strength : 1 - strength;

// Perform the update
Expand All @@ -324,15 +324,15 @@ app.view('chores-rank-callback', async ({ ack, body }) => {
const changeText = (Math.abs(change) > bigChange) ? 'a lot' : 'a little';

if (change > 0) {
const text = `Someone prioritized *${targetChore.name}* by *${changeText}*, to *${priority} ppt* :rocket:`;
const text = `Someone *prioritized ${targetChore.name}* by ${changeText}, to *${priority} ppt* :rocket:`;
await postMessage(houseId, text);
} else if (change < 0) {
const text = `Someone deprioritized *${targetChore.name}* by *${changeText}*, to *${priority} ppt* :snail:`;
const text = `Someone *deprioritized ${targetChore.name}* by ${changeText}, to *${priority} ppt* :snail:`;
await postMessage(houseId, text);
} else {
const text = 'You\'ve already input those preferences.\n\n' +
'To have an additional effect, *choose more or different chores*. ' +
'Alternatively, *convince others* to support your priorities.';
'To have an additional effect, *choose more or different chores* or a *stronger preference*.\n' +
'Alternatively, try and *convince others* to support your priorities.';
await postEphemeral(houseId, residentId, text);
}
});
Expand Down
18 changes: 17 additions & 1 deletion src/bolt/chores.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ exports.choresRankView2 = function (direction, choreRankings) {
};
});

const preferenceOptions = [
{ value: JSON.stringify({ strength: 0.7 }), text: common.blockPlaintext('Mild (70%)') },
{ value: JSON.stringify({ strength: 1.0 }), text: common.blockPlaintext('Strong (100%)') },
];

const header = 'Set chore priorities';
const mainText = 'Choose chores to update. ' +
'Chore priorities are measured in *points-per-thousand* (ppt) and always add up to *1000*. ' +
Expand All @@ -301,7 +306,8 @@ exports.choresRankView2 = function (direction, choreRankings) {
'*Some things to keep in mind:*\n\n' +
'*1.* Taking from *more chores* has a bigger effect.\n' +
'*2.* Taking from *high-priority chores* has a bigger effect.\n' +
'*3.* *More participants* have a bigger effect.';
'*3.* A *strong preference* has a bigger effect.\n' +
'*4.* *More participants* have a bigger effect.';

const textA = direction === 'faster'
? 'Chore to prioritize'
Expand Down Expand Up @@ -339,6 +345,16 @@ exports.choresRankView2 = function (direction, choreRankings) {
options: mappedChoreRankings,
},
));
blocks.push(common.blockInput(
'Preference strength',
{
action_id: 'strength',
type: 'static_select',
placeholder: common.blockPlaintext('Choose a preference strength'),
initial_option: preferenceOptions[0],
options: preferenceOptions,
},
));

return {
type: 'modal',
Expand Down

0 comments on commit f514858

Please sign in to comment.