File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,29 @@ initI18n()
2929
3030 const watched = initView ( state , elements )
3131
32+ const updateFeeds = ( ) => {
33+ const promises = watched . feeds . map ( feed =>
34+ loadFeed ( feed . url )
35+ . then ( xml => parseFeed ( xml ) )
36+ . then ( ( { posts } ) => {
37+ const existingLinks = watched . posts
38+ . filter ( p => p . feedId === feed . id )
39+ . map ( p => p . link )
40+
41+ const newPosts = posts . filter ( p => ! existingLinks . includes ( p . link ) )
42+
43+ if ( newPosts . length > 0 ) {
44+ watched . posts . push ( ...newPosts )
45+ }
46+ } )
47+ . catch ( ( ) => { } ) ,
48+ )
49+
50+ Promise . all ( promises ) . finally ( ( ) => {
51+ setTimeout ( updateFeeds , 5000 )
52+ } )
53+ }
54+
3255 elements . form . addEventListener ( 'submit' , ( e ) => {
3356 e . preventDefault ( )
3457
@@ -65,6 +88,10 @@ initI18n()
6588 watched . feeds . push ( normalizedFeed )
6689 watched . posts . push ( ...normalizedPosts )
6790 watched . form . status = 'success'
91+
92+ if ( watched . feeds . length === 1 ) {
93+ updateFeeds ( )
94+ }
6895 } )
6996 . catch ( ( err ) => {
7097 // errors
Original file line number Diff line number Diff line change 11import generateId from './generateId'
22
3- export const parseFeed = xmlString => {
3+ export const parseFeed = ( xmlString ) => {
44 const parser = new DOMParser ( )
55 const doc = parser . parseFromString ( xmlString , 'text/xml' )
66
You can’t perform that action at this time.
0 commit comments