Last active
May 10, 2023 08:09
-
-
Save mabry1985/86a4d56c4147a5061b9d9db23bd291f1 to your computer and use it in GitHub Desktop.
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
export const renderTags = async (dbName) => { | |
const tagsDb = await db(dbName); | |
await tagsDb.read(); | |
const allTags = [...tagsDb.data.tags]; | |
const selectedTags = {}; | |
let selecting = true; | |
while (selecting) { | |
const availableTags = allTags.map((tag) => ({ | |
name: `${tag} ${selectedTags[tag] ? " ✓" : " "}`, | |
value: tag, | |
})); | |
let tagToRead = await arg("Read a tag", [ | |
...availableTags, | |
{ name: "Done", value: "Done" }, | |
]); | |
if (tagToRead === "Done") { | |
selecting = false; | |
} else { | |
selectedTags[tagToRead] = !selectedTags[tagToRead]; | |
} | |
} | |
return Object.keys(selectedTags).filter((tag) => selectedTags[tag]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment