Skip to content

Commit

Permalink
add small loading indicator to nearby view
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-heppner-ibigroup committed Oct 20, 2023
1 parent 78bd791 commit c263329
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/components/narrative/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import React from 'react'
import { StyledIconWrapper } from '../util/styledIcon'

type Props = {
extraSmall?: boolean
small?: boolean
}

const Loading = ({ small }: Props): JSX.Element => {
const Loading = ({ extraSmall, small }: Props): JSX.Element => {
return (
<p className="text-center percy-hide" style={{ marginTop: '15px' }}>
<StyledIconWrapper size={small ? '3x' : '5x'} spin>
<p className="text-center percy-hide" style={{ margin: '0', padding: '0' }}>
<StyledIconWrapper size={small ? '3x' : extraSmall ? '1x' : '5x'} spin>
<Redo />
</StyledIconWrapper>
</p>
Expand Down
27 changes: 22 additions & 5 deletions lib/components/viewers/nearby/nearby-view.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { connect } from 'react-redux'
import { MapRef, useMap } from 'react-map-gl'
import { useIntl } from 'react-intl'
import React, { useEffect, useRef } from 'react'
import React, { useEffect, useRef, useState } from 'react'

import * as apiActions from '../../../actions/api'

import { NearbySidebarContainer, Scrollable } from './styled'
import {
FloatingLoadingIndicator,
NearbySidebarContainer,
Scrollable
} from './styled'
import Loading from '../../narrative/loading'
import RentalStation from './rental-station'
import Stop from './stop'
import Vehicle from './vehicle-rent'
Expand Down Expand Up @@ -45,26 +50,38 @@ function NearbyView(props: Props): JSX.Element {
const { fetchNearby, nearby, nearbyViewCoords } = props
const map = useMap().current
const intl = useIntl()
const [loading, setLoading] = useState(true)
const firstItemRef = useRef<HTMLDivElement>(null)
useEffect(() => {
firstItemRef.current?.scrollIntoView({ behavior: 'smooth' })
if (nearbyViewCoords) {
fetchNearby(nearbyViewCoords, map)
setLoading(true)
const interval = setInterval(() => {
fetchNearby(nearbyViewCoords, map)
}, 2000)
setLoading(true)
}, 15000)
return function cleanup() {
clearInterval(interval)
}
}
}, [nearbyViewCoords])

useEffect(() => {
setLoading(false)
}, [nearby])

// TODO: when coordinates are set, put a marker on the map and zoom there

return (
<Scrollable>
<div className="nearby-view" ref={firstItemRef} />
<Scrollable className="nearby-view base-color-bg">
<NearbySidebarContainer className="base-color-bg">
<div ref={firstItemRef} />
{loading && (
<FloatingLoadingIndicator>
<Loading extraSmall />
</FloatingLoadingIndicator>
)}
{nearby &&
(nearby.error
? intl.formatMessage({ id: 'components.NearbyView.error' })
Expand Down
14 changes: 13 additions & 1 deletion lib/components/viewers/nearby/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import styled from 'styled-components'

export const FloatingLoadingIndicator = styled.div`
position: fixed;
left: 0px;
margin: 5px;
aspect-ratio: 1;
padding: 3px;
background: white;
color: black;
border-radius: 1rem;
`

export const NearbySidebarContainer = styled.div`
display: flex;
position: relative;
flex-direction: column;
gap: 3rem;
padding: 3rem;
padding: 0 3rem;
overflow-y: scroll;
`

Expand Down

0 comments on commit c263329

Please sign in to comment.