Skip to content

Commit ff28617

Browse files
committed
feat(Admin > Edit Album): View photo in new tab as original dimensions
1 parent bf6de1c commit ff28617

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

src/components/AdminAlbum/Photo.tsx

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import Button from '@mui/joy/Button'
2+
import IconButton from '@mui/joy/IconButton'
23
import Stack from '@mui/joy/Stack'
34
import useSWRMutation from 'swr/mutation'
45

56
import type { Prediction } from '../../../app/api/admin/classify/route'
6-
import { photoPath } from '../../lib/paths'
7+
import { originalPath, photoPath } from '../../lib/paths'
78
import config from '../../models/config'
89
import type { Gallery, RawXmlItem } from '../../types/common'
910
import Img from '../Img'
1011
import Link from '../Link'
1112

13+
function OpenInNewIcon() {
14+
return (
15+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden>
16+
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z" />
17+
</svg>
18+
)
19+
}
20+
1221
const fetcher = async (url: string, { arg }: { arg: string }) =>
1322
fetch(url, {
1423
method: 'POST',
@@ -25,22 +34,39 @@ export default function AdminAlbumPhoto(
2534
fetcher,
2635
)
2736

28-
const path = photoPath(item.filename, gallery)
37+
const photoSrc = photoPath(item.filename, gallery)
38+
const originalSrc = originalPath(item.filename, gallery)
2939
const dimensions = size === 'small' ? config.resizeDimensions.preview : config.resizeDimensions.photo
3040

3141
return (
3242
<>
3343
<Stack direction="column">
34-
<Img
35-
src={path}
36-
alt={item.thumb_caption || 'Photo'}
37-
width={dimensions.width - 20}
38-
height={dimensions.height - 20}
39-
/>
44+
<Stack direction="row" alignItems="flex-start" spacing={1} sx={{ position: 'relative' }}>
45+
<Img
46+
src={photoSrc}
47+
alt={item.thumb_caption || 'Photo'}
48+
width={dimensions.width - 20}
49+
height={dimensions.height - 20}
50+
/>
51+
<IconButton
52+
component={Link}
53+
href={originalSrc}
54+
target="_blank"
55+
rel="noopener noreferrer"
56+
variant="soft"
57+
color="primary"
58+
size="sm"
59+
title="Open original image in new tab"
60+
aria-label="Open original image in new tab"
61+
sx={{ flexShrink: 0, mt: 0.5 }}
62+
>
63+
<OpenInNewIcon />
64+
</IconButton>
65+
</Stack>
4066
<Button
4167
onClick={(e) => {
4268
e.preventDefault()
43-
trigger(path)
69+
trigger(photoSrc)
4470
}}
4571
>
4672
Classify Image

src/lib/paths.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const filenameAsJpg = (filename: Item['filename'][0]) => {
1616
* @param {string} rasterType photo|thumb
1717
* @returns {string} path
1818
*/
19-
export const rasterPath = (filename: XmlItem['filename'], gallery: Gallery, rasterType: 'photo' | 'thumb') => {
19+
export const rasterPath = (filename: XmlItem['filename'], gallery: Gallery, rasterType: 'original' | 'photo' | 'thumb') => {
2020
const imageFilename = filenameAsJpg(Array.isArray(filename) ? filename[0] : filename)
2121
const year = imageFilename.indexOf('-') >= 0 ? imageFilename.split('-')[0] : ''
2222

@@ -29,10 +29,15 @@ export const rasterPath = (filename: XmlItem['filename'], gallery: Gallery, rast
2929
export const thumbPath = (filename: XmlItem['filename'], gallery: Gallery) => rasterPath(filename, gallery, 'thumb')
3030

3131
/**
32-
* Photo path to public folder
32+
* Photo path to public folder (resized for display)
3333
*/
3434
export const photoPath = (filename: XmlItem['filename'], gallery: Gallery) => rasterPath(filename, gallery, 'photo')
3535

36+
/**
37+
* Original (full-size) image path to public folder
38+
*/
39+
export const originalPath = (filename: XmlItem['filename'], gallery: Gallery) => rasterPath(filename, gallery, 'original')
40+
3641
/**
3742
* Video paths to public folder on local filesystem
3843
* @param {object} filename file plus extension

0 commit comments

Comments
 (0)