-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Make API request from service worker
- Loading branch information
Showing
6 changed files
with
59 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Platforms } from 'polarkit/api/client' | ||
import api from './api' | ||
|
||
const apiRequestDecoration = async ( | ||
orgName: string, | ||
repoName: string, | ||
issueNumbers: string[], | ||
) => { | ||
const extensionIssues = await api.extension.listIssuesForExtension({ | ||
platform: Platforms.GITHUB, | ||
orgName, | ||
repoName, | ||
numbers: issueNumbers.join(','), | ||
}) | ||
|
||
// Add all the issues to chrome.storage | ||
const itemsToAdd = {} | ||
extensionIssues.forEach((issue) => { | ||
itemsToAdd[`issues/${orgName}/${repoName}/${issue.number}`] = issue | ||
}) | ||
chrome.storage.local.set(itemsToAdd) | ||
|
||
// Remove the issues we asked for but didn't get a response for from the cache | ||
const keysToRemove = issueNumbers.filter( | ||
(issueNumber) => | ||
!extensionIssues.some( | ||
(extensionIssue) => extensionIssue.number.toString() === issueNumber, | ||
), | ||
) | ||
chrome.storage.local.remove( | ||
keysToRemove.map((k) => `issues/${orgName}/${repoName}/${k}`), | ||
) | ||
} | ||
|
||
chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => { | ||
const { type, orgName, repoName, issueNumbers } = message | ||
if (type === 'decorate-issues') { | ||
await apiRequestDecoration(orgName, repoName, issueNumbers) | ||
return true | ||
} | ||
}) | ||
|
||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters