Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [IOBP-1096] Replace legacy markdown component for IDPay #6585

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import React from "react";
import { StyleSheet, View } from "react-native";
import Placeholder from "rn-placeholder";
import { IOStyles } from "../../../../components/core/variables/IOStyles";
import LegacyMarkdown from "../../../../components/ui/Markdown/LegacyMarkdown";
import I18n from "../../../../i18n";
import { useIOBottomSheetAutoresizableModal } from "../../../../utils/hooks/bottomSheet";
import IOMarkdown from "../../../../components/IOMarkdown";

type Props = {
content: string;
Expand All @@ -25,7 +25,7 @@ const InitiativeRulesInfoBox = (props: Props) => {

const { bottomSheet, present, dismiss } = useIOBottomSheetAutoresizableModal(
{
component: <LegacyMarkdown>{content}</LegacyMarkdown>,
component: <IOMarkdown content={content} />,
title: I18n.t("idpay.initiative.beneficiaryDetails.infoModal.title"),
footer: (
<ContentWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
import { VSpacer } from "@pagopa/io-app-design-system";
import * as React from "react";
import { View } from "react-native";
import Placeholder from "rn-placeholder";
import { VSpacer } from "@pagopa/io-app-design-system";
import LegacyMarkdown from "../../../../components/ui/Markdown/LegacyMarkdown";

type Props = {
description: string;
onLoadEnd: () => void;
};

const OnboardingDescriptionMarkdown = (props: Props) => {
const { description, onLoadEnd } = props;

const [isLoaded, setLoaded] = React.useState(false);

const handleOnLoadEnd = () => {
// The markdown component has a different height for some istants after finishing loading
// Setting a timeout allows to properly display other components once the Markdown has finished
// loading.
setTimeout(() => {
setLoaded(true);
onLoadEnd();
}, 300);
};

if (description.length > 0) {
return (
<View style={{ flexGrow: 1 }}>
{!isLoaded && <OnboardingDescriptionMarkdownSkeleton />}
<LegacyMarkdown onLoadEnd={handleOnLoadEnd}>
{description}
</LegacyMarkdown>
</View>
);
}

return <View style={{ flexGrow: 1 }} />;
};

const OnboardingDescriptionMarkdownSkeleton = () => (
<>
Expand Down Expand Up @@ -68,4 +33,4 @@ const OnboardingDescriptionMarkdownSkeleton = () => (
</>
);

export { OnboardingDescriptionMarkdown, OnboardingDescriptionMarkdownSkeleton };
export { OnboardingDescriptionMarkdownSkeleton };
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { pipe } from "fp-ts/lib/function";
import * as React from "react";
import { StyleSheet, View } from "react-native";
import { ForceScrollDownView } from "../../../../components/ForceScrollDownView";
import IOMarkdown from "../../../../components/IOMarkdown";
import ItemSeparatorComponent from "../../../../components/ItemSeparatorComponent";
import { FooterActions } from "../../../../components/ui/FooterActions";
import { useHeaderSecondLevel } from "../../../../hooks/useHeaderSecondLevel";
import I18n from "../../../../i18n";
import { emptyContextualHelp } from "../../../../utils/emptyContextualHelp";
import { isLoadingSelector } from "../../common/machine/selectors";
import {
OnboardingDescriptionMarkdown,
OnboardingDescriptionMarkdownSkeleton
} from "../components/OnboardingDescriptionMarkdown";
import { OnboardingDescriptionMarkdownSkeleton } from "../components/OnboardingDescriptionMarkdown";
import { OnboardingPrivacyAdvice } from "../components/OnboardingPrivacyAdvice";
import { OnboardingServiceHeader } from "../components/OnboardingServiceHeader";
import { IdPayOnboardingMachineContext } from "../machine/provider";
Expand Down Expand Up @@ -47,7 +45,6 @@ export const InitiativeDetailsScreen = () => {

const initiative = useSelector(selectInitiative);
const isLoading = useSelector(isLoadingSelector);
const [isDescriptionLoaded, setDescriptionLoaded] = React.useState(false);

const handleGoBackPress = () => machine.send({ type: "close" });
const handleContinuePress = () => machine.send({ type: "next" });
Expand All @@ -66,12 +63,7 @@ export const InitiativeDetailsScreen = () => {
initiative,
O.fold(
() => <OnboardingDescriptionMarkdownSkeleton />,
({ description }) => (
<OnboardingDescriptionMarkdown
onLoadEnd={() => setDescriptionLoaded(true)}
description={description}
/>
)
({ description }) => <IOMarkdown content={description} />
)
);

Expand All @@ -85,7 +77,6 @@ export const InitiativeDetailsScreen = () => {
return (
<ForceScrollDownView
threshold={50}
scrollEnabled={isDescriptionLoaded}
contentContainerStyle={styles.scrollContainer}
>
<View style={styles.container}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { pipe } from "fp-ts/lib/function";
import React from "react";
import { ScrollView, StyleSheet, View } from "react-native";
import { ServiceId } from "../../../../../definitions/backend/ServiceId";
import IOMarkdown from "../../../../components/IOMarkdown";
import { IOStyles } from "../../../../components/core/variables/IOStyles";
import LegacyMarkdown from "../../../../components/ui/Markdown/LegacyMarkdown";
import { useHeaderSecondLevel } from "../../../../hooks/useHeaderSecondLevel";
import I18n from "../../../../i18n";
import { useIOSelector } from "../../../../store/hooks";
Expand Down Expand Up @@ -58,14 +58,14 @@ export const PDNDPrerequisitesScreen = () => {
"idpay.onboarding.PDNDPrerequisites.prerequisites.info.header"
),
component: (
<LegacyMarkdown>
{I18n.t(
<IOMarkdown
content={I18n.t(
"idpay.onboarding.PDNDPrerequisites.prerequisites.info.body",
{
provider: authority
}
)}
</LegacyMarkdown>
/>
),
footer: (
<ContentWrapper>
Expand Down
Loading