File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -34,16 +34,23 @@ export const validateInput = () => {
3434} ;
3535
3636export const updateInputValue = ( value ) => {
37+ if ( value === null ) return ;
3738 state . form . inputValue = value ;
38- state . form . errors = null ;
39+ if ( state . form . errors ) state . form . errors = null ;
3940} ;
4041
4142export const addRssFeed = ( ) => {
42- fetchRssData ( state . form . inputValue )
43+ return fetchRssData ( state . form . inputValue )
4344 . then ( ( xmlString ) => parseRss ( xmlString ) )
4445 . then ( ( { channel, items } ) => {
46+ if ( state . feeds . some ( ( feed ) => feed . link === channel . link ) ) {
47+ state . form . errors = i18next . t ( "no_duplicate" ) ;
48+ return ;
49+ }
50+ const existingIds = new Set ( state . posts . map ( ( post ) => post . id ) ) ;
51+ const newItems = items . filter ( ( item ) => ! existingIds . has ( item . id ) ) ;
4552 state . feeds = [ ...state . feeds , channel ] ;
46- state . posts = [ ...state . posts , ...items ] ;
53+ state . posts = [ ...state . posts , ...newItems ] ;
4754 state . form . inputValue = "" ;
4855 console . log ( "обновлён список rss" , state . feeds ) ;
4956 } )
You can’t perform that action at this time.
0 commit comments