Skip to content

Commit

Permalink
fix url matching
Browse files Browse the repository at this point in the history
  • Loading branch information
boredcity committed Oct 16, 2023
1 parent 868cd7e commit 159ab7b
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/components/GoalsComponents/MyGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,27 @@ const MyGoal: React.FC<MyGoalProps> = ({ goal, showActions, setShowActions }) =>
<div aria-hidden className="goal-tile" onClick={handleGoalClick}>
<div className="goal-title">
{replacedString.split(" ").map((ele, index) => {
if (ele.includes("zURL-")) {
const urlIndex = Number(ele.split("-")[1]);
const originalUrl = urlsWithIndexes[urlIndex];
const summarizedUrl = summarizeUrl(originalUrl);
console.log(originalUrl);

const replacedUrls = Array.from(ele.matchAll(/zURL-(\d+)/g));
if (replacedUrls.length) {
return (
<span
key={`${goal.id}-${ele}`}
style={{ cursor: "pointer", textDecoration: "underline" }}
onClickCapture={() => {
window.open(originalUrl, "_blank");
}}
>
{index === 0 ? summarizedUrl : ` ${summarizedUrl}`}
</span>
<React.Fragment key={`${goal.id}-${ele}-replacedUrlsFragment`}>
{replacedUrls.map(([url, digitStr]) => {
const urlIndex = Number.parseInt(digitStr, 10);
const originalUrl = urlsWithIndexes[urlIndex];
const summarizedUrl = summarizeUrl(originalUrl);
return (
<span
key={`${goal.id}-${ele}-${url}`}
style={{ cursor: "pointer", textDecoration: "underline" }}
onClickCapture={() => {
window.open(originalUrl, "_blank");
}}
>
{index === 0 ? summarizedUrl : ` ${summarizedUrl}`}
</span>
);
})}
</React.Fragment>
);
}
return <span key={`${goal.id}-${ele}`}>{index === 0 ? ele : ` ${ele}`}</span>;
Expand Down

0 comments on commit 159ab7b

Please sign in to comment.