refactor(react/collections/table): use class-based API

This commit is contained in:
Elian Doran
2025-09-11 19:14:54 +03:00
parent efcdac75e4
commit 2b452a18df
3 changed files with 49 additions and 32 deletions

View File

@@ -2,30 +2,39 @@ import FNote from "../../../entities/fnote";
import attributes from "../../../services/attributes";
import note_create from "../../../services/note_create";
export async function createNewItem(parentNote: FNote, column: string) {
try {
// Get the parent note path
const parentNotePath = parentNote.noteId;
const statusAttribute = parentNote.getLabelValue("board:groupBy") ?? "status";
export default class BoardApi {
// Create a new note as a child of the parent note
const { note: newNote } = await note_create.createNote(parentNotePath, {
activate: false,
title: "New item"
});
constructor(
private parentNote: FNote,
private statusAttribute: string
) {};
if (newNote) {
// Set the status label to place it in the correct column
await changeColumn(newNote.noteId, column, statusAttribute);
async createNewItem(column: string) {
try {
// Get the parent note path
const parentNotePath = this.parentNote.noteId;
// Start inline editing of the newly created card
//this.startInlineEditingCard(newNote.noteId);
// Create a new note as a child of the parent note
const { note: newNote } = await note_create.createNote(parentNotePath, {
activate: false,
title: "New item"
});
if (newNote) {
// Set the status label to place it in the correct column
await this.changeColumn(newNote.noteId, column);
// Start inline editing of the newly created card
//this.startInlineEditingCard(newNote.noteId);
}
} catch (error) {
console.error("Failed to create new item:", error);
}
} catch (error) {
console.error("Failed to create new item:", error);
}
async changeColumn(noteId: string, newColumn: string) {
await attributes.setLabel(noteId, this.statusAttribute, newColumn);
}
}
export async function changeColumn(noteId: string, newColumn: string, statusAttribute: string) {
await attributes.setLabel(noteId, statusAttribute, newColumn);
}