fix: handle invalid feeds (#28)

chore: lint
This commit is contained in:
Marc 2022-08-01 11:25:50 -04:00 committed by GitHub
parent 8620a35d33
commit e7fb9e4749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View file

@ -6,7 +6,7 @@ import { makeStyles } from '@material-ui/core/styles'
import useSettings from './hooks/useSettings'
import useRSSFeeds from './hooks/useRSSFeeds'
import sortFeedItemsByDate from './utils/sortFeedItemsByDate'
import sortFeedItemsByDate from './utils'
interface CardProps {
title: string

View file

@ -2,6 +2,7 @@ import { parseFeed } from 'htmlparser2'
import { useQueries } from 'react-query'
import { Feed } from '../types'
import { isDev } from '../utils'
import useLocalStorage from './useLocalStorage'
@ -58,8 +59,10 @@ async function fetchFeed(
return mergedFeeds
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
if (isDev()) {
// eslint-disable-next-line no-console
console.error(e)
}
}
return persistedData
@ -88,7 +91,7 @@ export default function useRSSFeeds(urls: string[]): { feeds: Feed[] } {
)
const fetchedFeeds = queries.reduce((fetchedFeeds: Feed[], current) => {
if (current.isSuccess) fetchedFeeds.push(current.data)
if (current.isSuccess && current.data) fetchedFeeds.push(current.data)
return fetchedFeeds
}, [])

View file

@ -1,4 +1,4 @@
import type { Feed, Item } from '../types'
import type { Feed, Item } from './types'
export default function sortFeedItemsByDate(feeds: Feed[]): Item[] {
const flattened = feeds.reduce((flattenedFeeds, feed) => {
@ -14,3 +14,7 @@ export default function sortFeedItemsByDate(feeds: Feed[]): Item[] {
first.published > second.published ? -1 : 1,
)
}
export function isDev(): boolean {
return process.env.NODE_ENV === 'development'
}