Skip to content

Commit 732f094

Browse files
authored
fix: persist hide-played toggle (#144)
1 parent 7e633ff commit 732f094

6 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const DEFAULT_SETTINGS: IPodNotesSettings = {
3434
podNotes: {},
3535
defaultPlaybackRate: 1,
3636
defaultVolume: 1,
37+
hidePlayedEpisodes: false,
3738
playedEpisodes: {},
3839
favorites: {
3940
...FAVORITES_SETTINGS,

src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
playlists,
88
queue,
99
savedFeeds,
10+
hidePlayedEpisodes,
1011
volume,
1112
} from "src/store";
1213
import { Plugin, type WorkspaceLeaf } from "obsidian";
@@ -29,6 +30,7 @@ import { QueueController } from "./store_controllers/QueueController";
2930
import { FavoritesController } from "./store_controllers/FavoritesController";
3031
import type { Episode } from "./types/Episode";
3132
import CurrentEpisodeController from "./store_controllers/CurrentEpisodeController";
33+
import { HidePlayedEpisodesController } from "./store_controllers/HidePlayedEpisodesController";
3234
import { TimestampTemplateEngine } from "./TemplateEngine";
3335
import createPodcastNote from "./createPodcastNote";
3436
import downloadEpisodeWithNotice from "./downloadEpisode";
@@ -66,6 +68,7 @@ export default class PodNotes extends Plugin implements IPodNotes {
6668
private downloadedEpisodesController?: StoreController<{
6769
[podcastName: string]: DownloadedEpisode[];
6870
}>;
71+
private hidePlayedEpisodesController?: StoreController<boolean>;
6972
private transcriptionService?: TranscriptionService;
7073
private volumeUnsubscribe?: Unsubscriber;
7174

@@ -87,6 +90,7 @@ export default class PodNotes extends Plugin implements IPodNotes {
8790
if (this.settings.currentEpisode) {
8891
currentEpisode.set(this.settings.currentEpisode);
8992
}
93+
hidePlayedEpisodes.set(this.settings.hidePlayedEpisodes);
9094
volume.set(
9195
Math.min(1, Math.max(0, this.settings.defaultVolume ?? 1)),
9296
);
@@ -108,6 +112,10 @@ export default class PodNotes extends Plugin implements IPodNotes {
108112
currentEpisode,
109113
this,
110114
).on();
115+
this.hidePlayedEpisodesController = new HidePlayedEpisodesController(
116+
hidePlayedEpisodes,
117+
this,
118+
).on();
111119

112120
this.api = new API();
113121
this.volumeUnsubscribe = volume.subscribe((value) => {
@@ -358,6 +366,7 @@ export default class PodNotes extends Plugin implements IPodNotes {
358366
this.localFilesController?.off();
359367
this.downloadedEpisodesController?.off();
360368
this.currentEpisodeController?.off();
369+
this.hidePlayedEpisodesController?.off();
361370
this.volumeUnsubscribe?.();
362371
}
363372

src/store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const plugin = writable<PodNotes>();
1313
export const currentTime = writable<number>(0);
1414
export const duration = writable<number>(0);
1515
export const volume = writable<number>(1);
16+
export const hidePlayedEpisodes = writable<boolean>(false);
1617

1718
export const currentEpisode = (() => {
1819
const store = writable<Episode>();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Writable } from "svelte/store";
2+
import type { IPodNotes } from "../types/IPodNotes";
3+
import { StoreController } from "../types/StoreController";
4+
5+
export class HidePlayedEpisodesController extends StoreController<boolean> {
6+
private plugin: IPodNotes;
7+
8+
constructor(store: Writable<boolean>, plugin: IPodNotes) {
9+
super(store);
10+
this.plugin = plugin;
11+
}
12+
13+
protected override onChange(value: boolean) {
14+
if (this.plugin.settings.hidePlayedEpisodes === value) return;
15+
16+
this.plugin.settings.hidePlayedEpisodes = value;
17+
this.plugin.saveSettings();
18+
}
19+
}

src/types/IPodNotesSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface IPodNotesSettings {
1010
podNotes: { [episodeName: string]: PodNote };
1111
defaultPlaybackRate: number;
1212
defaultVolume: number;
13+
hidePlayedEpisodes: boolean;
1314
playedEpisodes: { [episodeName: string]: PlayedEpisode };
1415
skipBackwardLength: number;
1516
skipForwardLength: number;

src/ui/PodcastView/EpisodeList.svelte

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<script lang="ts">
22
import type { Episode } from "src/types/Episode";
3-
import { createEventDispatcher, onMount } from "svelte";
3+
import { createEventDispatcher } from "svelte";
44
import EpisodeListItem from "./EpisodeListItem.svelte";
5-
import { playedEpisodes } from "src/store";
5+
import { hidePlayedEpisodes, playedEpisodes } from "src/store";
66
import Icon from "../obsidian/Icon.svelte";
77
import Text from "../obsidian/Text.svelte";
88
99
export let episodes: Episode[] = [];
1010
export let showThumbnails: boolean = false;
1111
export let showListMenu: boolean = true;
12-
let hidePlayedEpisodes: boolean = false;
1312
let searchInputQuery: string = "";
1413
1514
const dispatch = createEventDispatcher();
@@ -48,11 +47,11 @@
4847
/>
4948
</div>
5049
<Icon
51-
icon={hidePlayedEpisodes ? "eye-off" : "eye"}
50+
icon={$hidePlayedEpisodes ? "eye-off" : "eye"}
5251
size={25}
53-
label={hidePlayedEpisodes ? "Show played episodes" : "Hide played episodes"}
54-
pressed={hidePlayedEpisodes}
55-
on:click={() => (hidePlayedEpisodes = !hidePlayedEpisodes)}
52+
label={$hidePlayedEpisodes ? "Show played episodes" : "Hide played episodes"}
53+
pressed={$hidePlayedEpisodes}
54+
on:click={() => hidePlayedEpisodes.update((value) => !value)}
5655
/>
5756
<Icon
5857
icon="refresh-cw"
@@ -69,7 +68,7 @@
6968
{/if}
7069
{#each episodes as episode (episode.url || episode.streamUrl || `${episode.title}-${episode.episodeDate ?? ""}`)}
7170
{@const episodePlayed = $playedEpisodes[episode.title]?.finished}
72-
{#if !hidePlayedEpisodes || !episodePlayed}
71+
{#if !$hidePlayedEpisodes || !episodePlayed}
7372
<EpisodeListItem
7473
{episode}
7574
episodeFinished={episodePlayed}

0 commit comments

Comments
 (0)