1
1
import { get , writable } from "svelte/store" ;
2
2
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" ;
7
7
import { ViewState } from "src/types/ViewState" ;
8
- import DownloadedEpisode from "src/types/DownloadedEpisode" ;
8
+ import type DownloadedEpisode from "src/types/DownloadedEpisode" ;
9
9
import { TFile } from "obsidian" ;
10
- import { LocalEpisode } from "src/types/LocalEpisode" ;
10
+ import type { LocalEpisode } from "src/types/LocalEpisode" ;
11
11
12
12
export const plugin = writable < PodNotes > ( ) ;
13
13
export const currentTime = writable < number > ( 0 ) ;
14
14
export const duration = writable < number > ( 0 ) ;
15
15
16
- export const currentEpisode = ( function ( ) {
16
+ export const currentEpisode = ( ( ) => {
17
17
const store = writable < Episode > ( ) ;
18
18
const { subscribe, update } = store ;
19
19
@@ -30,12 +30,7 @@ export const currentEpisode = (function () {
30
30
const ct = get ( currentTime ) ;
31
31
const dur = get ( duration ) ;
32
32
const isFinished = ct === dur ;
33
- playedEpisodes . setEpisodeTime (
34
- previousEpisode ,
35
- ct ,
36
- dur ,
37
- isFinished
38
- ) ;
33
+ playedEpisodes . setEpisodeTime ( previousEpisode , ct , dur , isFinished ) ;
39
34
}
40
35
41
36
return newEpisode ;
@@ -45,7 +40,7 @@ export const currentEpisode = (function () {
45
40
} ) ( ) ;
46
41
47
42
export const isPaused = writable < boolean > ( true ) ;
48
- export const playedEpisodes = ( function ( ) {
43
+ export const playedEpisodes = ( ( ) => {
49
44
const store = writable < { [ key : string ] : PlayedEpisode } > ( { } ) ;
50
45
const { subscribe, update, set } = store ;
51
46
@@ -57,7 +52,7 @@ export const playedEpisodes = (function () {
57
52
episode : Episode ,
58
53
time : number ,
59
54
duration : number ,
60
- finished : boolean
55
+ finished : boolean ,
61
56
) => {
62
57
update ( ( playedEpisodes ) => {
63
58
playedEpisodes [ episode . title ] = {
@@ -100,17 +95,19 @@ export const playedEpisodes = (function () {
100
95
} ;
101
96
} ) ( ) ;
102
97
98
+ export const podcastsUpdated = writable ( 0 ) ;
99
+
103
100
export const savedFeeds = writable < { [ podcastName : string ] : PodcastFeed } > ( { } ) ;
104
101
105
102
export const episodeCache = writable < { [ podcastName : string ] : Episode [ ] } > ( { } ) ;
106
103
107
- export const downloadedEpisodes = ( function ( ) {
104
+ export const downloadedEpisodes = ( ( ) => {
108
105
const store = writable < { [ podcastName : string ] : DownloadedEpisode [ ] } > ( { } ) ;
109
106
const { subscribe, update, set } = store ;
110
107
111
108
function isEpisodeDownloaded ( episode : Episode ) : boolean {
112
109
return get ( store ) [ episode . podcastName ] ?. some (
113
- ( e ) => e . title === episode . title
110
+ ( e ) => e . title === episode . title ,
114
111
) ;
115
112
}
116
113
@@ -120,41 +117,48 @@ export const downloadedEpisodes = (function () {
120
117
update,
121
118
isEpisodeDownloaded,
122
119
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
+ }
137
138
138
- downloadedEpisodes [ episode . podcastName ] = podcastEpisodes ;
139
- return downloadedEpisodes ;
140
- } ) ;
139
+ downloadedEpisodes [ episode . podcastName ] = podcastEpisodes ;
140
+ return downloadedEpisodes ;
141
+ } ,
142
+ ) ;
141
143
} ,
142
144
removeEpisode : ( episode : Episode , removeFile : boolean ) => {
143
145
update ( ( downloadedEpisodes ) => {
144
- const podcastEpisodes =
145
- downloadedEpisodes [ episode . podcastName ] || [ ] ;
146
+ const podcastEpisodes = downloadedEpisodes [ episode . podcastName ] || [ ] ;
146
147
const index = podcastEpisodes . findIndex (
147
- ( e ) => e . title === episode . title
148
+ ( e ) => e . title === episode . title ,
148
149
) ;
149
150
const filePath = podcastEpisodes [ index ] . filePath ;
150
151
151
152
podcastEpisodes . splice ( index , 1 ) ;
152
153
153
154
if ( removeFile ) {
154
155
try {
156
+ // @ts -ignore: app is not defined in the global scope anymore, but is still
157
+ // available. Need to fix this later
155
158
const file = app . vault . getAbstractFileByPath ( filePath ) ;
156
159
157
160
if ( file instanceof TFile ) {
161
+ // @ts -ignore
158
162
app . vault . delete ( file ) ;
159
163
}
160
164
} catch ( error ) {
@@ -168,13 +172,13 @@ export const downloadedEpisodes = (function () {
168
172
} ,
169
173
getEpisode : ( episode : Episode ) => {
170
174
return get ( store ) [ episode . podcastName ] ?. find (
171
- ( e ) => e . title === episode . title
175
+ ( e ) => e . title === episode . title ,
172
176
) ;
173
177
} ,
174
178
} ;
175
179
} ) ( ) ;
176
180
177
- export const queue = ( function ( ) {
181
+ export const queue = ( ( ) => {
178
182
const store = writable < Playlist > ( {
179
183
icon : "list-ordered" ,
180
184
name : "Queue" ,
@@ -197,7 +201,7 @@ export const queue = (function () {
197
201
remove : ( episode : Episode ) => {
198
202
update ( ( queue ) => {
199
203
queue . episodes = queue . episodes . filter (
200
- ( e ) => e . title !== episode . title
204
+ ( e ) => e . title !== episode . title ,
201
205
) ;
202
206
return queue ;
203
207
} ) ;
@@ -224,7 +228,7 @@ export const favorites = writable<Playlist>({
224
228
shouldRepeat : false ,
225
229
} ) ;
226
230
227
- export const localFiles = function ( ) {
231
+ export const localFiles = ( ( ) => {
228
232
const store = writable < Playlist > ( {
229
233
icon : "folder" ,
230
234
name : "Local Files" ,
@@ -240,22 +244,24 @@ export const localFiles = function () {
240
244
update,
241
245
set,
242
246
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
+
245
249
return ep as LocalEpisode ;
246
250
} ,
247
251
updateStreamUrl : ( title : string , newUrl : string ) : void => {
248
252
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
+
251
255
if ( idx !== - 1 ) playlist . episodes [ idx ] . streamUrl = newUrl ;
252
256
253
257
return playlist ;
254
258
} ) ;
255
259
} ,
256
260
addEpisode : ( episode : LocalEpisode ) : void => {
257
261
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
+ ) ;
259
265
260
266
if ( idx !== - 1 ) {
261
267
playlist . episodes [ idx ] = episode ;
@@ -265,14 +271,14 @@ export const localFiles = function () {
265
271
266
272
return playlist ;
267
273
} ) ;
268
- }
269
- }
270
- } ( ) ;
274
+ } ,
275
+ } ;
276
+ } ) ( ) ;
271
277
272
278
export const playlists = writable < { [ name : string ] : Playlist } > ( { } ) ;
273
279
274
280
export const podcastView = writable < HTMLDivElement > ( ) ;
275
- export const viewState = ( function ( ) {
281
+ export const viewState = ( ( ) => {
276
282
const store = writable < ViewState > ( ViewState . PodcastGrid ) ;
277
283
const { subscribe, set } = store ;
278
284
0 commit comments