Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions front/src/components/Gallery/TextPlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FC, FunctionComponent, memo, ReactNode } from 'react'

const TextPlaceholder: FC<{ children?: ReactNode }> = memo(({ children }) => (
<div style={{
textAlign: 'center',
paddingTop: '30px',
width: '100%',
color: 'rgba(0, 0, 0, 0.4)',
}}>{ children }</div>
))

export default TextPlaceholder
51 changes: 37 additions & 14 deletions front/src/components/Gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Gallery, Photo } from 'api/photo'
import { CoverClickEvent, Props as PhotoBoxProps } from 'components/PhotoBox'
import Submission from 'components/Submission'
import useSafeState from 'hooks/useSafeState'
import { dateDiffInDays } from 'utils/date'
import TextPlaceholder from './TextPlaceholder'

function getViewportWidth() {
const { innerWidth } = window
Expand Down Expand Up @@ -141,25 +143,46 @@ export type Props = {
}
export default ({
cannot_select_vote = false,
show_vote_button, gallery, selected_id_list, onClickVote, onClickCover,
show_vote_button,
gallery,
selected_id_list,
onClickVote,
onClickCover,
}: Props) => {
const layout = useWaterfallLayout(gallery)

const title_node = useTitleNode(gallery)

const waterfall_layout_node = useMemo(() => (
<Waterfall
layout_configure={layout}
cannot_select_vote={cannot_select_vote}
photos={gallery.photos}
selected_id_list={selected_id_list}
show_vote_button={show_vote_button}
onClickCover={onClickCover}
onClickVote={(photoId) => {
onClickVote && onClickVote(photoId)
}}
/>
), [cannot_select_vote, gallery.photos, show_vote_button, layout, onClickCover, onClickVote, selected_id_list])
const waterfall_layout_node = useMemo(() => {
const day_diff = dateDiffInDays(new Date(gallery.event_start), new Date)
if (gallery.in_event) {
return <TextPlaceholder>提交你的投稿</TextPlaceholder>
} else if (gallery.photos.length === 0) {
if ((day_diff < 30) && day_diff > 0) {
return (
<TextPlaceholder>
活动将于 { day_diff } 天后开始<br />
</TextPlaceholder>
)
} else {
return <TextPlaceholder>暂无相片</TextPlaceholder>
}
} else {
return (
<Waterfall
layout_configure={layout}
cannot_select_vote={cannot_select_vote}
photos={gallery.photos}
selected_id_list={selected_id_list}
show_vote_button={show_vote_button}
onClickCover={onClickCover}
onClickVote={(photoId) => {
onClickVote && onClickVote(photoId)
}}
/>
)
}
}, [gallery.event_start, gallery.in_event, gallery.photos, layout, cannot_select_vote, selected_id_list, show_vote_button, onClickCover, onClickVote])

return (
<div className="gallery">
Expand Down
15 changes: 1 addition & 14 deletions front/src/components/Waterfall/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ type Pos = {
type PhotoID = number
type PosMap = Record<PhotoID, Pos>

const Empty: FunctionComponent = memo(() => (
<div style={{
textAlign: 'center',
paddingTop: '30px',
width: '100%',
color: 'rgba(0, 0, 0, 0.4)',
}}>暂无投稿作品</div>
))

export type WaterfallLayoutConfigure = {
box_type: PhotoBoxProps['type']
vertial_gutter: PhotoBoxProps['vertial_gutter']
Expand Down Expand Up @@ -95,10 +86,7 @@ export default (props: Props) => {
margin: 'auto',
minHeight: '150px',
}}>
{(photos.length === 0) ? (
<Empty />
) : (
<div
<div
className="waterfall"
style={{
width: '100%',
Expand Down Expand Up @@ -144,7 +132,6 @@ export default (props: Props) => {
))
}
</div>
)}
</div>
)
}
Expand Down
Loading