({ geography, parseGeographies })
| 11 | } from "../utils" |
| 12 | |
| 13 | export default function useGeographies({ geography, parseGeographies }) { |
| 14 | const { path } = useContext(MapContext) |
| 15 | const [output, setOutput] = useState({}) |
| 16 | |
| 17 | useEffect(() => { |
| 18 | if (typeof window === `undefined`) return |
| 19 | |
| 20 | if (!geography) return |
| 21 | |
| 22 | if (isString(geography)) { |
| 23 | fetchGeographies(geography).then((geos) => { |
| 24 | if (geos) { |
| 25 | setOutput({ |
| 26 | geographies: getFeatures(geos, parseGeographies), |
| 27 | mesh: getMesh(geos), |
| 28 | }) |
| 29 | } |
| 30 | }) |
| 31 | } else { |
| 32 | setOutput({ |
| 33 | geographies: getFeatures(geography, parseGeographies), |
| 34 | mesh: getMesh(geography), |
| 35 | }) |
| 36 | } |
| 37 | }, [geography, parseGeographies]) |
| 38 | |
| 39 | const { geographies, outline, borders } = useMemo(() => { |
| 40 | const mesh = output.mesh || {} |
| 41 | const preparedMesh = prepareMesh(mesh.outline, mesh.borders, path) |
| 42 | return { |
| 43 | geographies: prepareFeatures(output.geographies, path), |
| 44 | outline: preparedMesh.outline, |
| 45 | borders: preparedMesh.borders, |
| 46 | } |
| 47 | }, [output, path]) |
| 48 | |
| 49 | return { geographies, outline, borders } |
| 50 | } |
no test coverage detected
searching dependent graphs…