-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from Amsterdam/feature/128109-search-vve
128109 Added VVE search by address
- Loading branch information
Showing
18 changed files
with
355 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { DescriptionList } from "@amsterdam/design-system-react" | ||
import { Fragment } from "react" | ||
|
||
type DescriptionItem = { | ||
label: string; | ||
children: React.ReactNode | ||
} | ||
|
||
type DescriptionsProps = { | ||
items: DescriptionItem[] | ||
} | ||
|
||
export const Descriptions: React.FC<DescriptionsProps> = ({ items }) => ( | ||
<DescriptionList> | ||
{items.map((item, index) => ( | ||
<Fragment key={ index }> | ||
<DescriptionList.Term> | ||
{item.label} | ||
</DescriptionList.Term> | ||
<DescriptionList.Details> | ||
{item.children} | ||
</DescriptionList.Details> | ||
</Fragment> | ||
))} | ||
</DescriptionList> | ||
) | ||
|
||
export default Descriptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useRef } from "react" | ||
import styled from "styled-components" | ||
import { usePanoramaByBagId } from "app/state/rest/custom/usePanoramaByBagId" | ||
import useRect from "./hooks/useRect" | ||
|
||
type Props = { | ||
bagId: string | ||
width?: number | ||
aspect?: number | ||
radius?: number | ||
fov?: number | ||
} | ||
|
||
const Div = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
.skeleton { | ||
width: 100%; | ||
height: 100%; | ||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); | ||
background-size: 200% 100%; | ||
animation: loading 1.5s infinite; | ||
} | ||
@keyframes loading { | ||
0% { | ||
background-position: 200% 0; | ||
} | ||
100% { | ||
background-position: -200% 0; | ||
} | ||
} | ||
` | ||
const Img = styled.img` | ||
width: 100%; | ||
` | ||
|
||
export const PanoramaPreview: React.FC<Props> = ({ bagId, width: w, aspect = 1.5, radius = 180, fov = 80 }) => { | ||
const ref = useRef<HTMLDivElement>(null) | ||
const rect = useRect(ref, 100) | ||
const width = w ?? rect.width | ||
const height = width !== undefined ? width / aspect : undefined | ||
const [data] = usePanoramaByBagId(bagId, width, aspect, radius, fov) | ||
|
||
return ( | ||
<Div ref={ ref } style={ { height } }> | ||
{ data ? ( | ||
<Img src={ data.url } alt={ `Panorama preview voor BAG: ${ bagId }` } /> | ||
) : <div className="skeleton"></div> | ||
} | ||
</Div> | ||
) | ||
} | ||
|
||
export default PanoramaPreview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useLayoutEffect, useCallback, useState } from "react" | ||
import debounce from "lodash.debounce" | ||
|
||
type RectResult = { | ||
bottom: number | ||
height: number | ||
left: number | ||
right: number | ||
top: number | ||
width: number | ||
}; | ||
|
||
const getRect = <T extends HTMLElement>(element?: T): RectResult => { | ||
let rect: RectResult = { | ||
bottom: 0, | ||
height: 0, | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
width: 0 | ||
} | ||
if (element) rect = element.getBoundingClientRect() | ||
return rect | ||
} | ||
|
||
export default <T extends HTMLElement>( | ||
ref: React.RefObject<T>, | ||
delay = 0 | ||
): RectResult => { | ||
const [rect, setRect] = useState<RectResult>( | ||
ref?.current ? getRect(ref.current) : getRect() | ||
) | ||
|
||
const handleResize = useCallback(() => { | ||
if (ref.current == null) return | ||
setRect(getRect(ref.current)) // Update client rect | ||
}, [ref]) | ||
|
||
useLayoutEffect(() => { | ||
const element = ref.current | ||
if (element == null) return | ||
|
||
handleResize() | ||
|
||
const debounced = debounce(handleResize, delay) | ||
|
||
if (typeof ResizeObserver === "function") { | ||
const resizeObserver = new ResizeObserver(debounced) | ||
resizeObserver.observe(element) | ||
return () => { | ||
resizeObserver.disconnect() | ||
} | ||
} else { | ||
window.addEventListener("resize", debounced) // Browser support, remove freely | ||
return () => window.removeEventListener("resize", debounced) | ||
} | ||
}, [ref, delay, handleResize]) | ||
|
||
return rect | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
export * from "./Descriptions/Descriptions" | ||
export * from "./DefaultLayout/DefaultLayout" | ||
export * from "./DetailsList/DetailsList" | ||
export * from "./TimelineEvents/TimelineEvents" | ||
export * from "./icons/icons" | ||
export * from "./Modal/Modal" | ||
export * from "./LinkButton/LinkButton" | ||
export * from "./Modal/hooks/useModal" | ||
export * from "./Modal/Modal" | ||
export * from "./NavMenu/NavMenu" | ||
export * from "./PageHeading/PageHeading" | ||
export * from "./LinkButton/LinkButton" | ||
export * from "./Panorama/PanoramaPreview" | ||
export * from "./SmallSkeleton/SmallSkeleton" | ||
export * from "./Spinner/Spinner" | ||
export * from "./Table/Table" | ||
export * from "./Table/types" | ||
export * from "./TimelineEvents/TimelineEvents" | ||
export * from "./User/User" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { HousingIcon } from "@amsterdam/design-system-react-icons" | ||
import { useParams } from "react-router-dom" | ||
import { PanoramaPreview, PageHeading } from "app/components" | ||
import HoaDescription from "./HoaDescription" | ||
|
||
|
||
export const AddressPage: React.FC = () => { | ||
const { bagId } = useParams<{ bagId: string }>() | ||
|
||
return ( | ||
<> | ||
<PageHeading label="Adresoverzicht" icon={ HousingIcon } /> | ||
{ bagId && <PanoramaPreview bagId={ bagId } aspect={ 4 } fov={ 120 } />} | ||
{ bagId && <HoaDescription bagId={ bagId } /> } | ||
</> | ||
) | ||
} | ||
|
||
export default AddressPage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Button } from "@amsterdam/design-system-react" | ||
import { styled } from "styled-components" | ||
import { useNavigate } from "react-router-dom" | ||
import { PageSpinner, Descriptions } from "app/components" | ||
import { useHomeownerAssociation } from "app/state/rest" | ||
|
||
|
||
type Props = { | ||
bagId: string | ||
} | ||
|
||
const Wrapper = styled.div` | ||
margin: 24px 0; | ||
` | ||
|
||
export const HoaDescription: React.FC<Props> = ({ bagId }) => { | ||
const [data, { isBusy }] = useHomeownerAssociation(bagId) | ||
const navigate = useNavigate() | ||
|
||
if (isBusy) { | ||
return <PageSpinner /> | ||
} | ||
if (data?.message) { | ||
return <p>Er zijn geen VVE-gegevens gevonden voor dit adres.</p> | ||
} | ||
if (data?.id) { | ||
const items = [ | ||
{ label: "VVE statutaire naam", children: data?.name }, | ||
{ label: "Bouwjaar", children: data?.build_year }, | ||
{ label: "Aantal appartementen", children: data?.number_of_appartments } | ||
] | ||
return ( | ||
<> | ||
<Wrapper> | ||
<Descriptions items={ items } /> | ||
</Wrapper> | ||
<Button onClick={ () => navigate(`/vve/${ data.id }/zaken/nieuw`)} > | ||
Nieuwe zaak aanmaken | ||
</Button> | ||
</> | ||
) | ||
} | ||
return null | ||
} | ||
|
||
export default HoaDescription | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Options } from "." | ||
import { makeApiUrl, useErrorHandler } from "./hooks/utils" | ||
import useApiRequest from "./hooks/useApiRequest" | ||
|
||
|
||
export const useHomeownerAssociation = (bagId?: string ,options?: Options) => { | ||
const handleError = useErrorHandler() | ||
return useApiRequest<Components.Schemas.HomeownerAssociation>({ | ||
...options, | ||
url: `${ makeApiUrl("address", bagId, "homeowner-association") }`, | ||
lazy: bagId === undefined, | ||
groupName: "address", | ||
handleError, | ||
isProtected: true | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.