Skip to content

Commit 2633603

Browse files
committed
fix: mount views with svelte api (#134)
1 parent 79e5b80 commit 2633603

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/ui/PodcastView/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import type { WorkspaceLeaf } from "obsidian";
33
import type { IPodNotes } from "../../types/IPodNotes";
44
import { VIEW_TYPE } from "../../constants";
55
import PodcastView from "./PodcastView.svelte";
6+
import { mount, unmount } from "svelte";
67

78
export class MainView extends ItemView {
89
constructor(leaf: WorkspaceLeaf, private plugin: IPodNotes) {
910
super(leaf);
1011
}
1112

12-
private podcastView: PodcastView | null = null;
13+
private podcastView: Record<string, unknown> | null = null;
1314

1415
override getViewType(): string {
1516
return VIEW_TYPE;
@@ -24,13 +25,16 @@ export class MainView extends ItemView {
2425
}
2526

2627
protected override async onOpen(): Promise<void> {
27-
this.podcastView = new PodcastView({
28+
this.podcastView = mount(PodcastView, {
2829
target: this.contentEl,
2930
});
3031
}
3132

3233
protected override async onClose(): Promise<void> {
33-
this.podcastView?.$destroy();
34+
if (this.podcastView) {
35+
await unmount(this.podcastView);
36+
this.podcastView = null;
37+
}
3438

3539
this.contentEl.empty();
3640
}

src/ui/settings/PodNotesSettingsTab.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import type PodNotes from "../../main";
1010
import PodcastQueryGrid from "./PodcastQueryGrid.svelte";
1111
import PlaylistManager from "./PlaylistManager.svelte";
12+
import { mount, unmount } from "svelte";
1213
import {
1314
DownloadPathTemplateEngine,
1415
FilePathTemplateEngine,
@@ -23,8 +24,8 @@ import { clearFeedCache } from "src/services/FeedCacheService";
2324
export class PodNotesSettingsTab extends PluginSettingTab {
2425
plugin: PodNotes;
2526

26-
private podcastQueryGrid!: PodcastQueryGrid;
27-
private playlistManager!: PlaylistManager;
27+
private podcastQueryGrid: Record<string, unknown> | null = null;
28+
private playlistManager: Record<string, unknown> | null = null;
2829

2930
private settingsTab: PodNotesSettingsTab;
3031

@@ -51,7 +52,7 @@ export class PodNotesSettingsTab extends PluginSettingTab {
5152
.setDesc("Search for podcasts by name or custom feed URL.");
5253

5354
const queryGridContainer = settingsContainer.createDiv();
54-
this.podcastQueryGrid = new PodcastQueryGrid({
55+
this.podcastQueryGrid = mount(PodcastQueryGrid, {
5556
target: queryGridContainer,
5657
});
5758

@@ -61,7 +62,7 @@ export class PodNotesSettingsTab extends PluginSettingTab {
6162
.setDesc("Add playlists to gather podcast episodes.");
6263

6364
const playlistManagerContainer = settingsContainer.createDiv();
64-
this.playlistManager = new PlaylistManager({
65+
this.playlistManager = mount(PlaylistManager, {
6566
target: playlistManagerContainer,
6667
});
6768

@@ -76,8 +77,15 @@ export class PodNotesSettingsTab extends PluginSettingTab {
7677
}
7778

7879
override hide(): void {
79-
this.podcastQueryGrid?.$destroy();
80-
this.playlistManager?.$destroy();
80+
if (this.podcastQueryGrid) {
81+
void unmount(this.podcastQueryGrid);
82+
this.podcastQueryGrid = null;
83+
}
84+
85+
if (this.playlistManager) {
86+
void unmount(this.playlistManager);
87+
this.playlistManager = null;
88+
}
8189
}
8290

8391
private addDefaultPlaybackRateSetting(container: HTMLElement): void {

0 commit comments

Comments
 (0)