Skip to content

Commit c688e3e

Browse files
committed
feat: redesign podcast view in settings: shows all your podcasts by default, search shows found podcasts, and redesigned how the results look
1 parent 13557db commit c688e3e

File tree

5 files changed

+186
-127
lines changed

5 files changed

+186
-127
lines changed

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ export default class PodNotes extends Plugin implements IPodNotes {
106106
id: "podnotes-show-leaf",
107107
name: "Show PodNotes",
108108
icon: "podcast" as IconType,
109-
checkCallback(checking: boolean) {
109+
checkCallback: function (checking: boolean) {
110110
if (checking) {
111111
return !this.app.workspace.getLeavesOfType(VIEW_TYPE).length;
112112
}
113113

114114
this.app.workspace.getRightLeaf(false).setViewState({
115115
type: VIEW_TYPE,
116116
});
117-
},
117+
}.bind(this),
118118
});
119119

120120
this.addCommand({

src/store/index.ts

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { get, writable } from "svelte/store";
22
import type PodNotes from "src/main";
3-
import { Episode } from "src/types/Episode";
4-
import { PlayedEpisode } from "src/types/PlayedEpisode";
5-
import { PodcastFeed } from "src/types/PodcastFeed";
6-
import { Playlist } from "src/types/Playlist";
3+
import type { Episode } from "src/types/Episode";
4+
import type { PlayedEpisode } from "src/types/PlayedEpisode";
5+
import type { PodcastFeed } from "src/types/PodcastFeed";
6+
import type { Playlist } from "src/types/Playlist";
77
import { ViewState } from "src/types/ViewState";
8-
import DownloadedEpisode from "src/types/DownloadedEpisode";
8+
import type DownloadedEpisode from "src/types/DownloadedEpisode";
99
import { TFile } from "obsidian";
10-
import { LocalEpisode } from "src/types/LocalEpisode";
10+
import type { LocalEpisode } from "src/types/LocalEpisode";
1111

1212
export const plugin = writable<PodNotes>();
1313
export const currentTime = writable<number>(0);
1414
export const duration = writable<number>(0);
1515

16-
export const currentEpisode = (function () {
16+
export const currentEpisode = (() => {
1717
const store = writable<Episode>();
1818
const { subscribe, update } = store;
1919

@@ -30,12 +30,7 @@ export const currentEpisode = (function () {
3030
const ct = get(currentTime);
3131
const dur = get(duration);
3232
const isFinished = ct === dur;
33-
playedEpisodes.setEpisodeTime(
34-
previousEpisode,
35-
ct,
36-
dur,
37-
isFinished
38-
);
33+
playedEpisodes.setEpisodeTime(previousEpisode, ct, dur, isFinished);
3934
}
4035

4136
return newEpisode;
@@ -45,7 +40,7 @@ export const currentEpisode = (function () {
4540
})();
4641

4742
export const isPaused = writable<boolean>(true);
48-
export const playedEpisodes = (function () {
43+
export const playedEpisodes = (() => {
4944
const store = writable<{ [key: string]: PlayedEpisode }>({});
5045
const { subscribe, update, set } = store;
5146

@@ -57,7 +52,7 @@ export const playedEpisodes = (function () {
5752
episode: Episode,
5853
time: number,
5954
duration: number,
60-
finished: boolean
55+
finished: boolean,
6156
) => {
6257
update((playedEpisodes) => {
6358
playedEpisodes[episode.title] = {
@@ -100,17 +95,19 @@ export const playedEpisodes = (function () {
10095
};
10196
})();
10297

98+
export const podcastsUpdated = writable(0);
99+
103100
export const savedFeeds = writable<{ [podcastName: string]: PodcastFeed }>({});
104101

105102
export const episodeCache = writable<{ [podcastName: string]: Episode[] }>({});
106103

107-
export const downloadedEpisodes = (function () {
104+
export const downloadedEpisodes = (() => {
108105
const store = writable<{ [podcastName: string]: DownloadedEpisode[] }>({});
109106
const { subscribe, update, set } = store;
110107

111108
function isEpisodeDownloaded(episode: Episode): boolean {
112109
return get(store)[episode.podcastName]?.some(
113-
(e) => e.title === episode.title
110+
(e) => e.title === episode.title,
114111
);
115112
}
116113

@@ -120,41 +117,48 @@ export const downloadedEpisodes = (function () {
120117
update,
121118
isEpisodeDownloaded,
122119
addEpisode: (episode: Episode, filePath: string, size: number) => {
123-
update((downloadedEpisodes) => {
124-
const podcastEpisodes =
125-
downloadedEpisodes[episode.podcastName] || [];
126-
127-
const idx = podcastEpisodes.findIndex(ep => ep.title === episode.title);
128-
if (idx !== -1) {
129-
podcastEpisodes[idx] = { ...episode, filePath, size };
130-
} else {
131-
podcastEpisodes.push({
132-
...episode,
133-
filePath,
134-
size,
135-
});
136-
}
120+
update(
121+
(downloadedEpisodes: {
122+
[podcastName: string]: DownloadedEpisode[];
123+
}) => {
124+
const podcastEpisodes = downloadedEpisodes[episode.podcastName] || [];
125+
126+
const idx = podcastEpisodes.findIndex(
127+
(ep) => ep.title === episode.title,
128+
);
129+
if (idx !== -1) {
130+
podcastEpisodes[idx] = { ...episode, filePath, size };
131+
} else {
132+
podcastEpisodes.push({
133+
...episode,
134+
filePath,
135+
size,
136+
});
137+
}
137138

138-
downloadedEpisodes[episode.podcastName] = podcastEpisodes;
139-
return downloadedEpisodes;
140-
});
139+
downloadedEpisodes[episode.podcastName] = podcastEpisodes;
140+
return downloadedEpisodes;
141+
},
142+
);
141143
},
142144
removeEpisode: (episode: Episode, removeFile: boolean) => {
143145
update((downloadedEpisodes) => {
144-
const podcastEpisodes =
145-
downloadedEpisodes[episode.podcastName] || [];
146+
const podcastEpisodes = downloadedEpisodes[episode.podcastName] || [];
146147
const index = podcastEpisodes.findIndex(
147-
(e) => e.title === episode.title
148+
(e) => e.title === episode.title,
148149
);
149150
const filePath = podcastEpisodes[index].filePath;
150151

151152
podcastEpisodes.splice(index, 1);
152153

153154
if (removeFile) {
154155
try {
156+
// @ts-ignore: app is not defined in the global scope anymore, but is still
157+
// available. Need to fix this later
155158
const file = app.vault.getAbstractFileByPath(filePath);
156159

157160
if (file instanceof TFile) {
161+
// @ts-ignore
158162
app.vault.delete(file);
159163
}
160164
} catch (error) {
@@ -168,13 +172,13 @@ export const downloadedEpisodes = (function () {
168172
},
169173
getEpisode: (episode: Episode) => {
170174
return get(store)[episode.podcastName]?.find(
171-
(e) => e.title === episode.title
175+
(e) => e.title === episode.title,
172176
);
173177
},
174178
};
175179
})();
176180

177-
export const queue = (function () {
181+
export const queue = (() => {
178182
const store = writable<Playlist>({
179183
icon: "list-ordered",
180184
name: "Queue",
@@ -197,7 +201,7 @@ export const queue = (function () {
197201
remove: (episode: Episode) => {
198202
update((queue) => {
199203
queue.episodes = queue.episodes.filter(
200-
(e) => e.title !== episode.title
204+
(e) => e.title !== episode.title,
201205
);
202206
return queue;
203207
});
@@ -224,7 +228,7 @@ export const favorites = writable<Playlist>({
224228
shouldRepeat: false,
225229
});
226230

227-
export const localFiles = function () {
231+
export const localFiles = (() => {
228232
const store = writable<Playlist>({
229233
icon: "folder",
230234
name: "Local Files",
@@ -240,22 +244,24 @@ export const localFiles = function () {
240244
update,
241245
set,
242246
getLocalEpisode: (title: string): LocalEpisode | undefined => {
243-
const ep = get(store).episodes.find(ep => ep.title === title);
244-
247+
const ep = get(store).episodes.find((ep) => ep.title === title);
248+
245249
return ep as LocalEpisode;
246250
},
247251
updateStreamUrl: (title: string, newUrl: string): void => {
248252
store.update((playlist) => {
249-
const idx = playlist.episodes.findIndex(ep => ep.title === title);
250-
253+
const idx = playlist.episodes.findIndex((ep) => ep.title === title);
254+
251255
if (idx !== -1) playlist.episodes[idx].streamUrl = newUrl;
252256

253257
return playlist;
254258
});
255259
},
256260
addEpisode: (episode: LocalEpisode): void => {
257261
store.update((playlist) => {
258-
const idx = playlist.episodes.findIndex(ep => ep.title === episode.title);
262+
const idx = playlist.episodes.findIndex(
263+
(ep) => ep.title === episode.title,
264+
);
259265

260266
if (idx !== -1) {
261267
playlist.episodes[idx] = episode;
@@ -265,14 +271,14 @@ export const localFiles = function () {
265271

266272
return playlist;
267273
});
268-
}
269-
}
270-
}();
274+
},
275+
};
276+
})();
271277

272278
export const playlists = writable<{ [name: string]: Playlist }>({});
273279

274280
export const podcastView = writable<HTMLDivElement>();
275-
export const viewState = (function () {
281+
export const viewState = (() => {
276282
const store = writable<ViewState>(ViewState.PodcastGrid);
277283
const { subscribe, set } = store;
278284

src/ui/settings/PodNotesSettingsTab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
TranscriptTemplateEngine,
1616
} from "../../TemplateEngine";
1717
import { FilePathTemplateEngine } from "../../TemplateEngine";
18-
import { episodeCache, savedFeeds } from "src/store";
18+
import { episodeCache, savedFeeds } from "src/store/index";
1919
import type { Episode } from "src/types/Episode";
2020
import { get } from "svelte/store";
2121
import { exportOPML, importOPML } from "src/opml";

0 commit comments

Comments
 (0)