-
Notifications
You must be signed in to change notification settings - Fork 7
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
[#103] Update logic to get twitter username #104
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,17 @@ export const SpeakersDetails = ({ session }: { session: Session }) => { | |
if (!showChild) { | ||
return null | ||
} | ||
|
||
const getTwitterUsername = (url: string) => { | ||
if (url.includes('twitter.com/')) { | ||
return url.split('twitter.com/')[1] | ||
} | ||
if (url.includes('x.com/')) { | ||
return url.split('x.com/')[1] | ||
} | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="w-full flex-wrap lg:w-4/12 flex border-r-0 pr-0 lg:pr-4 mb-6 md:mb-0"> | ||
<div className="w-full py-4"> | ||
|
@@ -63,7 +74,7 @@ export const SpeakersDetails = ({ session }: { session: Session }) => { | |
> | ||
@ | ||
{speaker.twitter | ||
? speaker.twitter.split('twitter.com/')[1] | ||
? getTwitterUsername(speaker.twitter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, why not? {getTwitterUsername(speaker.twitter) ?? speaker.name} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @danielotieno . Let me implement that. What do you think about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or if you want to use ternary {speaker.twitter
? getTwitterUsername(speaker.twitter) || speaker.name
: speaker.name} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
: speaker.name} | ||
</a> | ||
</a> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the function return? string, null or both?
const getTwitterUsername = (url: string): string | null
if it's not url, you can return null form the start
if (!url) return null;
You can use regex to match both twitter and x URLs
The complete function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic @danielotieno . I don't know how I missed that. Exiting the loop early for non URLs will remove unnecessary processing. Let me make the changes.