diff --git a/src/FeedsPanel.tsx b/src/FeedsPanel.tsx index 4c66f2f..ef0a876 100644 --- a/src/FeedsPanel.tsx +++ b/src/FeedsPanel.tsx @@ -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 diff --git a/src/hooks/useRSSFeeds.ts b/src/hooks/useRSSFeeds.ts index bda7716..ee80cda 100644 --- a/src/hooks/useRSSFeeds.ts +++ b/src/hooks/useRSSFeeds.ts @@ -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 }, []) diff --git a/src/utils/sortFeedItemsByDate.ts b/src/utils.ts similarity index 77% rename from src/utils/sortFeedItemsByDate.ts rename to src/utils.ts index 80cfd70..3d6706c 100644 --- a/src/utils/sortFeedItemsByDate.ts +++ b/src/utils.ts @@ -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' +}