Skip to content

Commit 568127b

Browse files
Update endpoint view to allow directly opening the endpoint and copying the URL with one click
1 parent 1e34417 commit 568127b

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"build-cf-types": "wrangler types --env-interface CloudflareEnv env.d.ts"
1414
},
1515
"dependencies": {
16+
"@fortawesome/free-solid-svg-icons": "^6.5.2",
17+
"@fortawesome/react-fontawesome": "^0.2.0",
1618
"bright": "^0.8.5",
1719
"next": "14.1.0",
1820
"react": "^18",

src/app/pokedex/components/endpointView.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1+
"use client";
12
import React from "react";
3+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4+
import { faExternalLinkAlt, faCopy } from "@fortawesome/free-solid-svg-icons";
25

36
interface EndpointViewProps {
47
endpoint: string;
58
method: string;
69
}
710

811
const EndpointView: React.FC<EndpointViewProps> = ({ endpoint, method }) => {
12+
const fullUrl = `https://pokedex.mimo.dev/api/${endpoint}`;
13+
914
const handleOpenEndpoint = () => {
10-
window.open(endpoint, "_blank");
15+
window.open(fullUrl, "_blank");
1116
};
1217

1318
const handleCopyEndpoint = () => {
14-
navigator.clipboard.writeText(endpoint);
19+
navigator.clipboard.writeText(fullUrl);
1520
};
1621

1722
return (
1823
<div className="bg-pokemon-gray text-white p-2 h-12 w-fit rounded flex items-center">
1924
<span>{method}</span>
2025
<span className="w-2"></span>
21-
<span className="underline decoration-pokemon-yellow">{endpoint}</span>
26+
<span className="underline decoration-pokemon-yellow">{fullUrl}</span>
27+
<button onClick={handleOpenEndpoint} className="ml-2">
28+
<FontAwesomeIcon icon={faExternalLinkAlt} />
29+
</button>
30+
<button onClick={handleCopyEndpoint} className="ml-2">
31+
<FontAwesomeIcon icon={faCopy} />
32+
</button>
2233
</div>
2334
);
2435
};

0 commit comments

Comments
 (0)