Skip to content

Commit

Permalink
web: fix share link and avoid url-parse
Browse files Browse the repository at this point in the history
The parsed "protocol" field already includes the `:` so links were generated
with double colons.

While at it, replace the use of useLocation with document.location and
url-parse with URL.parse()
  • Loading branch information
ebirger committed Nov 19, 2024
1 parent d5c0b4a commit 2f20191
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
1 change: 0 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"react-scripts": "4.0.3",
"reactour": "1.18.7",
"styled-components": "^4.0.0",
"url-parse": "1.5.10",
"viz.js": "^2.1.2",
"yaml": "1.10.2"
},
Expand Down
7 changes: 3 additions & 4 deletions web/src/components/Share.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react'
import { useLocation } from 'react-router-dom';
import PropTypes from 'prop-types';
import { Button, message } from 'antd';
import { LinkOutlined } from '@ant-design/icons';
import parse from 'url-parse';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import PenLoader from './PenLoader.js';
import { CopyToPersonalPens } from './PersonalPens.js';
Expand Down Expand Up @@ -34,8 +32,9 @@ export default function Share(props) {

function shareUrl() {
const path = 'shared/' + encodeString(props.settings, props.items);
const cur = parse(useLocation);
return cur.protocol + '://' + cur.host + '/' + path;
const loc = document.location;
const cur = URL.parse(loc);
return cur.protocol + '//' + cur.host + '/' + path;
}

return (
Expand Down
8 changes: 0 additions & 8 deletions web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13313,14 +13313,6 @@ url-parse-lax@^1.0.0:
dependencies:
prepend-http "^1.0.1"

[email protected]:
version "1.5.10"
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==
dependencies:
querystringify "^2.1.1"
requires-port "^1.0.0"

url-parse@^1.4.3, url-parse@^1.4.7:
version "1.5.1"
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.1.tgz#d5fa9890af8a5e1f274a2c98376510f6425f6e3b"
Expand Down

0 comments on commit 2f20191

Please sign in to comment.