Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX of add slur and Crowdsource in single button #453

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 15 additions & 39 deletions browser-extension/plugin/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,27 @@ console.log(contextMenus);

contextMenus.create(
{
id: 'add-slur',
title: 'Add Slur to Uli',
id: 'add-slur-crowdsource',
title: 'Add Slur to Uli and Crowdsource',
contexts: ['selection']
},
() => {
console.log('context menu created');
}
);
contextMenus.create(
{
id: 'add-crowdsource-slur',
title: 'Crowdsource Slur Word',
contexts: ['selection']
},
() => {
console.log('crowdsource context menu created');
console.log('Unified context menu created');
}
);

contextMenus.onClicked.addListener(async (info, tab) => {
switch (info.menuItemId) {
case 'add-slur':
console.log('slur added');
tabs.sendMessage(
tab.id,
{ type: 'SLUR_ADDED', slur: info.selectionText },
function (response) {
console.log(response);
}
);
break;
case 'add-crowdsource-slur':
console.log('Crowdsource slur word added');
tabs.sendMessage(
tab.id,
{
type: 'CROWDSOURCE_SLUR_WORD',
crowdsourcedSlur: info.selectionText
},
function (response) {
console.log(response);
}
);
break;
default:
console('unexpected action');
if (info.menuItemId === 'add-slur-crowdsource') {
console.log('Slur added and Crowdsourced');
tabs.sendMessage(
tab.id,
{ type: 'SLUR_ADDED_AND_CROWDSOURCE_SLUR_WORD', slur: info.selectionText,crowdsourcedSlur: info.selectionText },
function (response) {
console.log(response);
}
);
} else {
console('unexpected action');
}
});

10 changes: 4 additions & 6 deletions browser-extension/plugin/src/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ chrome.runtime.onMessage.addListener(async function (request) {
processPage(location.href);
return true;
}
if (request.type === 'SLUR_ADDED') {

if (request.type === 'SLUR_ADDED_AND_CROWDSOURCE_SLUR_WORD') {
const slur = request.slur;
aatmanvaidya marked this conversation as resolved.
Show resolved Hide resolved
log('slur added from bg', slur);
const pref = await getPreferenceData();
Expand All @@ -111,20 +112,17 @@ chrome.runtime.onMessage.addListener(async function (request) {
}
}
await setPreferenceData({ ...pref, slurList });
return true;
}
if (request.type === 'CROWDSOURCE_SLUR_WORD') {
const crowdsource_slur = request.crowdsourcedSlur;
console.log('crowdsourced slur from bg = ', crowdsource_slur);
const user = await getUserData();
console.log('USER in cotnent', user);
console.log('USER in content', user);
const crowdsourceData = {
label: crowdsource_slur,
categories: []
};
try {
await createSlurAndCategory(user.accessToken, crowdsourceData);
console.log('finsihed POST req');
console.log('finished POST req');
window.alert(
`Crowdsourced Slur "${crowdsource_slur}" added to Uli`
);
Expand Down
Loading