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

Add fallback image for the course card images #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/containers/CourseCard/components/CourseCardImage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';

import { Badge } from '@openedx/paragon';
Expand All @@ -15,18 +16,23 @@ const { courseImageClicked } = track.course;

export const CourseCardImage = ({ cardId, orientation }) => {
const { formatMessage } = useIntl();
const [hasImageError, setHasImageError] = useState(false);
const { bannerImgSrc } = reduxHooks.useCardCourseData(cardId);
const { homeUrl } = reduxHooks.useCardCourseRunData(cardId);
const { isVerified } = reduxHooks.useCardEnrollmentData(cardId);
const { disableCourseTitle } = useActionDisabledState(cardId);
const handleImageClicked = reduxHooks.useTrackCourseEvent(courseImageClicked, cardId, homeUrl);
const wrapperClassName = `pgn__card-wrapper-image-cap overflow-visible ${orientation}`;
const fallbackImageSrc = `${getConfig().LMS_BASE_URL}/theming/asset/images/no_course_image.png`;
const image = (
Copy link
Contributor

@justinhynes justinhynes Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the no_course_image.png asset included by default as part of edx-platform? I was trying to check now and I can't find any assets in the master branch with this name, but maybe I am missing it.

Copy link
Contributor

@justinhynes justinhynes Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, re-reading your description now, I believe you're saying that the Open edX operator must provide an asset with this name for this feature to work?

I'm a little nervous that this feature would be a bit hard to discover. I think it would be better for operators if there were some standard theme-agnostic placeholder images available in edx-platform that we're referencing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is precedent for hosting a filler image in the MFE itself in case of absence:

I'm not saying I prefer this, architecturally speaking, but it would be a more immediate fix than adding placeholder images to edx-platform.

Also, I don't think hard-cording a reference to an image that needs to be provided as part of a comprehensive theme (something that's likely going away in the future), is the right thing to do here. If we're hard-coding something, it needs to be part of the vanilla edx-platform theme.

<>
<img
className="pgn__card-image-cap show"
src={bannerImgSrc}
src={!hasImageError ? bannerImgSrc : fallbackImageSrc}
alt={formatMessage(messages.bannerAlt)}
onError={() => {
if (!hasImageError) { setHasImageError(true); }
}}
/>
{
isVerified && (
Expand Down
Loading