@@ -6,8 +6,8 @@ import BeatLoader from 'react-spinners/BeatLoader'
66import Toggle from 'react-toggle'
77import 'react-toggle/style.css'
88import { SUPPORTED_CARDS , SUPPORTED_SEARCH_ENGINES , supportLink } from 'src/config'
9+ import { getRssUrlFeed } from 'src/features/cards/api/getRssFeed'
910import { Tag , useRemoteConfigStore } from 'src/features/remoteConfig'
10- import { getRssUrlFeed } from 'src/features/rssFeed/api/getRssFeed'
1111import {
1212 identifyUserCards ,
1313 identifyUserLanguages ,
@@ -152,27 +152,27 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
152152 }
153153
154154 // check if card exists
155- const exists = userCustomCards . find ( ( card ) => card . feedUrl === rssUrl )
156- if ( exists ) {
157- setRssInputError ( 'RSS Feed already exists' )
158- return
159- }
160155
161156 setIsRssInputLoading ( true )
162157
163158 // get rssUrl Info
164159 try {
165160 const info = await getRssUrlFeed ( rssUrl )
161+ let value = info . title . toLowerCase ( )
162+ const exists = userCustomCards . find ( ( card ) => card . link === info . link )
163+ if ( exists ) {
164+ throw Error ( 'RSS Feed already exists' , { cause : 'EXISTS' } )
165+ }
166+
166167 let customCard : SupportedCardType = {
167168 feedUrl : rssUrl . replace ( 'https:' , 'http:' ) ,
168169 label : info . title ,
169- value : info . title . toLowerCase ( ) ,
170- analyticsTag : info . title . toLowerCase ( ) ,
170+ value,
171+ analyticsTag : value ,
171172 link : info . link ,
172173 type : 'rss' ,
173- // icon: <BsFillRssFill className="blockHeaderWhite" /> ,
174+ icon : info . icon ,
174175 }
175- // add card to userCustomCards and selected cards
176176 setUserCustomCards ( [ ...userCustomCards , customCard ] )
177177 const newCards = [
178178 ...cards ,
@@ -183,8 +183,10 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
183183 identifyUserCards ( newCards . map ( ( card ) => card . name ) )
184184 trackRssSourceAdd ( customCard . value )
185185 setRssUrl ( '' )
186- } catch ( err ) {
187- setRssInputError ( 'rssInputError occured. Please check and try again.' )
186+ } catch ( err : any ) {
187+ setRssInputError (
188+ err ?. cause === 'EXISTS' ? err ?. message : 'Error occured. Please check and try again.'
189+ )
188190 } finally {
189191 setIsRssInputLoading ( false )
190192 }
0 commit comments