分享页: 照片按时间倒序、统一间距、卡片右下角显示日期与城市

This commit is contained in:
gallery
2026-11-15 20:33:21 +08:00
parent 8c376575f5
commit 6bec039595
12 changed files with 213 additions and 8 deletions
@@ -71,6 +71,7 @@ export interface AlbumGalleryFields_media_videoWeb {
export interface AlbumGalleryFields_media {
__typename: "Media";
id: string;
title: string;
type: MediaType;
/**
* A short string that can be used to generate a blured version of the media, to show while the original is loading
@@ -17,6 +17,7 @@ test('photo gallery with media', () => {
media: [
{
id: '165',
title: 'photo_165.jpg',
type: MediaType.Photo,
thumbnail: {
url: '/photo/thumbnail_3666760020_jpg_x76GG5pS.jpg',
@@ -32,6 +33,7 @@ test('photo gallery with media', () => {
},
{
id: '122',
title: 'photo_122.jpg',
type: MediaType.Photo,
thumbnail: null,
highRes: null,
@@ -42,6 +44,7 @@ test('photo gallery with media', () => {
},
{
id: '98',
title: 'photo_98.jpg',
type: MediaType.Video,
thumbnail: null,
highRes: null,
@@ -94,6 +97,7 @@ describe('photo gallery presenting', () => {
media: [
{
id: '165',
title: 'photo_165.jpg',
type: MediaType.Photo,
thumbnail: {
url: '/photo/thumbnail_3666760020_jpg_x76GG5pS.jpg',
@@ -14,6 +14,7 @@ import {
import MediaSidebar from '../sidebar/MediaSidebar/MediaSidebar'
import { SidebarContext } from '../sidebar/Sidebar'
import { gql } from '@apollo/client'
import { mediaCaption } from '../../helpers/mediaCaption'
const Gallery = styled.div`
display: flex;
@@ -21,7 +22,7 @@ const Gallery = styled.div`
align-items: center;
min-height: 200px;
position: relative;
margin: -4px;
margin: -2px;
@media (max-width: 1000px) {
/* Compensate for tab bar on mobile */
@@ -37,6 +38,7 @@ export const PhotoFiller = styled.div`
export const MEDIA_GALLERY_FRAGMENT = gql`
fragment MediaGalleryFields on Media {
id
title
type
blurhash
thumbnail {
@@ -72,11 +74,17 @@ const MediaGallery = ({ mediaState, dispatchMedia }: MediaGalleryProps) => {
mediaElements = media.map((media, index) => {
const active = activeIndex == index
const caption = mediaCaption(media.title)
const captionText = caption
? `${caption.date}${caption.city ? ` ${caption.city}` : ''}`
: null
return (
<MediaThumbnail
key={media.id}
media={media}
active={active}
caption={captionText}
selectImage={() => {
dispatchMedia({
type: 'selectImage',
@@ -9,7 +9,7 @@ const MediaContainer = styled.div`
flex-grow: 1;
flex-basis: 0;
height: 200px;
margin: 4px 2px;
margin: 2px;
background-color: #eee;
position: relative;
overflow: hidden;
@@ -136,9 +136,24 @@ const VideoThumbnailIcon = styled(VideoThumbnailIconSVG)`
top: calc(50% - 22px);
`
const Caption = styled.div`
position: absolute;
right: 6px;
bottom: 4px;
color: #ffd400;
font-size: 12px;
font-weight: 600;
line-height: 1.2;
white-space: nowrap;
pointer-events: none;
text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff,
1px 1px 0 #fff, 0 0 2px rgba(0, 0, 0, 0.35);
`
type MediaThumbnailProps = {
media: MediaGalleryFields
active: boolean
caption?: string | null
selectImage(): void
clickPresent(): void
clickFavorite(): void
@@ -147,6 +162,7 @@ type MediaThumbnailProps = {
export const MediaThumbnail = ({
media,
active,
caption,
selectImage,
clickPresent,
clickFavorite,
@@ -181,7 +197,7 @@ export const MediaThumbnail = ({
key={media.id}
style={{
cursor: 'pointer',
minWidth: `clamp(124px, ${minWidth}px, 100% - 8px)`,
minWidth: `clamp(124px, ${minWidth}px, 100% - 4px)`,
}}
onClick={() => {
clickPresent()
@@ -206,6 +222,7 @@ export const MediaThumbnail = ({
/>
{heartIcon}
</PhotoOverlay>
{caption && <Caption>{caption}</Caption>}
</MediaContainer>
)
}
@@ -214,7 +231,7 @@ export const MediaPlaceholder = styled.div`
flex-grow: 1;
height: 200px;
width: 300px;
margin: 4px 2px;
margin: 2px;
background-color: #eee;
position: relative;
`
@@ -44,6 +44,7 @@ export interface MediaGalleryFields_videoWeb {
export interface MediaGalleryFields {
__typename: "Media";
id: string;
title: string;
type: MediaType;
/**
* A short string that can be used to generate a blured version of the media, to show while the original is loading
@@ -9,6 +9,7 @@ describe('photo gallery reducer', () => {
{
__typename: 'Media',
id: '1',
title: 'photo_1.jpg',
highRes: null,
thumbnail: null,
blurhash: null,
@@ -17,6 +18,7 @@ describe('photo gallery reducer', () => {
{
__typename: 'Media',
id: '2',
title: 'photo_2.jpg',
highRes: null,
thumbnail: null,
blurhash: null,
@@ -25,6 +27,7 @@ describe('photo gallery reducer', () => {
{
__typename: 'Media',
id: '3',
title: 'photo_3.jpg',
highRes: null,
thumbnail: null,
blurhash: null,
@@ -9,6 +9,7 @@ test('render present image', () => {
const media: MediaGalleryFields = {
__typename: 'Media',
id: '123',
title: 'sample_image.jpg',
type: MediaType.Photo,
highRes: null,
blurhash: null,
@@ -37,6 +38,7 @@ test('render present video', () => {
const media: MediaGalleryFields = {
__typename: 'Media',
id: '123',
title: 'sample_video.mp4',
type: MediaType.Video,
highRes: null,
blurhash: null,