Skip to content

Commit

Permalink
fix: fixes deletion of default layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Aug 14, 2023
1 parent a5a0141 commit 06f33d9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export default class StatBlockPlugin extends Plugin implements StatblockAPI {
!this.settings.defaultLayouts.find((l) => l.id == layout.id)
);
}
console.log(this.settings.defaultLayouts.filter((f) => f.removed));

function fixSpells(...blocks: StatblockItem[]) {
for (const block of blocks) {
Expand Down Expand Up @@ -570,7 +571,10 @@ export default class StatBlockPlugin extends Plugin implements StatblockAPI {
}

get layouts() {
return [...this.settings.defaultLayouts, ...this.settings.layouts];
return [
...this.settings.defaultLayouts.filter((f) => !f.removed),
...this.settings.layouts
];
}

get defaultLayout() {
Expand Down
25 changes: 21 additions & 4 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,23 @@ export default class StatblockSettingTab extends PluginSettingTab {
) {
layoutContainer.empty();

if (this.plugin.settings.defaultLayouts.some((f) => f.removed)) {
new Setting(layoutContainer)
.setName("Restore Default Layouts")
.addButton((b) => {
b.setIcon("rotate-ccw").onClick(async () => {
for (const layout of this.plugin.settings
.defaultLayouts) {
delete layout.removed;
}
await this.plugin.saveSettings();
this.generateLayouts(outerContainer);
});
});
}
for (const layout of this.plugin.settings.defaultLayouts) {
if (layout.removed) continue;

const setting = new Setting(layoutContainer)
.setName(layout.name)
.addExtraButton((b) => {
Expand Down Expand Up @@ -617,11 +633,12 @@ export default class StatblockSettingTab extends PluginSettingTab {
b.setIcon("trash")
.setTooltip("Delete")
.onClick(async () => {
this.plugin.settings.layouts =
this.plugin.settings.layouts.filter(
(l) => l.id !== layout.id
);
layout.removed = true;
await this.plugin.saveSettings();
console.log(
"🚀 ~ file: settings.ts:623 ~ layout:",
layout
);

this.generateLayouts(outerContainer);
});
Expand Down
1 change: 1 addition & 0 deletions types/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@ export interface Layout {

export interface DefaultLayout extends Layout {
edited?: boolean;
removed?: boolean;
}

0 comments on commit 06f33d9

Please sign in to comment.