Compare commits

..

No commits in common. "098777bb020dba30ed245eae9bb06676a2b14775" and "a0b85dfbcafacaaf25f5c5730f90c922fcd35716" have entirely different histories.

3 changed files with 16 additions and 45 deletions

View File

@ -1,6 +1,5 @@
{ {
"name": "react-photo-viewer", "name": "react-photo-viewer",
"homepage": "https://dundun.ddns.net/photos",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {

View File

@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>Photos</title> <title>React App</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>

View File

@ -60,9 +60,7 @@ function getContents(
return getDir == item.is_dir; return getDir == item.is_dir;
}) })
.map((item: galleryItemInfo, index: number) => { .map((item: galleryItemInfo, index: number) => {
const url = item.url; const url = item.thumbnail_url === null ? item.url : item.thumbnail_url;
const thumbnail_url =
item.thumbnail_url === null ? item.url : item.thumbnail_url;
let onClick = () => {}; let onClick = () => {};
if (item.is_dir) { if (item.is_dir) {
onClick = () => { onClick = () => {
@ -75,49 +73,27 @@ function getContents(
setCategory(category); setCategory(category);
}; };
return ( return <DirectoryItem key={index} url={url} onClick={onClick} />;
<DirectoryItem
key={index}
thumbnail_url={thumbnail_url}
url={url}
onClick={onClick}
/>
);
} }
if (url.endsWith('.mp4')) { if (url.endsWith('.mp4')) {
return ( return <VideoItem key={index} url={url} onClick={onClick} />;
<VideoItem
key={index}
thumbnail_url={thumbnail_url}
url={url}
onClick={onClick}
/>
);
} }
return ( return <ImageItem key={index} url={url} onClick={onClick} />;
<ImageItem
key={index}
thumbnail_url={thumbnail_url}
url={url}
onClick={onClick}
/>
);
}); });
} }
interface galleryItem { interface galleryItem {
url: string; url: string;
thumbnail_url: string;
onClick: () => void; onClick: () => void;
} }
function ImageItem({ thumbnail_url, url }: galleryItem) { function ImageItem({ url }: galleryItem) {
return ( return (
<div className="GalleryItem"> <div className="GalleryItem">
<a href={url} target="_blank"> <a href={url} target="_blank">
{getFileName(url)} {getFileName(url)}
</a> </a>
<img src={thumbnail_url} loading="lazy" /> <img src={url} loading="lazy" />
</div> </div>
); );
} }
@ -154,19 +130,15 @@ function getFileName(string: string): string {
} }
function post(category: string, callback: (text: string) => void) { function post(category: string, callback: (text: string) => void) {
fetch( fetch('http://localhost/photo-viewer-backend/php/get.php', {
//'http://localhost/photo-viewer-backend/php/get.php', method: 'POST',
'https://dundun.ddns.net/photo-viewer/photo-viewer-backend/php/get.php', headers: {
{ 'Content-Type': 'application/json',
method: 'POST', },
headers: { body: JSON.stringify({
'Content-Type': 'application/json', category: category,
}, }),
body: JSON.stringify({ })
category: category,
}),
}
)
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
throw new Error('Network response was not ok'); throw new Error('Network response was not ok');