generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render course listing in paragon carousel
- Loading branch information
1 parent
da1c9c2
commit fd2e362
Showing
9 changed files
with
178 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { setupListeners } from '@reduxjs/toolkit/query'; | ||
import { coursesApi } from '../example'; | ||
|
||
const store = configureStore({ | ||
reducer: { | ||
// Add the generated reducer as a specific top-level slice | ||
[coursesApi.reducerPath]: coursesApi.reducer, | ||
}, | ||
// Adding the api middleware enables caching, invalidation, polling, | ||
// and other useful features of `rtk-query`. | ||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(coursesApi.middleware), | ||
}); | ||
|
||
setupListeners(store.dispatch); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Carousel } from '@edx/paragon'; | ||
|
||
const examplePrevIcon = ( | ||
<img width="100px" alt="Previous" src="https://raw.githubusercontent.com/brian-smith-tcril/workshop-images/73023da716b7b11723a2eea5d2a76a2ab944c55d/aiga_left_arrow_bg.svg" /> | ||
); | ||
|
||
const exampleNextIcon = ( | ||
<img width="100px" alt="Next" src="https://raw.githubusercontent.com/brian-smith-tcril/workshop-images/73023da716b7b11723a2eea5d2a76a2ab944c55d/aiga_right_arrow_bg.svg" /> | ||
); | ||
|
||
const ExampleCarousel = ({ carouselData }) => ( | ||
<Carousel prevIcon={examplePrevIcon} nextIcon={exampleNextIcon}> | ||
{carouselData.map(carouselEntryData => ( | ||
<Carousel.Item> | ||
<div className="img-gradient"> | ||
<img | ||
className="d-block w-100" | ||
src={carouselEntryData.imageUrl} | ||
alt={carouselEntryData.imageAltText} | ||
/> | ||
</div> | ||
<Carousel.Caption> | ||
<h1 style={{ color: 'white' }}>{carouselEntryData.title}</h1> | ||
<p>{carouselEntryData.description}</p> | ||
</Carousel.Caption> | ||
</Carousel.Item> | ||
))} | ||
</Carousel> | ||
); | ||
|
||
ExampleCarousel.propTypes = { | ||
carouselData: PropTypes.arrayOf(PropTypes.shape({ | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
imageUrl: PropTypes.string, | ||
imageAltText: PropTypes.string, | ||
})).isRequired, | ||
}; | ||
|
||
export default ExampleCarousel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { Container } from '@edx/paragon'; | ||
import { useGetCoursesQuery } from './data/coursesApiService'; | ||
import ExampleCarousel from './ExampleCarousel'; | ||
|
||
const ExamplePage = () => ( | ||
<main> | ||
<Container className="py-5"> | ||
<h1>Example Page</h1> | ||
<p>Hello world!</p> | ||
</Container> | ||
</main> | ||
); | ||
const ExamplePage = () => { | ||
const { data, error, isLoading } = useGetCoursesQuery(); | ||
|
||
return ( | ||
<main> | ||
<Container className="py-5"> | ||
{error && <>Oh no, there was an error</>} | ||
{isLoading && <>Loading...</>} | ||
{data && <ExampleCarousel carouselData={data} />} | ||
</Container> | ||
</main> | ||
); | ||
}; | ||
|
||
export default ExamplePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Need to use the React-specific entry point to import createApi | ||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; | ||
|
||
import { ensureConfig, getConfig } from '@edx/frontend-platform'; | ||
|
||
ensureConfig(['LMS_BASE_URL'], 'Courses API service'); | ||
|
||
// Define a service using a base URL and expected endpoints | ||
export const coursesApi = createApi({ | ||
reducerPath: 'coursesApi', | ||
baseQuery: fetchBaseQuery({ baseUrl: `${getConfig().LMS_BASE_URL}/api/` }), | ||
endpoints: (builder) => ({ | ||
getCourses: builder.query({ | ||
query: () => 'courses/v1/courses/', | ||
transformResponse: (response) => response.results.map(entry => ({ | ||
title: entry.name, | ||
description: entry.short_description, | ||
imageUrl: entry.media.banner_image.uri_absolute, | ||
imageAltText: 'API does not return alt text for images', | ||
})), | ||
}), | ||
}), | ||
}); | ||
|
||
// Export hooks for usage in functional components, which are | ||
// auto-generated based on the defined endpoints | ||
export const { useGetCoursesQuery } = coursesApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { coursesApi } from './data/coursesApiService'; | ||
export { default as ExamplePage } from './ExamplePage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.img-gradient:after { | ||
content: ''; | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
background: linear-gradient(0deg, rgba(0,0,0,1) 17%, rgba(0,0,0,0) 100%); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters