UNPKG

l7note

Version:

Access your notion notes quick

69 lines (56 loc) 1.77 kB
import { Client } from '@notionhq/client'; import chalk from 'chalk'; import { exit } from 'process'; import prompts, { Choice, PromptObject } from 'prompts'; import { getSettingValueByName } from '../helper/getSettingValueByName.js'; import { markAsDeleteById } from '../noteActions/markAsDelete.js'; import { globalConfig } from '../setup.js'; const removeList = async () => { const notion = new Client({ auth: globalConfig.token }); if (!globalConfig.dbId) { console.log(chalk.red('No default database selected')); return; } if (globalConfig.optionalArgs.length > 0) { const pageId = getSettingValueByName('-h'); await markAsDeleteById(pageId); console.log(chalk.red('Note got deleted')); return; } const response = await notion.databases.query({ database_id: globalConfig.dbId, }); if (response.results.length <= 0) { console.log(chalk.blue('No results found')); exit(1); } const onListCancel = () => { console.log('BYE'); exit(1); }; const listOptions: prompts.Options = { onCancel: onListCancel }; let choises = response.results.map((note: any) => { const newChoise: Choice = { title: note.properties.Title.title[0] ? note.properties.Title.title[0].plain_text : '', value: note.id, }; return newChoise; }); do { console.clear(); const noteDisplayList: PromptObject[] = [ { type: 'select', name: 'selected', message: `Selet the note you want to ${chalk.red('delete')}:`, choices: choises, }, ]; const res = await prompts(noteDisplayList, listOptions); choises = choises.filter(choise => choise.value != res.selected); await markAsDeleteById(res.selected); } while (true); }; export { removeList };