Skip to content

Commit

Permalink
perf(beer): update to use new id prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrk committed Dec 2, 2020
1 parent 4e88939 commit 9b8818b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/screens/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const FeedScreen: React.FC<FeedScreenProps> = () => {
const { colors } = useTheme() as AppTheme
const { dispatch, beers } = useStoreon<State, Events>('beers')

const keyExtractor = (item: Beer) => `${item.giver.id}-${item.givenAt}-${item.receiver.id}`
const keyExtractor = (item: Beer) => `${item.id}`

const renderItem: ListRenderItem<Beer> = ({ item }) => {
const renderItem: ListRenderItem<Beer> = React.useCallback(({ item }) => {
const giverFName = item.giver.name.split(' ')[0]
const receiverFName = item.receiver.name.split(' ')[0]
const giverPic = item.giver.picture
Expand Down Expand Up @@ -54,7 +54,7 @@ export const FeedScreen: React.FC<FeedScreenProps> = () => {
</View>
</View>
)
}
}, [colors])

const renderFooter: React.FC = () => {
return (
Expand Down
1 change: 1 addition & 0 deletions src/store/auth/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function onMessage (message: FirebaseMessagingTypes.RemoteMessage) {
if (message.data?.hasOwnProperty('beers')) {
store.dispatch(BEER_EVENTS.NEW_LOG, {
beer: {
id: Number(message.data.id),
beers: Number(message.data.beers),
givenAt: message.data.givenAt,
giver: JSON.parse(message.data.giver),
Expand Down
2 changes: 1 addition & 1 deletion src/store/beers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const beers: StoreonModule<State, Events> = (store) => {
// add a single log to the state
store.on(BEER_EVENTS.NEW_LOG, ({ beers, auth }, { beer }) => {
const topLog = beers.beerLog[0]
let newLog = [beer].concat(beers.beerLog)
let newLog = [beer].concat(beers.beerLog.filter((item) => item.id !== beer.id))

// sort the log in case the beer received is older than the last log we have
if (topLog && topLog.givenAt > beer.givenAt) {
Expand Down
1 change: 1 addition & 0 deletions src/store/beers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type BeersEvents = {
}

export type Beer = {
id: number,
beers: number,
giver: {
id: string,
Expand Down

0 comments on commit 9b8818b

Please sign in to comment.