@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
46 lines (37 loc) • 1.27 kB
text/typescript
import * as R from "ramda";
import { SCREEN_TYPES } from "./itemTypes";
import { isPlayable, isLink } from "./itemTypeMatchers";
const screenTypeMapper = {
player: "playable",
general_content: "river",
general: "river",
login: "river",
payments: "river",
};
type Predicate =
| ((...args: any[]) => boolean)
| ((arg: any) => (arg: any) => boolean);
const hasPluginTypeInContentType: Predicate = R.curry((contentTypes, item) => {
return typeof contentTypes?.[item?.type?.value]?.screenType !== "undefined";
});
const getScreenTypeForItem = R.curry((contentTypes, item) => {
const { screenType } = contentTypes?.[item?.type?.value] || {};
return screenTypeMapper[screenType] || screenType;
});
export const layoutV2TypeMatcher = (item, contentTypes = {}) => {
const mappedTypes = R.keys(contentTypes);
const isNotMapped = R.compose(
R.not,
R.flip(R.includes)(mappedTypes),
R.path(["type", "value"])
);
return R.cond([
[R.allPass([isPlayable, isNotMapped]), R.always(SCREEN_TYPES.PLAYABLE)],
[R.allPass([isLink, isNotMapped]), R.always(SCREEN_TYPES.LINK)],
[
hasPluginTypeInContentType(contentTypes),
getScreenTypeForItem(contentTypes),
],
[R.T, R.always(SCREEN_TYPES.RIVER)],
])(item);
};