Skip to content

Commit

Permalink
refactor: prefer map over object for mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhongtw committed Aug 23, 2023
1 parent 7fc789f commit 6bbcec4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ async function generateKeyList(secretStorage: PassphraseStorage, keyStatusManage
return false;
}
const items: vscode.QuickPickItem[] = [];
const keyList = Object.fromEntries(
(await gpg.getKeyInfos())
.filter(({ userId }) => userId)
.map(({ userId, fingerprint }) => [fingerprint, userId]),
);
const keyInfos = await gpg.getKeyInfos();
const keyToUser = keyInfos.map(({ userId, fingerprint }): [string, string?] => [fingerprint, userId]);
const withUsers = keyToUser.filter((pair): pair is [string, string] => pair[1] !== undefined);
const keyList = new Map<string, string>(withUsers);
const isCurrentKey = (fingerprint: string) => keyStatusManager.getCurrentKey()?.fingerprint === fingerprint;
const currentKeyList = list.filter(isCurrentKey);
const currentKey = currentKeyList.length === 1 ? currentKeyList[0] : undefined;
Expand All @@ -50,7 +49,7 @@ async function generateKeyList(secretStorage: PassphraseStorage, keyStatusManage
});
items.push({
label: currentKey,
detail: keyList[currentKey],
detail: keyList.get(currentKey),
alwaysShow: true,
picked: false,
kind: vscode.QuickPickItemKind.Default,
Expand All @@ -66,7 +65,7 @@ async function generateKeyList(secretStorage: PassphraseStorage, keyStatusManage
for (const fingerprint of restList) {
items.push({
label: fingerprint,
detail: keyList[fingerprint],
detail: keyList.get(fingerprint),
alwaysShow: false,
picked: false,
kind: vscode.QuickPickItemKind.Default,
Expand Down

0 comments on commit 6bbcec4

Please sign in to comment.