From 66bb46912a3f4bae3862582ba291c8b8e1d013b0 Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Fri, 5 Feb 2021 16:01:08 +0100 Subject: [PATCH] Work on media interaction --- .../components/photoGallery/MediaThumbnail.js | 1 - .../timelineGallery/TimelineGallery.js | 108 +++++++++++++++++- .../timelineGallery/TimelineGroupAlbum.js | 26 +++-- .../timelineGallery/TimelineGroupDate.js | 28 ++++- 4 files changed, 142 insertions(+), 21 deletions(-) diff --git a/ui/src/components/photoGallery/MediaThumbnail.js b/ui/src/components/photoGallery/MediaThumbnail.js index 7a414152..f2cb0cb7 100644 --- a/ui/src/components/photoGallery/MediaThumbnail.js +++ b/ui/src/components/photoGallery/MediaThumbnail.js @@ -205,7 +205,6 @@ export const MediaThumbnail = ({ MediaThumbnail.propTypes = { media: PropTypes.object.isRequired, onSelectImage: PropTypes.func, - minWidth: PropTypes.number.isRequired, index: PropTypes.number.isRequired, active: PropTypes.bool.isRequired, setPresenting: PropTypes.func.isRequired, diff --git a/ui/src/components/timelineGallery/TimelineGallery.js b/ui/src/components/timelineGallery/TimelineGallery.js index 6bc5111b..e9cb5f00 100644 --- a/ui/src/components/timelineGallery/TimelineGallery.js +++ b/ui/src/components/timelineGallery/TimelineGallery.js @@ -1,7 +1,9 @@ -import React from 'react' +import React, { useState } from 'react' +import PropTypes from 'prop-types' import { useQuery, gql } from '@apollo/client' import TimelineGroupDate from './TimelineGroupDate' import styled from 'styled-components' +import PresentView from '../photoGallery/presentView/PresentView' const MY_TIMELINE_QUERY = gql` query myTimeline { @@ -12,11 +14,22 @@ const MY_TIMELINE_QUERY = gql` } media { id + title + type thumbnail { url width height } + highRes { + url + width + height + } + videoWeb { + url + } + favorite } mediaTotal date @@ -30,6 +43,51 @@ const GalleryWrapper = styled.div` ` const TimelineGallery = () => { + const [activeIndex, setActiveIndex] = useState({ + dateGroup: -1, + albumGroup: -1, + media: -1, + }) + const [presenting, setPresenting] = useState(false) + + const nextMedia = () => { + setActiveIndex(activeIndex => { + const albumGroups = dateGroupedAlbums[activeIndex.dateGroup].groups + const albumMedia = albumGroups[activeIndex.albumGroup].media + + if (activeIndex.media < albumMedia.length - 1) { + return { + ...activeIndex, + media: activeIndex.media + 1, + } + } + + if (activeIndex.albumGroup < albumGroups.length - 1) { + return { + ...activeIndex, + albumGroup: activeIndex.albumGroup + 1, + media: 0, + } + } + + if (activeIndex.dateGroup < dateGroupedAlbums.length - 1) { + return { + dateGroup: activeIndex.dateGroup + 1, + albumGroup: 0, + media: 0, + } + } + + return { + dateGroup: 0, + albumGroup: 0, + media: 0, + } + }) + } + + const previousMedia = () => {} + const { data, error } = useQuery(MY_TIMELINE_QUERY) if (error) { @@ -37,8 +95,9 @@ const TimelineGallery = () => { } let timelineGroups = null + let dateGroupedAlbums = [] if (data?.myTimeline) { - const dateGroupedAlbums = data.myTimeline.reduce((acc, val) => { + dateGroupedAlbums = data.myTimeline.reduce((acc, val) => { if (acc.length == 0 || acc[acc.length - 1].date != val.date) { acc.push({ date: val.date, @@ -51,12 +110,51 @@ const TimelineGallery = () => { return acc }, []) - timelineGroups = dateGroupedAlbums.map(({ date, groups }) => ( - + timelineGroups = dateGroupedAlbums.map(({ date, groups }, i) => ( + { + setActiveIndex({ + media, + albumGroup, + dateGroup: i, + }) + }} + /> )) } - return {timelineGroups} + return ( + + {timelineGroups} + {presenting && ( + + )} + + ) +} + +TimelineGallery.propTypes = { + favorites: PropTypes.bool, + setFavorites: PropTypes.func, } export default TimelineGallery diff --git a/ui/src/components/timelineGallery/TimelineGroupAlbum.js b/ui/src/components/timelineGallery/TimelineGroupAlbum.js index 3705cfc8..15ee7c13 100644 --- a/ui/src/components/timelineGallery/TimelineGroupAlbum.js +++ b/ui/src/components/timelineGallery/TimelineGroupAlbum.js @@ -7,7 +7,7 @@ const MediaWrapper = styled.div` display: flex; flex-wrap: wrap; align-items: center; - height: 200px; + height: 210px; position: relative; margin: -4px; @@ -30,19 +30,20 @@ const GroupAlbumWrapper = styled.div` margin-top: 12px; ` -const TimelineGroupAlbum = ({ group: { album, media /* mediaTotal */ } }) => { - const mediaElms = media.map(media => ( +const TimelineGroupAlbum = ({ + group: { album, media /* mediaTotal */ }, + onSelectMedia, + setPresenting, + activeIndex, +}) => { + const mediaElms = media.map((media, i) => ( { - // todo - }} - setPresenting={() => { - // todo - }} - index={0} - active={false} + onSelectImage={onSelectMedia} + setPresenting={setPresenting} + index={i} + active={activeIndex == i} /> )) @@ -56,6 +57,9 @@ const TimelineGroupAlbum = ({ group: { album, media /* mediaTotal */ } }) => { TimelineGroupAlbum.propTypes = { group: PropTypes.object.isRequired, + onSelectMedia: PropTypes.func.isRequired, + setPresenting: PropTypes.func.isRequired, + activeIndex: PropTypes.number.isRequired, } export default TimelineGroupAlbum diff --git a/ui/src/components/timelineGallery/TimelineGroupDate.js b/ui/src/components/timelineGallery/TimelineGroupDate.js index ae1f88a1..7a2de68d 100644 --- a/ui/src/components/timelineGallery/TimelineGroupDate.js +++ b/ui/src/components/timelineGallery/TimelineGroupDate.js @@ -18,9 +18,26 @@ const DateTitle = styled.h1` margin: 0 0 -12px; ` -const TimelineGroupDate = ({ date, groups }) => { - const groupElms = groups.map(group => ( - +const TimelineGroupDate = ({ + date, + groups, + onSelectDateGroup, + activeIndex, + setPresenting, +}) => { + const albumGroupElms = groups.map((group, i) => ( + { + onSelectDateGroup({ + media: mediaIndex, + albumGroup: i, + }) + }} + activeIndex={activeIndex.albumGroup == i ? activeIndex.media : -1} + setPresenting={setPresenting} + /> )) const formattedDate = dateFormatter.format(new Date(date)) @@ -28,7 +45,7 @@ const TimelineGroupDate = ({ date, groups }) => { return ( {formattedDate} -
{groupElms}
+
{albumGroupElms}
) } @@ -36,6 +53,9 @@ const TimelineGroupDate = ({ date, groups }) => { TimelineGroupDate.propTypes = { date: PropTypes.string.isRequired, groups: PropTypes.array.isRequired, + onSelectDateGroup: PropTypes.func.isRequired, + activeIndex: PropTypes.object.isRequired, + setPresenting: PropTypes.func.isRequired, } export default TimelineGroupDate