Skip to content

Commit

Permalink
FE Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
wtcarter committed Nov 21, 2024
1 parent 34ea5a1 commit e54962e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/cccv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@babel/core": "^7.24.7",
"@chromatic-com/storybook": "^1.5.0",
"@chromatic-com/storybook": "^3.2.2",
"@lingui/cli": "^4.11.1",
"@lingui/macro": "^4.11.1",
"@playwright/test": "^1.42.1",
Expand All @@ -64,7 +64,7 @@
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/dompurify": "^3.0.5",
"@types/node": "^20.11.24",
"@types/node": "^22.9.1",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@types/testing-library__user-event": "^4.2.0",
Expand All @@ -74,9 +74,9 @@
"autoprefixer": "^10.4.18",
"babel-plugin-macros": "^3.1.0",
"check-dependencies": "^2.0.0",
"eslint": "^8.57.1",
"eslint": "^9.15.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.5",
"eslint-plugin-storybook": "^0.8.0",
"file-loader": "^6.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function Spinner(props: { width: number, height: number }) {
<svg className={`animate-spin -ml-1 mr-3 w-${props.width} h-${props.height} text-white" xmlns="http://www.w3.org/2000/svg`}
fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="navy"
stroke-width="4"></circle>
strokeWidth="4"></circle>
<path className="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const StringCarousel: React.FC<CarouselProps> = ({ displayValues, index, setInde

return (
<div className={["flex items-center justify-center space-x-2", className].join(' ')}>
<button onClick={handlePrev} className="border-none text-xl">&lt;</button>
<button onClick={handlePrev} className="hover:bg-transparent hover:text-nui border-none text-xl">&lt;</button>
<h2 className="text-2lg h-full text-center">{displayValues[currentIndex]}</h2>
<button onClick={handleNext} className="border-none text-xl">&gt;</button>
<button onClick={handleNext} className="hover:bg-transparent hover:text-nui border-none text-xl">&gt;</button>
</div>
)
}
Expand Down
33 changes: 24 additions & 9 deletions packages/cccv/src/pages/MapPage/MapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import getFeaturesUnderMouse from "@lib/getFeaturesUnderMouse.ts"
import {urlDefaultMapStyle} from "@lib/urlsAndPaths.ts"
import env from "@src/env.ts"
import useMapFocus from "@lib/useMapFocus.tsx"
// import formatFilename from "@lib/formatAsFilename.ts"
// import dateTimeString from "@lib/dateTimeString.ts"

const ADDRESS_ZOOM = 12

Expand Down Expand Up @@ -83,6 +85,10 @@ const useFMUSelection = () => {
return {fmuSelected, currentFmu, fmuIndex, currentFmus, setCurrentFmus, setFmuIndex, clearFmus, loadFmus}
}

// function getFileName(currentFmu: FmuFullDetails) {
// return formatFilename(currentFmu.freshwaterManagementUnit.fmuName1 || "", `fmu_${currentFmu.freshwaterManagementUnit.id}`) + `_${dateTimeString()}` + ".pdf"
// }

export default function MapPage() {
const {setError} = useContext(ErrorContext)
const locationDetails = useLoaderData()
Expand All @@ -94,14 +100,17 @@ export default function MapPage() {
const sliderRef = useRef<HTMLDivElement>(null)
const [sliderWidth, setSliderWidth] = useState<number>(0)

const {mapSnapshot} = useMapSnapshot()
const {setLoading} = useLoadingIndicator()
const mapRef = useRef<CombinedMapRef | null>(null)

const [mapStyle, setMapStyle] = useState(urlDefaultMapStyle(env.LINZ_API_KEY))

const [featureBeingRolledOver, setFeatureBeingRolledOver] = useState<Feature | FeatureCollection | null>(null)

const [showInfoPanel] = useState<boolean | null>(false)

const {mapSnapshot, takeMapSnapshot} = useMapSnapshot()

useMapFocus(mapRef, selectedLocation)

const fetchFmu = async () => {
Expand All @@ -123,10 +132,18 @@ export default function MapPage() {
setError(null)
}

useEffect(() => {
if (currentFmu) {
takeMapSnapshot(mapRef, selectedLocation)
// setPdfDocument(pdf({ document: <FreshwaterManagementUnitPDF {...currentFmu} />}))
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentFmu])

useEffect(() => {
fetchFmu().catch((e) => console.error(e))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedLocation, setError, mapSnapshot])
}, [selectedLocation, setError])

useEscapeKey(() => {
selectLocation(null)
Expand Down Expand Up @@ -217,11 +234,7 @@ export default function MapPage() {
}
}

const afterMapLoaded = () => {
if (locationDetails) {
selectLocation(locationDetails as IMViewLocation)
}
}
const afterMapLoaded = () => {}

return (
<div className="map-page bg-white">
Expand Down Expand Up @@ -291,7 +304,7 @@ export default function MapPage() {
id={CURRENT_FMU_LAYER}
type="fill"
paint={mapProperties.currentFMU.fill}
filter={['==', ['id'], currentFmu?.freshwaterManagementUnit?.id]}
filter={['==', ['id'], currentFmu?.freshwaterManagementUnit?.id ?? null]}
source={FMU_BOUNDARIES_SOURCE}
maxzoom={DEFAULT_ZOOM+5}
/>)}
Expand All @@ -311,7 +324,8 @@ export default function MapPage() {
</div>

{currentFmu && (
<SlidingPanel showPanel={!!currentFmus.length} contentChanged={false}
<SlidingPanel contentChanged={false} showPanel={showInfoPanel || true}
onResize={(width) => setSliderWidth(width)}
onClose={() => clearFmus()}>
{/*{currentFmus.length > 1 && (<FmuPanelHeader className={"ml-6 mb-8"} fmuName1={currentFmu.freshwaterManagementUnit.fmuName1!}/>)}*/}
{selectedLocation?.address && <PhysicalAddress address={selectedLocation.address}/>}
Expand All @@ -324,6 +338,7 @@ export default function MapPage() {
<div
className="text-sm text-center font-extralight mb-2">{`Catchment ${fmuIndex! + 1} of ${currentFmus.length}`}</div>
</div>)}

<FreshwaterManagementUnit
key={0}
{...currentFmu}
Expand Down

0 comments on commit e54962e

Please sign in to comment.