详情侧边栏收窄至 380px;分享页加载时自动打开首张照片详情

This commit is contained in:
gallery
2026-11-15 20:42:29 +08:00
parent 34e69bac61
commit c62f24bb9d
5 changed files with 23 additions and 7 deletions
+19 -3
View File
@@ -1,6 +1,8 @@
import React from 'react'
import React, { useContext, useEffect, useRef } from 'react'
import Layout from '../../components/layout/Layout'
import AlbumGallery from '../../components/albumGallery/AlbumGallery'
import { SidebarContext } from '../../components/sidebar/Sidebar'
import MediaSidebar from '../../components/sidebar/MediaSidebar/MediaSidebar'
import styled from 'styled-components'
import { gql, useQuery } from '@apollo/client'
import { useTranslation } from 'react-i18next'
@@ -103,6 +105,9 @@ type AlbumSharePageProps = {
const AlbumSharePage = ({ albumID, token, password }: AlbumSharePageProps) => {
const { t } = useTranslation()
const { updateSidebar } = useContext(SidebarContext)
const openedAlbumID = useRef<string | null>(null)
const urlParams = useURLParameters()
const orderParams = useOrderingParams(
urlParams,
@@ -133,12 +138,23 @@ const AlbumSharePage = ({ albumID, token, password }: AlbumSharePageProps) => {
getItems: data => data.album.media,
})
const album = data?.album
// Open the detail sidebar with the first (newest) photo when the page loads.
useEffect(() => {
if (!album || openedAlbumID.current === album.id) return
const firstMedia = album.media[0]
if (!firstMedia) return
openedAlbumID.current = album.id
updateSidebar(<MediaSidebar media={firstMedia} />)
}, [album, updateSidebar])
if (error) {
return <div>{error.message}</div>
}
const album = data?.album
return (
<AlbumSharePageWrapper data-testid="AlbumSharePage">
<Layout