Skip to content

Commit

Permalink
fix: module credential end component
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 committed Dec 6, 2024
1 parent adf19d3 commit 4b1012e
Showing 1 changed file with 49 additions and 39 deletions.
88 changes: 49 additions & 39 deletions src/components/modules/ModuleCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -43,26 +41,28 @@ type BaseModuleProps = {
};

type ModuleCredentialProps =
| LoadingModuleProps
| (BaseModuleProps & ImageProps & PressableModuleBaseProps);
| BaseModuleProps & ImageProps & PressableModuleBaseProps;

const ModuleCredential = (props: WithTestID<ModuleCredentialProps>) => {
const theme = useIOTheme();

if (props.isLoading) {
return <ModuleCredentialSkeleton />;
}
const ModuleCredential = (
props: WithTestID<LoadingModuleProps | ModuleCredentialProps>
) =>
props.isLoading ? (
<ModuleCredentialSkeleton />
) : (
<ModuleCredentialContent {...props} />
);

const {
testID,
icon,
image,
label,
onPress,
badge,
isFetching,
...pressableProps
} = props;
const ModuleCredentialContent = ({
testID,
icon,
image,
label,
onPress,
badge,
isFetching,
...pressableProps
}: WithTestID<ModuleCredentialProps>) => {
const theme = useIOTheme();

const iconComponent = icon && (
<Icon
Expand All @@ -80,6 +80,33 @@ const ModuleCredential = (props: WithTestID<ModuleCredentialProps>) => {
/>
);

const endComponent = React.useMemo(() => {
if (isFetching) {
return (
<LoadingSpinner
testID={testID ? `${testID}_activityIndicator` : undefined}
color={theme["interactiveElem-default"]}
/>
);
}
if (badge) {
return (
<Badge {...badge} testID={testID ? `${testID}_badge` : undefined} />
);
}
if (onPress) {
return (
<Icon
testID={testID ? `${testID}_icon` : undefined}
name="chevronRightListItem"
color={theme["interactiveElem-default"]}
size={IOListItemVisualParams.chevronSize}
/>
);
}
return null;
}, [testID, theme, isFetching, badge, onPress]);

const ModuleContent = () => (
<HStack space={8} style={{ alignItems: "center" }}>
<HStack
Expand All @@ -99,24 +126,7 @@ const ModuleCredential = (props: WithTestID<ModuleCredentialProps>) => {
{label}
</BodySmall>
</HStack>
<View style={IOStyles.row}>
{badge ? (
<Badge {...badge} testID={testID ? `${testID}_badge` : undefined} />
) : null}
{isFetching ? (
<LoadingSpinner
testID={testID ? `${testID}_activityIndicator` : undefined}
color={theme["interactiveElem-default"]}
/>
) : onPress ? (
<Icon
testID={testID ? `${testID}_icon` : undefined}
name="chevronRightListItem"
color={theme["interactiveElem-default"]}
size={IOListItemVisualParams.chevronSize}
/>
) : null}
</View>
{endComponent}
</HStack>
);

Expand Down

0 comments on commit 4b1012e

Please sign in to comment.