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

[#103] Update logic to get twitter username #104

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

JNicolao
Copy link
Collaborator

@JNicolao JNicolao commented Oct 30, 2024

Make sure the checklist below is checked before PR merge, mark if not applicable

PR Checklist

  • [-] UI created matched design
  • [-] For evey color class added, dark: is defined, images have alt and _blank links have rel
  • [-] API is integrated as required
  • [-] Page is responsive

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

@JNicolao JNicolao changed the title Update logic to get twitter username in SpeakerDetail component #103 [#103] Update logic to get twitter username Oct 30, 2024
@@ -14,6 +14,17 @@ export const SpeakersDetails = ({ session }: { session: Session }) => {
if (!showChild) {
return null
}

const getTwitterUsername = (url: string) => {
Copy link
Collaborator

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;
}

Copy link
Collaborator Author

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)
Copy link
Collaborator

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}

Copy link
Collaborator Author

@JNicolao JNicolao Oct 30, 2024

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 ?

Copy link
Member

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 ??

Copy link
Collaborator

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}

Copy link
Collaborator Author

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.

@JNicolao JNicolao requested a review from danielotieno October 30, 2024 14:13
@manuelgeek manuelgeek merged commit 3625b67 into droidconKE:dev Oct 31, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants