Skip to content

Instantly share code, notes, and snippets.

@mabry1985
Last active May 10, 2023 08:09
Show Gist options
  • Save mabry1985/86a4d56c4147a5061b9d9db23bd291f1 to your computer and use it in GitHub Desktop.
Save mabry1985/86a4d56c4147a5061b9d9db23bd291f1 to your computer and use it in GitHub Desktop.
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