Skip to content

Commit 25745b8

Browse files
committed
Refactor useScreenshot to use ipns instead of siteUrl
1 parent 9010ab5 commit 25745b8

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/ProjectItem.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { makeSearch } from './useRoutes';
33
import { useScreenshot } from './useScreenshot';
44

55
export function ProjectItem({ name, ipfs, ipns, setParams, published }) {
6-
const screenshot = useScreenshot({ siteUrl: `http://127.0.0.1:8080/ipns/${ipns}/`, published });
6+
const screenshot = useScreenshot({ ipns, published });
77

88
return (
99
<section className="hero">
@@ -12,7 +12,9 @@ export function ProjectItem({ name, ipfs, ipns, setParams, published }) {
1212
<figure className="image is-16by9">
1313
<img
1414
src={
15-
screenshot.data?.image || 'https://bulma.io/assets/images/placeholders/1280x960.png'
15+
screenshot.data?.screenshotBase64
16+
? `data:image/png;base64,${screenshot.data?.screenshotBase64}`
17+
: 'https://bulma.io/assets/images/placeholders/1280x960.png'
1618
}
1719
alt={name || 'Project screenshot'}
1820
/>

src/useScreenshot.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@ import { useQuery } from '@tanstack/react-query';
22
import { useSynthetix } from './useSynthetix';
33
import { getApiUrl } from './utils';
44

5-
export function useScreenshot({ siteUrl, published }) {
5+
export function useScreenshot({ ipns, published }) {
66
const [synthetix] = useSynthetix();
77
const { chainId, token } = synthetix;
88

99
return useQuery({
10-
enabled: Boolean(chainId && siteUrl && published),
11-
queryKey: [chainId, 'useScreenshot', siteUrl, { published }],
10+
enabled: Boolean(chainId && ipns && published),
11+
queryKey: [chainId, 'useScreenshot', ipns, { published }],
1212
queryFn: async () => {
13-
const response = await fetch(
14-
`${getApiUrl()}/api/screenshot?url=${encodeURIComponent(siteUrl)}`,
15-
{
16-
method: 'GET',
17-
headers: { Authorization: `Bearer ${token}` },
18-
}
19-
);
13+
const response = await fetch(`${getApiUrl()}/api/screenshot?ipns=${ipns}`, {
14+
method: 'GET',
15+
headers: { Authorization: `Bearer ${token}` },
16+
});
2017

2118
if (!response.ok) {
2219
throw new Error('Network response was not ok');

0 commit comments

Comments
 (0)