@@ -2,11 +2,9 @@ import React, { useState } from 'react'
22import { VscClose } from 'react-icons/vsc'
33import ReactModal from 'react-modal'
44import Select , { ActionMeta , MultiValue , SingleValue } from 'react-select'
5- import BeatLoader from 'react-spinners/BeatLoader'
65import Toggle from 'react-toggle'
76import 'react-toggle/style.css'
87import { SUPPORTED_CARDS , SUPPORTED_SEARCH_ENGINES , supportLink } from 'src/config'
9- import { getRssUrlFeed } from 'src/features/cards/api/getRssFeed'
108import { Tag , useRemoteConfigStore } from 'src/features/remoteConfig'
119import {
1210 identifyUserCards ,
@@ -18,16 +16,15 @@ import {
1816 trackLanguageAdd ,
1917 trackLanguageRemove ,
2018 trackListingModeSelect ,
21- trackRssSourceAdd ,
2219 trackSearchEngineSelect ,
2320 trackSourceAdd ,
2421 trackSourceRemove ,
2522 trackTabTarget ,
2623 trackThemeSelect ,
2724} from 'src/lib/analytics'
2825import { useUserPreferences } from 'src/stores/preferences'
29- import { SearchEngineType , SelectedCard , SupportedCardType } from 'src/types'
30- import { isValidURL } from 'src/utils/UrlUtils '
26+ import { SearchEngineType , SelectedCard } from 'src/types'
27+ import { RssSetting } from './RssSetting '
3128import './settings.css'
3229
3330type SettingsModalProps = {
@@ -61,10 +58,6 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
6158 } = useUserPreferences ( )
6259 const [ selectedCards , setSelectedCards ] = useState ( cards )
6360
64- const [ rssUrl , setRssUrl ] = useState ( '' )
65- const [ rssInputError , setRssInputError ] = useState ( '' )
66- const [ isRssInputLoading , setIsRssInputLoading ] = useState ( false )
67-
6861 const AVAILABLE_CARDS = [ ...SUPPORTED_CARDS , ...userCustomCards ]
6962
7063 const handleCloseModal = ( ) => {
@@ -150,53 +143,6 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
150143 identifyUserTheme ( newTheme )
151144 }
152145
153- const onRssAddClick = async ( ) => {
154- if ( ! isValidURL ( rssUrl ) ) {
155- setRssInputError ( 'Invalid RSS Feed URL. Please check and try again.' )
156- return
157- }
158-
159- // check if card exists
160-
161- setIsRssInputLoading ( true )
162-
163- // get rssUrl Info
164- try {
165- const info = await getRssUrlFeed ( rssUrl )
166- let value = info . title . toLowerCase ( )
167- const exists = userCustomCards . find ( ( card ) => card . link === info . link )
168- if ( exists ) {
169- throw Error ( 'RSS Feed already exists' , { cause : 'EXISTS' } )
170- }
171-
172- let customCard : SupportedCardType = {
173- feedUrl : rssUrl . replace ( 'https:' , 'http:' ) ,
174- label : info . title ,
175- value,
176- analyticsTag : value ,
177- link : info . link ,
178- type : 'rss' ,
179- icon : info . icon ,
180- }
181- setUserCustomCards ( [ ...userCustomCards , customCard ] )
182- const newCards = [
183- ...cards ,
184- { id : cards . length , name : customCard . value , type : customCard . type } ,
185- ]
186- setCards ( newCards )
187- setSelectedCards ( newCards )
188- identifyUserCards ( newCards . map ( ( card ) => card . name ) )
189- trackRssSourceAdd ( customCard . value )
190- setRssUrl ( '' )
191- } catch ( err : any ) {
192- setRssInputError (
193- err ?. cause === 'EXISTS' ? err ?. message : 'Error occured. Please check and try again.'
194- )
195- } finally {
196- setIsRssInputLoading ( false )
197- }
198- }
199-
200146 return (
201147 < ReactModal
202148 isOpen = { showSettings }
@@ -266,39 +212,7 @@ export const SettingsModal = ({ showSettings, setShowSettings }: SettingsModalPr
266212 </ div >
267213 </ div >
268214
269- < div className = "settingRow" >
270- < p className = "settingTitle" > Add Custom Source</ p >
271- < div className = "settingContent" >
272- { /* <Select
273- menuIsOpen={false}
274- options={[]}
275- value={userCustomCards}
276- onChange={onRssSelectChange}
277- isMulti={true}
278- isClearable={false}
279- isSearchable={false}
280- classNamePrefix={'hackertab'}
281- className={'rss-sources'}
282- /> */ }
283- < div className = "rssUrlControl" >
284- < input
285- className = "rssUrlInput"
286- value = { rssUrl }
287- onChange = { ( e ) => setRssUrl ( e . target . value ) }
288- />
289- { isRssInputLoading ? (
290- < BeatLoader color = { '#A9B2BD' } loading = { isRssInputLoading } size = { 6 } />
291- ) : (
292- < button onClick = { onRssAddClick } > ADD</ button >
293- ) }
294- </ div >
295- { rssInputError && (
296- < div className = "settingHint" >
297- < p > { rssInputError } </ p >
298- </ div >
299- ) }
300- </ div >
301- </ div >
215+ < RssSetting setSelectedCards = { setSelectedCards } />
302216
303217 < div className = "settingRow" >
304218 < p className = "settingTitle" > Dark Mode</ p >
0 commit comments