Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'find' of undefined #6

Open
ifvictr opened this issue Aug 28, 2020 · 0 comments
Open

Uncaught TypeError: Cannot read property 'find' of undefined #6

ifvictr opened this issue Aug 28, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@ifvictr
Copy link
Owner

ifvictr commented Aug 28, 2020

This occurs very rarely, but when it does, the entire page crashes. Pretty sure the issue is somewhere in here:

export const EVENTS: Record<EventType, EventInfo> = {
media: {
emoji: '🖼️',
color: theme.colors.orange,
description: payload => {
const { type } = payload.includes.media![0]
return `posted a ${type === 'animated_gif' ? 'GIF' : type}`
},
rawDescription: payload => {
const { type } = payload.includes.media![0]
return `posted a ${type === 'animated_gif' ? 'GIF' : type}`
},
transformText: payload => payload.data.text
},
poll: {
emoji: '🗳️',
color: theme.colors.purple,
description: () => 'started a poll',
rawDescription: () => 'started a poll',
transformText: payload => payload.data.text
},
reply: {
emoji: '💬',
color: 'transparent',
description: payload => {
const recipient = payload.includes.users.find(
user => user.id === payload.data.in_reply_to_user_id
)
return (
<>
replied to{' '}
{!!recipient ? (
<>
<Link
target="_blank"
href={`https://twitter.com/${recipient.username}`}
sx={{ color: 'inherit', fontWeight: 'bold' }}
onClick={e => {
e.stopPropagation()
}}
>
{recipient.name}
</Link>
</>
) : (
'a tweet'
)}
</>
)
},
rawDescription: payload => {
const recipient = payload.includes.users.find(
user => user.id === payload.data.in_reply_to_user_id
)
return (
'replied to ' + (!!recipient ? `@${recipient.username}` : 'a tweet')
)
},
transformText: payload => payload.data.text
},
retweet: {
emoji: '🔁',
color: theme.colors.green,
description: payload => {
const retweetReference = payload.data.referenced_tweets!.find(
referencedTweet => referencedTweet.type === 'retweeted'
)
const originalTweet = payload.includes.tweets?.find(
includedTweet => includedTweet.id === retweetReference?.id
)
const author = payload.includes.users.find(
user => user.id === originalTweet?.author_id
)
return (
<>
retweeted{' '}
{!!author ? (
<>
<Link
target="_blank"
href={`https://twitter.com/${author.username}`}
sx={{ color: 'inherit', fontWeight: 'bold' }}
onClick={e => {
e.stopPropagation()
}}
>
{author.name}
</Link>
’s tweet
</>
) : (
'a tweet'
)}
</>
)
},
rawDescription: payload => {
const retweetReference = payload.data.referenced_tweets!.find(
referencedTweet => referencedTweet.type === 'retweeted'
)
const originalTweet = payload.includes.tweets?.find(
includedTweet => includedTweet.id === retweetReference?.id
)
const author = payload.includes.users.find(
user => user.id === originalTweet?.author_id
)
return `retweeted ${!!author ? `@${author.username}’s tweet` : 'a tweet'}`
},
transformText: payload => payload.data.text.replace(RETWEET_PATTERN, '') // Remove the RT @user prefix
},
tweet: {
emoji: '📢',
color: '#1da0f2',
description: () => 'tweeted',
rawDescription: () => 'tweeted',
transformText: payload => payload.data.text
}
}

@ifvictr ifvictr added the bug Something isn't working label Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant