[FEAT] csv explorer delete 버튼 추가

This commit is contained in:
ChangHangeol 2025-06-08 23:06:48 +09:00
parent ecf5a24247
commit 8ced697567
3 changed files with 29 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import { App, Modal, TFile } from 'obsidian';
import './styles/CSVExplorer.css';
/*
obsidian CSV ,\
@ -40,7 +41,26 @@ export default class CSVExplorerModal extends Modal {
Object.keys(this.CSVStructure).forEach((folder) => {
contentEl.createEl("h3", { text: folder });
this.CSVStructure[folder].forEach((file) => {
contentEl.createEl("p", { text: file });
const fileRow = contentEl.createEl("div", { cls: "file-row"});
// file name
fileRow.createEl("p", { text: file });
// file delete button
const bt = fileRow.createEl("button", { text: "Delete" });
bt.addEventListener("click", async () => {
const fileToDelete = this.CSVStructure[folder].find(f => f === file);
if (fileToDelete) {
const filePath = `${folder}/${fileToDelete}`;
const fileObj = this.app.vault.getAbstractFileByPath(filePath);
if (fileObj && fileObj instanceof TFile) {
await this.app.vault.delete(fileObj);
// Update the structure after deletion
this.CSVStructure[folder] = this.CSVStructure[folder].filter(f => f !== fileToDelete);
this.onOpen(); // Refresh the modal content
}
}
});
});
});
}

View file

@ -59,8 +59,6 @@ export const readCSVs_ = async (app: App, filePath: string, filter: string): Pro
// filter의 정규식에 맞는 파일들을 읽어와서 return;
const vault = app.vault;
const files = vault.getFiles();
console.log(`readCSVs_ : ${filePath}, filter: ${filter}`);
console.log(files);
const csvFiles: { key: string; value: CSVTable }[] = [];
for(const file of files) {

View file

@ -0,0 +1,8 @@
.file-row {
display: flex;
flex-direction: row;
gap: 2px;
justify-content: space-between;
margin-left: 10px;
}