Skip to content

Commit

Permalink
On adding photo, scroll into view
Browse files Browse the repository at this point in the history
Otherwise the submit button tends to get lost
  • Loading branch information
wbazant committed Nov 27, 2024
1 parent 6140f4d commit 2536074
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/photo/PhotoUploader.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { equals } from 'ramda'
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { toast } from 'react-toastify'
import styled from 'styled-components/macro'

import { addPhoto } from '../../utils/api'
import { PhotoOrganizer } from './PhotoOrganizer'

const ScrollAnchor = styled.div`
height: 100px;
margin-top: -100px;
pointer-events: none;
`

export const PhotoUploader = ({ value, onChange }) => {
const [photos, setPhotos] = useState(value)

Expand All @@ -23,8 +30,11 @@ export const PhotoUploader = ({ value, onChange }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [photos])

const scrollAnchorRef = useRef(null)

const onOrganizerChange = async (organizerPhotos) => {
setPhotos(organizerPhotos.map((photo) => ({ ...photo, file: null })))
scrollAnchorRef.current?.scrollIntoView()

await Promise.all(
organizerPhotos.map(async (photo) => {
Expand Down Expand Up @@ -66,5 +76,10 @@ export const PhotoUploader = ({ value, onChange }) => {
)
}

return <PhotoOrganizer photos={photos} onChange={onOrganizerChange} />
return (
<>
<PhotoOrganizer photos={photos} onChange={onOrganizerChange} />
<ScrollAnchor ref={scrollAnchorRef} />
</>
)
}

0 comments on commit 2536074

Please sign in to comment.