l7note
Version:
Access your notion notes quick
72 lines (71 loc) • 3.23 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeList = void 0;
const client_1 = require("@notionhq/client");
const chalk_1 = __importDefault(require("chalk"));
const process_1 = require("process");
const prompts_1 = __importDefault(require("prompts"));
const getSettingValueByName_js_1 = require("../helper/getSettingValueByName.js");
const markAsDelete_js_1 = require("../noteActions/markAsDelete.js");
const setup_js_1 = require("../setup.js");
const removeList = () => __awaiter(void 0, void 0, void 0, function* () {
const notion = new client_1.Client({ auth: setup_js_1.globalConfig.token });
if (!setup_js_1.globalConfig.dbId) {
console.log(chalk_1.default.red('No default database selected'));
return;
}
if (setup_js_1.globalConfig.optionalArgs.length > 0) {
const pageId = (0, getSettingValueByName_js_1.getSettingValueByName)('-h');
yield (0, markAsDelete_js_1.markAsDeleteById)(pageId);
console.log(chalk_1.default.red('Note got deleted'));
return;
}
const response = yield notion.databases.query({
database_id: setup_js_1.globalConfig.dbId,
});
if (response.results.length <= 0) {
console.log(chalk_1.default.blue('No results found'));
(0, process_1.exit)(1);
}
const onListCancel = () => {
console.log('BYE');
(0, process_1.exit)(1);
};
const listOptions = { onCancel: onListCancel };
let choises = response.results.map((note) => {
const newChoise = {
title: note.properties.Title.title[0]
? note.properties.Title.title[0].plain_text
: '',
value: note.id,
};
return newChoise;
});
do {
console.clear();
const noteDisplayList = [
{
type: 'select',
name: 'selected',
message: `Selet the note you want to ${chalk_1.default.red('delete')}:`,
choices: choises,
},
];
const res = yield (0, prompts_1.default)(noteDisplayList, listOptions);
choises = choises.filter(choise => choise.value != res.selected);
yield (0, markAsDelete_js_1.markAsDeleteById)(res.selected);
} while (true);
});
exports.removeList = removeList;