From c24af09afb8cf972cfc0af2ab56dbd55020c4876 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Thu, 21 Nov 2024 13:43:06 +0500 Subject: [PATCH 1/3] fix: fixed reponsiveness issues on mobile view --- src/profile-v2/CertificateCard.jsx | 53 +++++++++++--- src/profile-v2/Certificates.jsx | 98 +++++++++++++++----------- src/profile-v2/ProfilePage.jsx | 69 +++++++++++++++--- src/profile-v2/UsernameDescription.jsx | 33 +++++---- src/profile-v2/index.scss | 3 + 5 files changed, 186 insertions(+), 70 deletions(-) diff --git a/src/profile-v2/CertificateCard.jsx b/src/profile-v2/CertificateCard.jsx index bbdb55f6b..53005ea17 100644 --- a/src/profile-v2/CertificateCard.jsx +++ b/src/profile-v2/CertificateCard.jsx @@ -1,9 +1,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FormattedDate, FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; -import { Hyperlink } from '@openedx/paragon'; +import { breakpoints, Hyperlink, useWindowSize } from '@openedx/paragon'; import get from 'lodash.get'; +import classNames from 'classnames'; import professionalCertificateSVG from './assets/professional-certificate.svg'; import verifiedCertificateSVG from './assets/verified-certificate.svg'; import messages from './Certificates.messages'; @@ -27,6 +28,8 @@ const CertificateCard = ({ audit: null, }[certificateType] || null; + const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; + return (
-
+
-

+

{intl.formatMessage(get( messages, `profile.certificates.types.${certificateType}`, messages['profile.certificates.types.unknown'], ))}

-

{courseDisplayName}

-

+

+ {courseDisplayName} +

+

{courseOrganization}
-

+

{intl.formatMessage(messages['profile.certificates.view.certificate'])}

-

+

( -

-
-
-

- -

+const Certificates = ({ certificates }) => { + const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; + const isTabletView = useWindowSize().width <= breakpoints.medium.minWidth; + return ( +
+
+
+

+ +

+
+
+

+ +

+
-
-

+ {certificates?.length > 0 ? ( +

+
+ {certificates.map(certificate => ( + + ))} +
+
+ ) : ( +
-

-
-
- {certificates?.length > 0 ? ( -
-
- {certificates.map(certificate => ( - - ))}
-
- ) : ( -
- -
- )} -
-); + )} +
+ ); +}; Certificates.propTypes = { certificates: PropTypes.arrayOf(PropTypes.shape({ diff --git a/src/profile-v2/ProfilePage.jsx b/src/profile-v2/ProfilePage.jsx index 22bcf7179..c853ae30a 100644 --- a/src/profile-v2/ProfilePage.jsx +++ b/src/profile-v2/ProfilePage.jsx @@ -7,7 +7,13 @@ import { sendTrackingLogEvent } from '@edx/frontend-platform/analytics'; import { ensureConfig, getConfig } from '@edx/frontend-platform'; import { AppContext } from '@edx/frontend-platform/react'; import { useIntl } from '@edx/frontend-platform/i18n'; -import { Alert, Hyperlink } from '@openedx/paragon'; +import { + Alert, + Hyperlink, + breakpoints, + useWindowSize, +} from '@openedx/paragon'; +import classNames from 'classnames'; import { fetchProfile, saveProfilePhoto, @@ -42,6 +48,8 @@ const ProfilePage = ({ params }) => { } = useSelector(profilePageSelector); const [viewMyRecordsUrl, setViewMyRecordsUrl] = useState(null); + const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; + const isTabletView = useWindowSize().width <= breakpoints.medium.minWidth; useEffect(() => { const { CREDENTIALS_BASE_URL } = context.config; @@ -81,7 +89,10 @@ const ProfilePage = ({ params }) => { return ( { ) : ( <> -
+
-
+
{ savePhotoState={savePhotoState} isEditable={isAuthenticatedUserProfile() && !requiresParentalConsent} /> -
-

{params.username}

+
+

+ {params.username} +

{isBlockVisible(name) && ( -

{name}

+

+ {name} +

+ )} +
+ >
-
+
{renderViewMyRecordsButton()}
diff --git a/src/profile-v2/UsernameDescription.jsx b/src/profile-v2/UsernameDescription.jsx index bbbd70333..d807903bc 100644 --- a/src/profile-v2/UsernameDescription.jsx +++ b/src/profile-v2/UsernameDescription.jsx @@ -1,18 +1,27 @@ import React from 'react'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; import { getConfig } from '@edx/frontend-platform'; +import classNames from 'classnames'; +import { breakpoints, useWindowSize } from '@openedx/paragon'; -const UsernameDescription = () => ( -

- -

-); +const UsernameDescription = () => { + const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; + return ( +

+ +

+ ); +}; export default UsernameDescription; diff --git a/src/profile-v2/index.scss b/src/profile-v2/index.scss index 32762c523..0538ccfcd 100644 --- a/src/profile-v2/index.scss +++ b/src/profile-v2/index.scss @@ -151,6 +151,9 @@ max-width: 32em; } +.max-width-19rem{ + max-width: 19rem; +} .width-75rem { width: 75rem; } From 99d3a296b40ad8f7d57b4dbbebea5ec29047a5e3 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Thu, 21 Nov 2024 14:50:59 +0500 Subject: [PATCH 2/3] test: updated tests --- .../__snapshots__/ProfilePage.test.jsx.snap | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/profile-v2/__snapshots__/ProfilePage.test.jsx.snap b/src/profile-v2/__snapshots__/ProfilePage.test.jsx.snap index d0434b33a..204043b89 100644 --- a/src/profile-v2/__snapshots__/ProfilePage.test.jsx.snap +++ b/src/profile-v2/__snapshots__/ProfilePage.test.jsx.snap @@ -31,7 +31,7 @@ exports[` Renders correctly in various states viewing other profi class="profile-page" >
Renders correctly in various states viewing other profi class="col h-100 w-100 py-4 px-0 justify-content-start g-15rem" >
Renders correctly in various states viewing other profi
-

staff -

+

user

@@ -111,7 +111,7 @@ exports[` Renders correctly in various states viewing other profi
Renders correctly in various states viewing other profi class="row-auto d-flex align-items-center h-100 w-100 justify-content-start m-0 pt-4" >

Your learner records information is only visible to you. Only your username is visible to others on localhost.

@@ -148,17 +148,17 @@ exports[` Renders correctly in various states viewing other profi
-

Your certificates -

+

Your learner records information is only visible to you. Only your username is visible to others on localhost.

@@ -181,7 +181,7 @@ exports[` Renders correctly in various states viewing own profile class="profile-page" >
Renders correctly in various states viewing own profile class="col h-100 w-100 py-4 px-0 justify-content-start g-15rem" >
Renders correctly in various states viewing own profile
-

staff -

+

Lemon Seltzer

@@ -277,7 +277,7 @@ exports[` Renders correctly in various states viewing own profile
Renders correctly in various states viewing own profile
-

Your certificates -

+

Credential ID

@@ -407,7 +407,7 @@ exports[` Renders correctly in various states without credentials class="profile-page" >
Renders correctly in various states without credentials class="col h-100 w-100 py-4 px-0 justify-content-start g-15rem" >
Renders correctly in various states without credentials
-

staff -

+

Lemon Seltzer

@@ -503,7 +503,7 @@ exports[` Renders correctly in various states without credentials
Renders correctly in various states without credentials
-

Your certificates -

+

Your learner records information is only visible to you. Only your username is visible to others on localhost.

@@ -564,17 +564,17 @@ exports[` Renders correctly in various states without credentials class="w-100 color-black" >

Verified Certificate

-

edX Demonstration Course -

+

From

@@ -584,7 +584,7 @@ exports[` Renders correctly in various states without credentials edX

Completed on 3/4/2019 @@ -603,7 +603,7 @@ exports[` Renders correctly in various states without credentials

Credential ID

From 43b03829f0a9c98ab5779045f9e6bc90611d5d37 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Fri, 22 Nov 2024 15:57:17 +0500 Subject: [PATCH 3/3] refactor: refactored code as requested --- src/profile-v2/CertificateCard.jsx | 8 ++++---- src/profile-v2/Certificates.jsx | 17 +++++++++++++---- src/profile-v2/ProfilePage.jsx | 12 ++++-------- src/profile-v2/UsernameDescription.jsx | 4 ++-- src/profile-v2/data/hooks.js | 11 +++++++++++ 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/profile-v2/data/hooks.js diff --git a/src/profile-v2/CertificateCard.jsx b/src/profile-v2/CertificateCard.jsx index 53005ea17..360a7c811 100644 --- a/src/profile-v2/CertificateCard.jsx +++ b/src/profile-v2/CertificateCard.jsx @@ -1,13 +1,14 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FormattedDate, FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; -import { breakpoints, Hyperlink, useWindowSize } from '@openedx/paragon'; +import { Hyperlink } from '@openedx/paragon'; import get from 'lodash.get'; import classNames from 'classnames'; import professionalCertificateSVG from './assets/professional-certificate.svg'; import verifiedCertificateSVG from './assets/verified-certificate.svg'; import messages from './Certificates.messages'; +import { useIsOnMobileScreen } from './data/hooks'; const CertificateCard = ({ certificateType, @@ -28,7 +29,7 @@ const CertificateCard = ({ audit: null, }[certificateType] || null; - const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; + const isMobileView = useIsOnMobileScreen(); return (
{ - const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; - const isTabletView = useWindowSize().width <= breakpoints.medium.minWidth; + const isMobileView = useIsOnMobileScreen(); + const isTabletView = useIsOnTabletScreen(); return (
@@ -53,7 +53,16 @@ const Certificates = ({ certificates }) => { )} > {certificates.map(certificate => ( - + ))}
diff --git a/src/profile-v2/ProfilePage.jsx b/src/profile-v2/ProfilePage.jsx index c853ae30a..9db64afcd 100644 --- a/src/profile-v2/ProfilePage.jsx +++ b/src/profile-v2/ProfilePage.jsx @@ -7,12 +7,7 @@ import { sendTrackingLogEvent } from '@edx/frontend-platform/analytics'; import { ensureConfig, getConfig } from '@edx/frontend-platform'; import { AppContext } from '@edx/frontend-platform/react'; import { useIntl } from '@edx/frontend-platform/i18n'; -import { - Alert, - Hyperlink, - breakpoints, - useWindowSize, -} from '@openedx/paragon'; +import { Alert, Hyperlink } from '@openedx/paragon'; import classNames from 'classnames'; import { fetchProfile, @@ -28,6 +23,7 @@ import PageLoading from './PageLoading'; import { profilePageSelector } from './data/selectors'; import messages from './ProfilePage.messages'; import withParams from '../utils/hoc'; +import { useIsOnMobileScreen, useIsOnTabletScreen } from './data/hooks'; ensureConfig(['CREDENTIALS_BASE_URL', 'LMS_BASE_URL'], 'ProfilePage'); @@ -48,8 +44,8 @@ const ProfilePage = ({ params }) => { } = useSelector(profilePageSelector); const [viewMyRecordsUrl, setViewMyRecordsUrl] = useState(null); - const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; - const isTabletView = useWindowSize().width <= breakpoints.medium.minWidth; + const isMobileView = useIsOnMobileScreen(); + const isTabletView = useIsOnTabletScreen(); useEffect(() => { const { CREDENTIALS_BASE_URL } = context.config; diff --git a/src/profile-v2/UsernameDescription.jsx b/src/profile-v2/UsernameDescription.jsx index d807903bc..dd496e599 100644 --- a/src/profile-v2/UsernameDescription.jsx +++ b/src/profile-v2/UsernameDescription.jsx @@ -2,10 +2,10 @@ import React from 'react'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; import { getConfig } from '@edx/frontend-platform'; import classNames from 'classnames'; -import { breakpoints, useWindowSize } from '@openedx/paragon'; +import { useIsOnMobileScreen } from './data/hooks'; const UsernameDescription = () => { - const isMobileView = useWindowSize().width <= breakpoints.small.minWidth; + const isMobileView = useIsOnMobileScreen(); return (