UNPKG

@applicaster/zapp-react-native-ui-components

Version:

Applicaster Zapp React Native ui components for the Quick Brick App

41 lines (32 loc) 1.02 kB
import * as R from "ramda"; import { ZappPipesEntryContext, ZappPipesScreenContext, ZappPipesSearchContext, } from "../../../Contexts"; export function riverIsCurrentRoute(riverId, route) { const routeRiverId = R.compose(R.last, R.split("/"))(route); return typeof riverId === "undefined" || routeRiverId === riverId; } export function usePipesContexts( riverId: string, route: string ): { entryContext: ReturnType<typeof ZappPipesEntryContext.useZappPipesContext>[0]; searchContext: string; screenContext: ZappRiver; } { const isNestedScreen = !riverIsCurrentRoute(riverId, route); const routeForEntry = isNestedScreen ? `${route}/river/${riverId}` : route; const [entryContext] = ZappPipesEntryContext.useZappPipesContext( routeForEntry, isNestedScreen ); const [searchContext] = ZappPipesSearchContext.useZappPipesContext(); const [screenContext] = ZappPipesScreenContext.useZappPipesContext(); return { entryContext, searchContext, screenContext, }; }