Skip to content

Commit 4f8fb67

Browse files
authored
Merge pull request #6 from droidconKE/feature/logic
[#4] update logic to extract twitter username
2 parents ce78b1b + 06ebe2d commit 4f8fb67

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

components/sessions/SpeakersDetails.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ import 'react-responsive-carousel/lib/styles/carousel.min.css'
77

88
export const SpeakersDetails = ({ session }: { session: Session }) => {
99
const [showChild, setShowChild] = useState(false)
10+
1011
useEffect(() => {
1112
setShowChild(true)
1213
}, [])
1314

1415
if (!showChild) {
1516
return null
1617
}
18+
19+
const getTwitterUsername = (url: string): string | null => {
20+
if (!url) return null
21+
const match = url.match(/(?:twitter\.com|x\.com)\/([^/?#]+)/i)
22+
return match?.[1] ?? null
23+
}
24+
1725
return (
1826
<div className="w-full flex-wrap lg:w-4/12 flex border-r-0 pr-0 lg:pr-4 mb-6 md:mb-0">
1927
<div className="w-full py-4">
@@ -62,9 +70,8 @@ export const SpeakersDetails = ({ session }: { session: Session }) => {
6270
className="text-primary dark:text-accent text-sm lowercase font-medium"
6371
>
6472
@
65-
{speaker.twitter
66-
? speaker.twitter.split('twitter.com/')[1]
67-
: speaker.name}
73+
{getTwitterUsername(speaker.twitter ?? '') ||
74+
speaker.name}
6875
</a>
6976
</a>
7077
</p>

0 commit comments

Comments
 (0)