-
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.
- Loading branch information
1 parent
16b75f2
commit 0fb48ce
Showing
17 changed files
with
317 additions
and
25 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,44 @@ | ||
import { Button } from "@amsterdam/design-system-react" | ||
import { HousingIcon } from "@amsterdam/design-system-react-icons" | ||
import { styled } from "styled-components" | ||
import { useNavigate, useParams } from "react-router-dom" | ||
import { PanoramaPreview, PageHeading, PageSpinner, Descriptions } from "app/components" | ||
import { useHomeownerAssociation } from "app/state/rest" | ||
|
||
|
||
const Wrapper = styled.div` | ||
margin: 24px 0; | ||
` | ||
|
||
export const AddressPage: React.FC = () => { | ||
const { bagId } = useParams<{ bagId: string }>() | ||
const [data, { isBusy }] = useHomeownerAssociation(bagId) | ||
const navigate = useNavigate() | ||
|
||
const items = [ | ||
{ label: "VVE statutaire naam", children: data?.name }, | ||
{ label: "Bouwjaar", children: data?.build_year }, | ||
{ label: "Aantal appartementen", children: data?.number_of_appartments } | ||
] | ||
|
||
return ( | ||
<> | ||
<PageHeading label="Adresoverzicht" icon={ HousingIcon } /> | ||
{ bagId && <PanoramaPreview bagId={ bagId } aspect={ 4 } fov={ 120 } />} | ||
{ isBusy && <PageSpinner /> } | ||
{ data && data.id && ( | ||
<> | ||
<Wrapper> | ||
<Descriptions items={ items } /> | ||
</Wrapper> | ||
<Button onClick={ () => navigate(`/vve/${ data.id }/zaken/nieuw`)} > | ||
Nieuwe zaak aanmaken | ||
</Button> | ||
</> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
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
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
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,36 @@ | ||
import { useBagPdok, usePanorama } from "app/state/rest" | ||
|
||
const extractLatLng = (point?: BAGPdokAddress["centroide_ll"]) => { | ||
// Ensure the string starts with "POINT(" and ends with ")" | ||
if (point && point.startsWith("POINT(") && point.endsWith(")")) { | ||
// Remove "POINT(" from the start and ")" from the end | ||
const coordinates = point.slice(6, -1) | ||
// Split the coordinates by space | ||
const [lng, lat] = coordinates.split(" ") | ||
// Parse the coordinates to floats | ||
return { | ||
lat: parseFloat(lat), | ||
lng: parseFloat(lng) | ||
} | ||
} | ||
return null | ||
} | ||
|
||
export const usePanoramaByBagId = (bagId: string, width: number | undefined, aspect: number | undefined, radius: number, fov: number | undefined) => { | ||
const [data] = useBagPdok(bagId) | ||
const docs = data?.response?.docs | ||
const foundAddress = docs && docs[0] ? docs[0] : undefined | ||
const latLng = extractLatLng(foundAddress?.centroide_ll) | ||
|
||
return usePanorama( | ||
latLng?.lat, | ||
latLng?.lng, | ||
width, | ||
aspect, | ||
radius, | ||
fov, | ||
{ lazy: foundAddress === undefined || width === undefined } | ||
) | ||
} | ||
|
||
export default usePanoramaByBagId |
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,15 @@ | ||
import qs from "qs" | ||
import type { Options } from "./" | ||
import { useSuppressErrorHandler } from "./hooks/utils" | ||
import useApiRequest from "./hooks/useApiRequest" | ||
|
||
export const usePanorama = (lat?: number, lon?: number, width?: number, aspect?: number, radius?: number, fov?: number, options?: Options) => { | ||
const handleError = useSuppressErrorHandler() | ||
const queryString = qs.stringify({ lat, lon, width, fov, aspect, radius }, { addQueryPrefix: true }) | ||
return useApiRequest<{ url: string }>({ | ||
...options, | ||
url: `https://api.data.amsterdam.nl/panorama/thumbnail/${ queryString }`, | ||
groupName: "dataPunt", | ||
handleError | ||
}) | ||
} |
Oops, something went wrong.