Skip to content

Commit 212c465

Browse files
committed
add rss card icon
1 parent c7c6ec5 commit 212c465

6 files changed

Lines changed: 39 additions & 29 deletions

File tree

src/features/cards/api/getRssFeed.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ import { axios } from 'src/lib/axios'
44
import { ExtractFnReturnType, QueryConfig } from 'src/lib/react-query'
55
import { Article } from 'src/types'
66

7+
type RssInfoType = {
8+
title: string
9+
link: string
10+
icon?: string
11+
}
12+
13+
export const getRssUrlFeed = async (rssUrl: string): Promise<RssInfoType> => {
14+
return axios.get('/engine/rss_info/', { params: { url: rssUrl } })
15+
}
16+
717
const getArticles = async (feedUrl: string): Promise<Article[]> => {
818
const res: string = await axios.get(`/engine/remote_feed?feedUrl=${feedUrl}`)
919
try {
1020
const feed = htmlparser2.parseFeed(res)
11-
return feed?.items.map((item) => {
21+
return feed?.items?.map((item) => {
1222
return {
1323
id: item.id,
1424
title: item.title,
@@ -17,9 +27,7 @@ const getArticles = async (feedUrl: string): Promise<Article[]> => {
1727
source: 'customFeed',
1828
}
1929
}) as Article[]
20-
} catch (err) {
21-
console.log(666, err)
22-
}
30+
} catch (err) {}
2331
return []
2432
}
2533

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { BsRssFill } from 'react-icons/bs'
2+
3+
const CardIcon = (props: { url?: string }) => {
4+
const { url } = props
5+
return url ? <img src={url} alt="" /> : <BsRssFill />
6+
}
7+
8+
export default CardIcon

src/features/cards/components/customRssCard/CustomRssCard.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { BsRssFill } from 'react-icons/bs'
21
import { Card, FloatingFilter } from 'src/components/Elements'
32
import { ListComponent } from 'src/components/List'
43
import { Article, CardPropsType } from 'src/types'
54
import { useRssFeed } from '../../api/getRssFeed'
65
import ArticleItem from './ArticleItem'
6+
import CardIcon from './CardIcon'
77

88
export function CustomRssCard({ meta, withAds }: CardPropsType) {
99
const { data = [], isLoading } = useRssFeed({ feedUrl: meta.feedUrl || '' })
@@ -21,7 +21,9 @@ export function CustomRssCard({ meta, withAds }: CardPropsType) {
2121
}
2222

2323
return (
24-
<Card card={{ ...meta, icon: <BsRssFill /> }} titleComponent={<HeaderTitle />}>
24+
<Card
25+
card={{ ...meta, icon: <CardIcon url={meta.icon as string} /> }}
26+
titleComponent={<HeaderTitle />}>
2527
<FloatingFilter card={meta} filters={['language']} />
2628
<ListComponent items={data} isLoading={isLoading} renderItem={renderItem} withAds={withAds} />
2729
</Card>

src/features/rssFeed/api/getRssFeed.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/features/settings/components/SettingsModal.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import BeatLoader from 'react-spinners/BeatLoader'
66
import Toggle from 'react-toggle'
77
import 'react-toggle/style.css'
88
import { SUPPORTED_CARDS, SUPPORTED_SEARCH_ENGINES, supportLink } from 'src/config'
9+
import { getRssUrlFeed } from 'src/features/cards/api/getRssFeed'
910
import { Tag, useRemoteConfigStore } from 'src/features/remoteConfig'
10-
import { getRssUrlFeed } from 'src/features/rssFeed/api/getRssFeed'
1111
import {
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
}

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type SupportedCardType = {
8383
type: 'rss' | 'supported'
8484
component?: React.FunctionComponent<CardPropsType>
8585
feedUrl?: string
86-
icon?: React.ReactNode
86+
icon?: React.ReactNode | string
8787
}
8888

8989
export type CardPropsType = {

0 commit comments

Comments
 (0)