-
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
Conversation
@@ -14,6 +14,17 @@ export const SpeakersDetails = ({ session }: { session: Session }) => { | |||
if (!showChild) { | |||
return null | |||
} | |||
|
|||
const getTwitterUsername = (url: string) => { |
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
const match = url.match(/(?:twitter\.com|x\.com)\/([^/?#]+)/i);
return match?.[1] ?? null;
The complete function
const getTwitterUsername = (url: string): string | null => {
if (!url) return null;
const match = url.match(/(?:twitter\.com|x\.com)\/([^/?#]+)/i);
return match?.[1] ?? null;
}
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.
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @danielotieno . Let me implement that. What do you think about
{getTwitterUsername(speaker.twitter ?? '') ?? speaker.name}
to ensure that speaker.twitter is a string before passing it to getTwitterUsername
?
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.
{getTwitterUsername(speaker.twitter ?? '') || speaker.name}
you can check the usage of || vs ??
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ||
would be best in this case. I've already resolved this and pushed. Please review.
Make sure the checklist below is checked before PR merge, mark if not applicable
PR Checklist
What is the Purpose?
To update logic to get twitter username from both domains
Briefly describe what the PR addresses
[#103]
What was the approach?
check if the URL contains either twitter.com or x.com. split the string to extract the username based on which domain is present.
Are there any concerns to addressed further before or after merging this PR?
No
State some additional info if any. For instance running
install
or setting some environment variable(s)Mentions?
Mention persons you'd like to review this PR
@manuelgeek
Issue(s) affected?
List of issues addressed by this PR.
#103