Skip to content

Commit 8e5a654

Browse files
committed
add across account dropdown option, fix bug with clearing data, fix issues with cache
1 parent 3cd708e commit 8e5a654

3 files changed

Lines changed: 68 additions & 25 deletions

File tree

src/content.js

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ function getContributorInfo() {
3333
// global variable
3434
if (statsScope === "org") {
3535
ret.user = org;
36+
ret.repoPath = org;
37+
}
38+
39+
if (statsScope === "account") {
40+
ret.repoPath = "__self";
3641
}
3742

3843
injectInitialUI(ret);
@@ -51,19 +56,31 @@ function buildUrl({base, q: {type, filterUser, author, repo, user}, sort, order,
5156
query += `${order ? `&order=${order}`: ""}`;
5257
query += `${per_page ? `&per_page=${per_page}`: ""}`;
5358
query += `${sort ? `&sort=${sort}`: ""}`;
59+
5460
return query;
5561
}
5662

5763
function contributorCount({access_token, contributor, user, repoPath, old = {}, type}) {
64+
let repo = repoPath;
65+
66+
// global variable
67+
if (statsScope === "org") {
68+
repo = undefined;
69+
repoPath = repoPath.split("/")[0];
70+
} else if (statsScope === "account") {
71+
repo = undefined;
72+
repoPath = "__self";
73+
}
74+
5875
let searchURL = buildUrl({
5976
access_token,
6077
base: "https://api.github.com/search/issues",
6178
order: "asc",
6279
per_page: "1",
6380
q: {
6481
type,
82+
repo,
6583
author: contributor,
66-
repo: user ? undefined : repoPath,
6784
user: user
6885
},
6986
sort: "created"
@@ -174,13 +191,16 @@ function injectInitialUI({ contributor, repoPath }) {
174191
<div class="dropdown-header">
175192
View options
176193
</div>
177-
<a class="dropdown-item" id="gce-across-this-org">
178-
across this org
179-
</a>
180194
<a class="dropdown-item selected" id="gce-in-this-repo">
181195
${$checkbox}
182196
in this repo
183197
</a>
198+
<a class="dropdown-item" id="gce-in-this-org">
199+
in this org
200+
</a>
201+
<a class="dropdown-item" id="gce-in-this-account">
202+
in this account
203+
</a>
184204
</ul>
185205
</div>
186206
</div>`;
@@ -200,31 +220,55 @@ ${dropdown}
200220
update(getContributorInfo());
201221
});
202222

203-
let $acrossThisOrg = $("#gce-across-this-org");
223+
let $inThisOrg = $("#gce-in-this-org");
204224
let $inThisRepo = $("#gce-in-this-repo");
225+
let $inThisAccount = $("#gce-in-this-account");
205226
let $dropdownText = $("#gce-dropdown-text");
206227

207-
$acrossThisOrg.dom[0].addEventListener("click", function() {
208-
$acrossThisOrg.addClass("selected");
228+
$inThisOrg.dom[0].addEventListener("click", function() {
229+
$inThisOrg.addClass("selected");
209230
$inThisRepo.removeClass("selected");
210-
$acrossThisOrg.html(`${$checkbox} across this org`);
211-
$inThisRepo.html('in this repo');
212-
$dropdownText.html('across this org');
231+
$inThisAccount.removeClass("selected");
232+
233+
$inThisOrg.html(`${$checkbox} in this org`);
234+
$dropdownText.html("in this org");
235+
236+
$inThisAccount.html("in this account");
237+
$inThisRepo.html("in this repo");
213238
// global
214239
statsScope = "org";
215240
update(getContributorInfo());
216241
});
217242

218243
$inThisRepo.dom[0].addEventListener("click", function() {
219244
$inThisRepo.addClass("selected");
220-
$acrossThisOrg.removeClass("selected");
245+
$inThisOrg.removeClass("selected");
246+
$inThisAccount.removeClass("selected");
247+
221248
$inThisRepo.html(`${$checkbox} in this repo`);
222-
$acrossThisOrg.html('across this org');
223-
$dropdownText.html('in this repo');
249+
$dropdownText.html("in this repo");
250+
251+
$inThisAccount.html("in this account");
252+
$inThisOrg.html("in this org");
224253
// global
225254
statsScope = "repo";
226255
update(getContributorInfo());
227256
});
257+
258+
$inThisAccount.dom[0].addEventListener("click", function() {
259+
$inThisAccount.addClass("selected");
260+
$inThisOrg.removeClass("selected");
261+
$inThisRepo.removeClass("selected");
262+
263+
$inThisAccount.html(`${$checkbox} in this account`);
264+
$dropdownText.html("in this account");
265+
266+
$inThisRepo.html("in this repo");
267+
$inThisOrg.html("in this org");
268+
// global
269+
statsScope = "account";
270+
update(getContributorInfo());
271+
});
228272
}
229273

230274
function updateTextNodes({ prText, issueText, lastUpdate }) {
@@ -247,7 +291,14 @@ function updateTextNodes({ prText, issueText, lastUpdate }) {
247291
function update({ contributor, repoPath, currentNum, user }) {
248292
getStorage(contributor, repoPath)
249293
.then((storage) => {
250-
let storageRes = storage[contributor][user ? user : repoPath] = {};
294+
let path = repoPath;
295+
if (user) {
296+
path = user;
297+
} else if (statsScope === "account") {
298+
path = "__self";
299+
}
300+
301+
let storageRes = storage[`${contributor}|${path}`] || {};
251302

252303
if (storageRes.prs || storageRes.issues) {
253304
updateTextNodes(appendPRText(currentNum, storageRes));

src/options.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ document.addEventListener("DOMContentLoaded", () => {
2222

2323
clearCacheLink.addEventListener("click", () => {
2424
let temp = accessTokenInput.value;
25-
clearSyncStorage()
26-
.then(() => {
25+
chrome.storage.sync.clear(() => {
2726
setSyncStorage({ "access_token": temp });
2827
document.querySelector("#feedback").textContent = "Storage Cleared";
2928
});

src/storage.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,13 @@ function promisify(func) {
2525

2626
window.getSyncStorage = promisify(chrome.storage.sync.get.bind(chrome.storage.sync));
2727
window.setSyncStorage = promisify(chrome.storage.sync.set.bind(chrome.storage.sync));
28-
window.clearSyncStorage = promisify(chrome.storage.sync.clear.bind(chrome.storage.sync));
2928

3029
window.setStorage = (CONTRIBUTOR, ORG_REPO_PATH, value) => {
3130
return window.setSyncStorage({
32-
[CONTRIBUTOR]: {
33-
[ORG_REPO_PATH]: value
34-
}
31+
[`${CONTRIBUTOR}|${ORG_REPO_PATH}`]: value
3532
});
3633
};
3734

3835
window.getStorage = (CONTRIBUTOR, ORG_REPO_PATH) => {
39-
return window.getSyncStorage({
40-
[CONTRIBUTOR]: {
41-
[ORG_REPO_PATH]: {}
42-
}
43-
});
36+
return window.getSyncStorage(`${CONTRIBUTOR}|${ORG_REPO_PATH}`);
4437
};

0 commit comments

Comments
 (0)