Starting physical address lookups

This commit is contained in:
Sean Edmunds
2025-01-28 16:27:18 -06:00
parent a372a7d8e8
commit 7f1dd022a0
5 changed files with 51 additions and 5 deletions

View File

@@ -1,2 +1,2 @@
export { useQueryAPI, useWeatherAPI, useMutationAPI } from './useAPI';
export { useQueryAPI, useWeatherAPI, useMutationAPI, useCensusAPI } from './useAPI';
export { useCommonHooks } from './useCommonHooks';

View File

@@ -142,6 +142,23 @@ export function useWeatherAPI({ endpoint }: { endpoint: string }) {
});
}
export function useCensusAPI({ address }: { address: string }) {
const url = `https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address=${address?.replaceAll(' ', '+').replaceAll(',', '%2C').replaceAll('#', '%23')}&benchmark=4&format=json`;
const callEndpoint = async () => {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
return await response.json();
};
return useQuery({
queryKey: ['GET', url],
queryFn: () => callEndpoint(),
});
}
export function useFileUploadAPI() {
const callEndpoint = async (
method: string,

View File

@@ -3,7 +3,7 @@ import { appTheme } from 'contexts';
import { useAtom } from 'jotai';
import { useEffect, useState } from 'react';
import { toast } from 'react-toastify';
import { useQueryAPI, useWeatherAPI } from './useAPI';
import { useCensusAPI, useQueryAPI, useWeatherAPI } from './useAPI';
export function useCommonHooks() {
const isMobile = window.matchMedia('(max-width: 600px)').matches;
@@ -161,6 +161,18 @@ export function useCommonHooks() {
}
}, [wolClients, wolClientsIsFetched]);
const { data: locationData } = useCensusAPI({
address: personalData?.[0]?.physicalAddress,
});
const [location, setLocation] = useState<any>([]);
useEffect(() => {
if (locationData) {
setLocation(locationData);
}
}, [locationData]);
return {
isMobile,
theme,
@@ -222,6 +234,7 @@ export function useCommonHooks() {
wolClientsIsFetched,
wolClientsIsFetching,
wolClientsIsLoading,
location,
notify,
};
}