Improve responsive date handling
This commit is contained in:
parent
a48a421063
commit
cd4445d880
@ -33,6 +33,7 @@ import { PRO_MODE_ENABLED } from '@/site/config';
|
|||||||
import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
|
import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
|
||||||
import IconGrSync from '@/site/IconGrSync';
|
import IconGrSync from '@/site/IconGrSync';
|
||||||
import { getStoragePhotoUrlsNoStore } from '@/services/storage/cache';
|
import { getStoragePhotoUrlsNoStore } from '@/services/storage/cache';
|
||||||
|
import PhotoDate from '@/photo/PhotoDate';
|
||||||
|
|
||||||
const DEBUG_PHOTO_BLOBS = false;
|
const DEBUG_PHOTO_BLOBS = false;
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ export default async function AdminPhotosPage({
|
|||||||
'lg:w-[50%] uppercase',
|
'lg:w-[50%] uppercase',
|
||||||
'text-dim',
|
'text-dim',
|
||||||
)}>
|
)}>
|
||||||
{photo.takenAtNaive}
|
<PhotoDate {...{ photo }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={clsx(
|
<div className={clsx(
|
||||||
|
|||||||
20
src/components/ResponsiveDate.tsx
Normal file
20
src/components/ResponsiveDate.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { formatDate } from '@/utility/date';
|
||||||
|
|
||||||
|
export default function ResponsiveDate({
|
||||||
|
date,
|
||||||
|
}: {
|
||||||
|
date: Date
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* Mobile */}
|
||||||
|
<span className="inline-block sm:hidden">
|
||||||
|
{formatDate(date, true)}
|
||||||
|
</span>
|
||||||
|
{/* Desktop */}
|
||||||
|
<span className="hidden sm:inline-block">
|
||||||
|
{formatDate(date)}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
17
src/photo/PhotoDate.tsx
Normal file
17
src/photo/PhotoDate.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import ResponsiveDate from '@/components/ResponsiveDate';
|
||||||
|
import { Photo } from '.';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
|
export default function PhotoDate({
|
||||||
|
photo: { takenAtNaive },
|
||||||
|
}: {
|
||||||
|
photo: Photo
|
||||||
|
}) {
|
||||||
|
const date = useMemo(() => {
|
||||||
|
const date = new Date(takenAtNaive);
|
||||||
|
return isNaN(date.getTime()) ? new Date() : date;
|
||||||
|
}, [takenAtNaive]);
|
||||||
|
return (
|
||||||
|
<ResponsiveDate {...{ date }} />
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -21,7 +21,6 @@ import { authCached } from '@/auth/cache';
|
|||||||
import { getPhotos } from '@/services/vercel-postgres';
|
import { getPhotos } from '@/services/vercel-postgres';
|
||||||
import { getKeywordsForPhoto, photoQuantityText, titleForPhoto } from '@/photo';
|
import { getKeywordsForPhoto, photoQuantityText, titleForPhoto } from '@/photo';
|
||||||
import PhotoTiny from '@/photo/PhotoTiny';
|
import PhotoTiny from '@/photo/PhotoTiny';
|
||||||
import { formatDate } from '@/utility/date';
|
|
||||||
import { formatCount, formatCountDescriptive } from '@/utility/string';
|
import { formatCount, formatCountDescriptive } from '@/utility/string';
|
||||||
import { BiLockAlt, BiSolidUser } from 'react-icons/bi';
|
import { BiLockAlt, BiSolidUser } from 'react-icons/bi';
|
||||||
import { sortTagsObject } from '@/tag';
|
import { sortTagsObject } from '@/tag';
|
||||||
@ -31,6 +30,7 @@ import { TbPhoto } from 'react-icons/tb';
|
|||||||
import { IoMdCamera } from 'react-icons/io';
|
import { IoMdCamera } from 'react-icons/io';
|
||||||
import { HiDocumentText } from 'react-icons/hi';
|
import { HiDocumentText } from 'react-icons/hi';
|
||||||
import { signOutAction } from '@/auth/actions';
|
import { signOutAction } from '@/auth/actions';
|
||||||
|
import PhotoDate from '@/photo/PhotoDate';
|
||||||
|
|
||||||
export default async function CommandK() {
|
export default async function CommandK() {
|
||||||
const [
|
const [
|
||||||
@ -147,14 +147,7 @@ export default async function CommandK() {
|
|||||||
items: photos.map(photo => ({
|
items: photos.map(photo => ({
|
||||||
label: titleForPhoto(photo),
|
label: titleForPhoto(photo),
|
||||||
keywords: getKeywordsForPhoto(photo),
|
keywords: getKeywordsForPhoto(photo),
|
||||||
annotation: <>
|
annotation: <PhotoDate {...{ photo }} />,
|
||||||
<span className="hidden sm:inline-block">
|
|
||||||
{formatDate(photo.takenAt)}
|
|
||||||
</span>
|
|
||||||
<span className="inline-block sm:hidden">
|
|
||||||
{formatDate(photo.takenAt, true)}
|
|
||||||
</span>
|
|
||||||
</>,
|
|
||||||
accessory: <PhotoTiny photo={photo} />,
|
accessory: <PhotoTiny photo={photo} />,
|
||||||
path: pathForPhoto(photo),
|
path: pathForPhoto(photo),
|
||||||
})),
|
})),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user