From 4b1012e87ff7f6df52cdc7c1f50ded65b500fc36 Mon Sep 17 00:00:00 2001 From: Federico Mastrini Date: Fri, 6 Dec 2024 13:01:06 +0100 Subject: [PATCH] fix: module credential end component --- src/components/modules/ModuleCredential.tsx | 88 ++++++++++++--------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/src/components/modules/ModuleCredential.tsx b/src/components/modules/ModuleCredential.tsx index d82bac4a..df534bed 100644 --- a/src/components/modules/ModuleCredential.tsx +++ b/src/components/modules/ModuleCredential.tsx @@ -3,15 +3,13 @@ import { Image, ImageSourcePropType, ImageURISource, - StyleSheet, - View + StyleSheet } from "react-native"; import Placeholder from "rn-placeholder"; import { IOListItemVisualParams, IOSelectionListItemVisualParams, IOSpacer, - IOStyles, IOVisualCostants, useIOTheme } from "../../core"; @@ -43,26 +41,28 @@ type BaseModuleProps = { }; type ModuleCredentialProps = - | LoadingModuleProps - | (BaseModuleProps & ImageProps & PressableModuleBaseProps); + | BaseModuleProps & ImageProps & PressableModuleBaseProps; -const ModuleCredential = (props: WithTestID) => { - const theme = useIOTheme(); - - if (props.isLoading) { - return ; - } +const ModuleCredential = ( + props: WithTestID +) => + props.isLoading ? ( + + ) : ( + + ); - const { - testID, - icon, - image, - label, - onPress, - badge, - isFetching, - ...pressableProps - } = props; +const ModuleCredentialContent = ({ + testID, + icon, + image, + label, + onPress, + badge, + isFetching, + ...pressableProps +}: WithTestID) => { + const theme = useIOTheme(); const iconComponent = icon && ( ) => { /> ); + const endComponent = React.useMemo(() => { + if (isFetching) { + return ( + + ); + } + if (badge) { + return ( + + ); + } + if (onPress) { + return ( + + ); + } + return null; + }, [testID, theme, isFetching, badge, onPress]); + const ModuleContent = () => ( ) => { {label} - - {badge ? ( - - ) : null} - {isFetching ? ( - - ) : onPress ? ( - - ) : null} - + {endComponent} );