diff --git a/src/constants.ts b/src/constants.ts index 0d5354d..315a8c3 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -34,6 +34,7 @@ export const DEFAULT_SETTINGS: IPodNotesSettings = { podNotes: {}, defaultPlaybackRate: 1, defaultVolume: 1, + hidePlayedEpisodes: false, playedEpisodes: {}, favorites: { ...FAVORITES_SETTINGS, diff --git a/src/main.ts b/src/main.ts index 22fb81b..27f464c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,7 @@ import { playlists, queue, savedFeeds, + hidePlayedEpisodes, volume, } from "src/store"; import { Plugin, type WorkspaceLeaf } from "obsidian"; @@ -29,6 +30,7 @@ import { QueueController } from "./store_controllers/QueueController"; import { FavoritesController } from "./store_controllers/FavoritesController"; import type { Episode } from "./types/Episode"; import CurrentEpisodeController from "./store_controllers/CurrentEpisodeController"; +import { HidePlayedEpisodesController } from "./store_controllers/HidePlayedEpisodesController"; import { TimestampTemplateEngine } from "./TemplateEngine"; import createPodcastNote from "./createPodcastNote"; import downloadEpisodeWithNotice from "./downloadEpisode"; @@ -66,6 +68,7 @@ export default class PodNotes extends Plugin implements IPodNotes { private downloadedEpisodesController?: StoreController<{ [podcastName: string]: DownloadedEpisode[]; }>; + private hidePlayedEpisodesController?: StoreController; private transcriptionService?: TranscriptionService; private volumeUnsubscribe?: Unsubscriber; @@ -87,6 +90,7 @@ export default class PodNotes extends Plugin implements IPodNotes { if (this.settings.currentEpisode) { currentEpisode.set(this.settings.currentEpisode); } + hidePlayedEpisodes.set(this.settings.hidePlayedEpisodes); volume.set( Math.min(1, Math.max(0, this.settings.defaultVolume ?? 1)), ); @@ -108,6 +112,10 @@ export default class PodNotes extends Plugin implements IPodNotes { currentEpisode, this, ).on(); + this.hidePlayedEpisodesController = new HidePlayedEpisodesController( + hidePlayedEpisodes, + this, + ).on(); this.api = new API(); this.volumeUnsubscribe = volume.subscribe((value) => { @@ -358,6 +366,7 @@ export default class PodNotes extends Plugin implements IPodNotes { this.localFilesController?.off(); this.downloadedEpisodesController?.off(); this.currentEpisodeController?.off(); + this.hidePlayedEpisodesController?.off(); this.volumeUnsubscribe?.(); } diff --git a/src/store/index.ts b/src/store/index.ts index 05281a2..d5035f4 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -13,6 +13,7 @@ export const plugin = writable(); export const currentTime = writable(0); export const duration = writable(0); export const volume = writable(1); +export const hidePlayedEpisodes = writable(false); export const currentEpisode = (() => { const store = writable(); diff --git a/src/store_controllers/HidePlayedEpisodesController.ts b/src/store_controllers/HidePlayedEpisodesController.ts new file mode 100644 index 0000000..7f6736d --- /dev/null +++ b/src/store_controllers/HidePlayedEpisodesController.ts @@ -0,0 +1,19 @@ +import type { Writable } from "svelte/store"; +import type { IPodNotes } from "../types/IPodNotes"; +import { StoreController } from "../types/StoreController"; + +export class HidePlayedEpisodesController extends StoreController { + private plugin: IPodNotes; + + constructor(store: Writable, plugin: IPodNotes) { + super(store); + this.plugin = plugin; + } + + protected override onChange(value: boolean) { + if (this.plugin.settings.hidePlayedEpisodes === value) return; + + this.plugin.settings.hidePlayedEpisodes = value; + this.plugin.saveSettings(); + } +} diff --git a/src/types/IPodNotesSettings.ts b/src/types/IPodNotesSettings.ts index 1e56c4f..70b80dc 100644 --- a/src/types/IPodNotesSettings.ts +++ b/src/types/IPodNotesSettings.ts @@ -10,6 +10,7 @@ export interface IPodNotesSettings { podNotes: { [episodeName: string]: PodNote }; defaultPlaybackRate: number; defaultVolume: number; + hidePlayedEpisodes: boolean; playedEpisodes: { [episodeName: string]: PlayedEpisode }; skipBackwardLength: number; skipForwardLength: number; diff --git a/src/ui/PodcastView/EpisodeList.svelte b/src/ui/PodcastView/EpisodeList.svelte index 3fa7312..6abee3b 100644 --- a/src/ui/PodcastView/EpisodeList.svelte +++ b/src/ui/PodcastView/EpisodeList.svelte @@ -1,15 +1,14 @@