feat: inital query logic to cross product endpoint

This commit is contained in:
Jody Bailey
2023-05-16 08:51:40 +02:00
parent be1e1bf7d9
commit 7bd3452dc3
3 changed files with 73 additions and 9 deletions

View File

@@ -0,0 +1,10 @@
import { get, stringifyUrl } from 'data/services/lms/utils';
import urls from 'data/services/lms/urls';
export const getCrossProductRecommendationsUrl = (courseId) => `${urls.api}/learner_recommendations/cross_product/${courseId}`;
const fetchCrossProductCourses = (courseId) => get(stringifyUrl(getCrossProductRecommendationsUrl(courseId)));
export default {
fetchCrossProductCourses,
};

View File

@@ -4,24 +4,28 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import './index.scss';
import messages from '../messages';
import useFetchCrossProductCourses from '../hooks';
import ProductCardContainer from './ProductCardContainer';
import mockCrossProductRecommendations from '../mockData';
const ProductRecommendationsContainer = () => {
const { formatMessage } = useIntl();
const mockRecommendations = mockCrossProductRecommendations.courses;
const { productRecommendations, isProductRecommendationsLoading } = useFetchCrossProductCourses();
return (
<div className="bg-light-200">
<Container
size="lg"
className="recommendations-container pt-sm-5 pt-4.5 pb-2 pb-sm-4.5"
>
<h2 className="mb-4">
{formatMessage(messages.recommendationsHeading)}
</h2>
<ProductCardContainer courses={mockRecommendations} />
</Container>
{!isProductRecommendationsLoading && (
<Container
size="lg"
className="recommendations-container pt-sm-5 pt-4.5 pb-2 pb-sm-4.5"
>
<h2 className="mb-4">
{formatMessage(messages.recommendationsHeading)}
</h2>
<ProductCardContainer courses={productRecommendations} />
</Container>
)}
</div>
);
};

View File

@@ -0,0 +1,50 @@
import { useState, useEffect } from "react";
import { StrictDict } from 'utils';
import api from './api';
import * as module from './hooks';
// export const state = StrictDict({
// requestState: (val) => useState(val), // eslint-disable-line
// courses: (val) => useState(val), // eslint-disable-line
// });
const useFetchMostRecentCourse = () => {
// Gets the most recent course a user is enrolled in
// Goes through the courses enrollment property and checks the lastEnrolled property?
// Can we assume that the order the courses are listed on the Dashbaord is the order that the course was enrolled in?
};
const useFetchCrossProductCourses = () => {
const [productRecommendations, setProductRecommendations] = useState([]);
const [isProductRecommendationsLoading, setIsProductRecommendationsLoading] = useState(false);
// Uses the data from the most recently enrolled course to get the courseId to query our cross product endpoint
// const mostRecentCourse = useFetchMostRecentCourse()
useEffect(() => {
let isMounted = true;
setIsProductRecommendationsLoading(true);
if (isMounted) {
api
.fetchCrossProductCourses('course-v1:IBM+IBMBCC001+1T2022')
.then((response) => {
if (response.status === 200) {
setIsProductRecommendationsLoading(false);
setProductRecommendations(response.data.courses);
}
});
}
return () => { isMounted = false; };
}, []); // most recent course ID will be the dependancy
return {
productRecommendations,
isProductRecommendationsLoading,
};
};
const useFetchAlgoliaRecommendations = () => {
// This hook will fetch algolia reccs and return the reccs
}
export default useFetchCrossProductCourses;