Skip to main content

State & Data Flow

State Management

Two Zustand stores in lib/store.ts:

useAuthStore

FieldTypeDescription
userUser | nullCurrent authenticated user
isAuthenticatedbooleanWhether a user is signed in
setUser(user)actionSet user and isAuthenticated
logout()actionClear user state

Written by: Login screen, logout action Read by: Profile screen, Place Detail (review gate)

useMapStore

FieldTypeDescription
region{ latitude, longitude, latitudeDelta, longitudeDelta }Current map viewport
selectedPlaceIdstring | nullCurrently selected marker
categoriesstring[]Active category filter IDs
acsAttrsstring[]Active accessibility attribute filters
setRegion(region)actionUpdate viewport
setSelectedPlaceId(id)actionSelect a marker
setCategories(ids)actionUpdate category filters
setAcsAttrs(attrs)actionUpdate ACS filters

Written by: Map screen (region changes, marker selection), Search Modal (filters, search result selection) Read by: usePlaces (region, categories, acsAttrs), Map screen (selectedPlaceId for marker highlighting)

Data Flow

How places get from the database to the screen:

tRPC Integration

The mobile client connects to the same tRPC API the web app uses via lib/api.ts.

Platform-aware base URL (getBaseUrl()):

  • Web: http://localhost:3000
  • Native (dev): Uses Constants.expoConfig.hostUri to extract the LAN IP, e.g. http://192.168.1.x:3000
  • Production: https://enaccessmaps.com

Client setup:

export const api = createTRPCReact<AppRouter>();

export function createTRPCClient() {
return api.createClient({
links: [
httpBatchLink({
url: `${BASE_URL}/api/trpc`,
async headers() {
return {};
},
}),
],
});
}

The AppRouter type is imported from @enaccess/shared, which re-exports it from the main app's tRPC router definition. This gives the mobile client full type safety on all procedure calls.

Key procedures used:

  • place.searchPlacesByBounds — spatial search by map bounds
  • place.searchGooglePlaces — text search via Google Places API
  • category.getAll — fetch all place categories

The TRPCProvider (lib/trpc-provider.tsx) wraps the app with both the tRPC provider and QueryClientProvider from TanStack Query.

Authentication Flow

Session management (lib/auth.ts):

  • Tokens stored in expo-secure-store (encrypted native storage)
  • getStoredSession() / storeSession() for session token
  • getStoredUser() / storeUser() for cached user data
  • clearSession() removes both on logout