Skip to content

Commit 88f6ddc

Browse files
authored
Merge pull request #104 from ucladevx/maxwell/tinylinkhotfix
Fix invalid url by creating error handling wrapper
2 parents e97847b + 3da6b33 commit 88f6ddc

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

package-lock.json

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/TinyLinkWrapper.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import { ReactTinyLink } from "react-tiny-link"; //uses https://cors-anywhere.herokuapp.com by default.
3+
4+
const backendHost = "https://cors-anywhere-embark.herokuapp.com";
5+
6+
const TinyLinkWrapper = ({ link }) => {
7+
try {
8+
new URL(link);
9+
return (
10+
<ReactTinyLink
11+
proxyUrl={backendHost}
12+
cardSize="small"
13+
showGraphic={true}
14+
maxLine={2}
15+
minLine={1}
16+
url={link}
17+
/>
18+
);
19+
} catch (e) {
20+
return <></>;
21+
}
22+
};
23+
24+
export default TinyLinkWrapper;

src/pages/Home/Comment/CommentBox.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from "react";
2-
import { ReactTinyLink } from "react-tiny-link"; //uses https://cors-anywhere.herokuapp.com by default.
32
import Linkify from "react-linkify";
43
import linksFinder from "links-finder";
4+
import TinyLinkWrapper from "../../../components/TinyLinkWrapper";
55

66
import {
77
PreviousCommentItem,
@@ -52,13 +52,7 @@ const CommentBox = ({ comments }) => {
5252
<PreviousCommentText>{c.body}</PreviousCommentText>
5353
</Linkify>
5454
{c.body !== undefined && getURL(c.body) !== "" ? (
55-
<ReactTinyLink
56-
cardSize="small"
57-
showGraphic={true}
58-
maxLine={2}
59-
minLine={1}
60-
url={getURL(c.body)}
61-
/>
55+
<TinyLinkWrapper link={getURL(c.body)} />
6256
) : (
6357
<></>
6458
)}

src/pages/Home/Posts.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import ImageIcon from "@material-ui/icons/Image";
33
import LinkIcon from "@material-ui/icons/Link";
4-
import { ReactTinyLink } from "react-tiny-link"; //uses https://cors-anywhere.herokuapp.com by default.
4+
import TinyLinkWrapper from "../../components/TinyLinkWrapper";
55
import Linkify from "react-linkify";
66
import linksFinder from "links-finder";
77

@@ -112,7 +112,6 @@ const Posts = ({ setNewPost }) => {
112112
const getURL = (body) => {
113113
const urlSet = linksFinder.findLinks(body);
114114
if (urlSet.length <= 0) return "";
115-
console.log(urlSet);
116115
return body.substring(urlSet[0].start, urlSet[0].end + 1);
117116
};
118117

@@ -208,13 +207,8 @@ const Posts = ({ setNewPost }) => {
208207
product development process!! https://ucladevx.com/
209208
</PreviousCommentText>
210209
</Linkify>
211-
<ReactTinyLink
212-
cardSize="small"
213-
showGraphic={true}
214-
maxLine={2}
215-
minLine={1}
216-
proxyUrl={backendHost}
217-
url={getURL(
210+
<TinyLinkWrapper
211+
link={getURL(
218212
"Hey Christie! We have a slidedeck all about product thinking on our profile. You should totally apply to be on one of our teams this quarter to gain some more experience with the product development process!! https://ucladevx.com/"
219213
)}
220214
/>
@@ -279,14 +273,7 @@ const Posts = ({ setNewPost }) => {
279273
<PostContent>{p.body}</PostContent>
280274
</Linkify>
281275
{getURL(p.body) !== "" ? (
282-
<ReactTinyLink
283-
proxyUrl={backendHost}
284-
cardSize="small"
285-
showGraphic={true}
286-
maxLine={2}
287-
minLine={1}
288-
url={getURL(p.body)}
289-
/>
276+
<TinyLinkWrapper link={getURL(p.body)} />
290277
) : (
291278
<></>
292279
)}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,9 +3457,9 @@
34573457
"lodash.uniq" "^4.5.0"
34583458

34593459
"caniuse-lite@^1.0.0", "caniuse-lite@^1.0.30000981", "caniuse-lite@^1.0.30001109", "caniuse-lite@^1.0.30001125", "caniuse-lite@^1.0.30001181":
3460-
"integrity" "sha512-JUdjWpcxfJ9IPamy2f5JaRDCaqJOxDzOSKtbdx4rH9VivMd1vIzoPumsJa9LoMIi4Fx2BV2KZOxWhNkBjaYivQ=="
3461-
"resolved" "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001204.tgz"
3462-
"version" "1.0.30001204"
3460+
"integrity" "sha512-YhF/hG6nqBEllymSIjLtR2iWDDnChvhnVJqp+vloyt2tEHFG1yBR+ac2B/rOw0qOK0m0lEXU2dv4E/sMk5P9Kg=="
3461+
"resolved" "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001282.tgz"
3462+
"version" "1.0.30001282"
34633463

34643464
"capture-exit@^2.0.0":
34653465
"integrity" "sha512-PiT/hQmTonHhl/HFGN+Lx3JJUznrVYJ3+AQsnthneZbvW7x+f08Tk7yLJTLEOUvBTbduLeeBkxEaYXUOUrRq6g=="

0 commit comments

Comments
 (0)