From 13c2cd60930582cfaa3c7da2a5e2d937eed977e1 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 16 Jul 2021 23:50:11 -0400 Subject: [PATCH 1/2] refactor: consolidate itemcard into feedspanel --- src/FeedsPanel.tsx | 37 ++++++++++++++++++++++++++++++++----- src/ItemCard.tsx | 33 --------------------------------- 2 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 src/ItemCard.tsx diff --git a/src/FeedsPanel.tsx b/src/FeedsPanel.tsx index 6075e01..e840ed2 100644 --- a/src/FeedsPanel.tsx +++ b/src/FeedsPanel.tsx @@ -1,23 +1,50 @@ import React, { ReactNode } from 'react' import Box from '@material-ui/core/Box' +import Card from '@material-ui/core/Card' +import { makeStyles } from '@material-ui/core/styles' -import ItemCard from './ItemCard' import type { Item } from './types' interface Props { items: Item[] } +interface CardProps { + title: string + url: string + published: Date +} +const useStyles = makeStyles({ + root: { + margin: '5px', + padding: '10px', + display: 'flex', + flexDirection: 'column', + }, +}) + +function ItemCard(props: CardProps): ReactNode { + const { title, url, published } = props + const classes = useStyles() + + const formattedDate = published.toLocaleString('en-GB', { timeZone: 'UTC' }) + return ( + + {title} + {formattedDate} + + ) +} export default function FeedsPanel(props: Props): ReactNode { const { items } = props return ( - {items.map((item) => ( + {items.map( - ))} + key={`feed_item_${item.title.replace(' ', '_')}`} + />, + )} ) } diff --git a/src/ItemCard.tsx b/src/ItemCard.tsx deleted file mode 100644 index f169636..0000000 --- a/src/ItemCard.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React, { ReactNode } from 'react' -import Card from '@material-ui/core/Card' -import { makeStyles } from '@material-ui/core/styles' - -interface CardProps { - title: string - url: string - published: Date -} - -const useStyles = makeStyles({ - root: { - margin: '5px', - padding: '10px', - display: 'flex', - flexDirection: 'column', - }, -}) - -function formatDate(date: Date): string { - return date.toLocaleString('en-GB', { timeZone: 'UTC' }) -} - -export default function ItemCard(props: CardProps): ReactNode { - const { title, url, published } = props - const classes = useStyles() - return ( - - {title} - {formatDate(published)} - - ) -} -- 2.45.2 From 008359fa2a56993202baa59e0f5f451e6e6fe398 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 16 Jul 2021 23:57:54 -0400 Subject: [PATCH 2/2] fix: typing --- src/utils/useAppState.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/useAppState.ts b/src/utils/useAppState.ts index 3cf5e5a..338508b 100644 --- a/src/utils/useAppState.ts +++ b/src/utils/useAppState.ts @@ -1,5 +1,6 @@ import { useReducer, useRef } from 'react' +import type { State } from '../types' import { panelIdentifiers } from '../constants' export const SET_PANEL_IDENTIFIER = 'setPanelIdentifier' @@ -46,7 +47,17 @@ function setRssItems(rssItems) { payload: { rssItems }, } } -export default function useAppState() { + +type Action = + | ReturnType + | ReturnType + | ReturnType + +interface ActionSet { + [key: string]: Action +} + +export default function useAppState(): [State, ActionSet] { const [state, dispatch] = useReducer(reducer, defaultState) const actions = { -- 2.45.2