-
Notifications
You must be signed in to change notification settings - Fork 155
Make event location links clickable #641
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
base: main
Are you sure you want to change the base?
Changes from all 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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,60 @@ import dataService from "../../services/dataService"; | |||||||||||||
| import { useAuthContext } from "../../contexts/AuthContext"; | ||||||||||||||
| import { useEventsContext } from "../../contexts/EventsContext"; | ||||||||||||||
|
|
||||||||||||||
| // URLRegex matches strings that look like URLs, including: | ||||||||||||||
| // 1. URLs starting with "http://" or "https://" (e.g., "https://example.com/path") | ||||||||||||||
| // 2. URLs starting with "www." (e.g., "www.example.com") | ||||||||||||||
| // 3. Bare domain names without protocol or www (e.g., "example.com") | ||||||||||||||
|
|
||||||||||||||
| const URLRegex = | ||||||||||||||
| /(https?:\/\/[^\s]+|www\.[^\s]+|[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(?:[^\s]*))/g; | ||||||||||||||
|
|
||||||||||||||
| const LinkText = ({ children }) => { | ||||||||||||||
| if (typeof children !== "string") | ||||||||||||||
| throw new Error("LinkText can only accept a string as children"); | ||||||||||||||
|
|
||||||||||||||
| const separated = children.split(URLRegex); | ||||||||||||||
|
|
||||||||||||||
| return separated.map((res, index) => { | ||||||||||||||
| if (URLRegex.test(res)) { | ||||||||||||||
|
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. With a named capturing group we can better use our methods to get a predictable result. (I prefer ending early over gate control.
Suggested change
|
||||||||||||||
| let href; | ||||||||||||||
|
|
||||||||||||||
| // Determine href and always enforce HTTPS | ||||||||||||||
| if (res.startsWith("https://")) { | ||||||||||||||
| href = res; | ||||||||||||||
| } else if (res.startsWith("http://")) { | ||||||||||||||
| href = res.replace(/^http:\/\//, "https://"); | ||||||||||||||
| } else if (res.startsWith("www.")) { | ||||||||||||||
| href = `https://${res}`; | ||||||||||||||
| } else { | ||||||||||||||
| href = `https://${res}`; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Convert Unicode domain to punycode for display | ||||||||||||||
| let displayURL; | ||||||||||||||
| try { | ||||||||||||||
| const urlObj = new URL(href); | ||||||||||||||
| displayURL = urlObj.toString(); // toString() converts hostname to punycode | ||||||||||||||
| } catch { | ||||||||||||||
| displayURL = href; // fallback if URL parsing fails | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <a | ||||||||||||||
| key={`${res}-${index}`} | ||||||||||||||
| href={href} | ||||||||||||||
| target="_blank" | ||||||||||||||
| rel="noreferrer" | ||||||||||||||
| className="text-blue-600 underline hover:text-blue-800" | ||||||||||||||
| > | ||||||||||||||
| {displayURL} | ||||||||||||||
| </a> | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
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. Since our check returns
Suggested change
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's the early returning check #641 (comment) |
||||||||||||||
| return res; | ||||||||||||||
| }); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| const EventModal = () => { | ||||||||||||||
| const { setEvents } = useEventsContext(); | ||||||||||||||
| const modal = useModalContext(); | ||||||||||||||
|
|
@@ -94,7 +148,9 @@ const EventModal = () => { | |||||||||||||
| </div> | ||||||||||||||
| <h3 className="mb-0">Description:</h3>{" "} | ||||||||||||||
| <div className="description break-words w-auto min-h-20 mb-2 p-2 border-solid border-black border-2 font-semibold rounded-xl bg-neutral-200/50"> | ||||||||||||||
| <p>{modal.activeEvent.description}</p> | ||||||||||||||
| <p> | ||||||||||||||
| <LinkText>{modal.activeEvent.description}</LinkText> | ||||||||||||||
|
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. If the |
||||||||||||||
| </p> | ||||||||||||||
| </div> | ||||||||||||||
| <div> | ||||||||||||||
| {/* <section className="flex m-3 gap-1 font-semibold"> | ||||||||||||||
|
|
@@ -106,7 +162,17 @@ const EventModal = () => { | |||||||||||||
| </section> */} | ||||||||||||||
| <section className="flex m-3 gap-1 font-semibold"> | ||||||||||||||
| <IoLocationOutline className="mt-1" />{" "} | ||||||||||||||
| <span>Location: {modal.activeEvent.location}</span> | ||||||||||||||
| <span> | ||||||||||||||
| Location:{" "} | ||||||||||||||
| <a | ||||||||||||||
| href={modal.activeEvent.location} | ||||||||||||||
| target="_blank" | ||||||||||||||
| rel="noopener noreferrer" | ||||||||||||||
| className="text-blue-600 underline hover:text-blue-800" | ||||||||||||||
| > | ||||||||||||||
| {modal.activeEvent.location} | ||||||||||||||
| </a> | ||||||||||||||
| </span> | ||||||||||||||
|
Comment on lines
+165
to
+175
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. Is this different from the LinkText component we built?
Contributor
Author
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, I did that part first but wasn't able to do the same thing for the event description links. Thats where you came in and recommended the LinkText component. |
||||||||||||||
| </section> | ||||||||||||||
| {user ? ( | ||||||||||||||
| <> | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.