- offer to create tag when none is found while adding a link from cli - fix tag display in search
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
import inquirer from "inquirer";
|
||
import { loadConfig } from "../config.js";
|
||
import { initDirectusClient, searchItems, updateItem } from "../directus/client.js";
|
||
|
||
export const updateReadingProgress = async () => {
|
||
const config = await loadConfig();
|
||
|
||
initDirectusClient(config);
|
||
|
||
const readingBooks = await searchItems("books", "", { read_status: "started" });
|
||
|
||
if (!readingBooks.length) {
|
||
console.log('📖 No books currently marked as "started".');
|
||
|
||
return;
|
||
}
|
||
|
||
const { bookId } = await inquirer.prompt({
|
||
type: "list",
|
||
name: "bookId",
|
||
message: "📚 Select a book to update progress:",
|
||
choices: readingBooks.map((book) => {
|
||
const title = book.title || book.name || `Book #${book.id}`;
|
||
const progress = book.progress ?? 0;
|
||
|
||
return {
|
||
name: `${title} (${progress}%)`,
|
||
value: book.id
|
||
};
|
||
})
|
||
});
|
||
const { progress } = await inquirer.prompt({
|
||
name: "progress",
|
||
message: "📕 New progress percentage (0–100):",
|
||
validate: (input) => {
|
||
const num = Number(input);
|
||
|
||
return (!isNaN(num) && num >= 0 && num <= 100) || "Enter a number from 0 to 100";
|
||
}
|
||
});
|
||
|
||
await updateItem("books", bookId, { progress: Number(progress) });
|
||
|
||
console.log(`✅ Updated book progress to ${progress}%`);
|
||
};
|