diff --git a/src/discussions/posts/data/api.js b/src/discussions/posts/data/api.js index 530edb1d..ed8c6328 100644 --- a/src/discussions/posts/data/api.js +++ b/src/discussions/posts/data/api.js @@ -27,6 +27,7 @@ export const coursesApiUrl = `${apiBaseUrl}/api/discussion/v1/courses/`; * @param {string} threadType Can be 'discussion' or 'question'. * @param {ThreadViewStatus} view Set to "unread" on "unanswered" to filter to only those statuses. * @param {boolean} countFlagged If true, abuseFlaggedCount will be available. + * @param {number} cohort * @returns {Promise<{}>} */ export async function getThreads( diff --git a/src/discussions/posts/data/thunks.js b/src/discussions/posts/data/thunks.js index b9883d26..71fc0d94 100644 --- a/src/discussions/posts/data/thunks.js +++ b/src/discussions/posts/data/thunks.js @@ -44,9 +44,10 @@ import { * Normalises raw data returned by threads API by mapping threads to id and * mapping topic ids to threads in them. * @param data + * @param {[string]?} topicIds * @returns {{pagination, threadsById: {}, threadsInTopic: {}, avatars: {}}} */ -export function normaliseThreads(data) { +export function normaliseThreads(data, topicIds = null) { const normalized = {}; let threads; if ('results' in data) { @@ -59,6 +60,11 @@ export function normaliseThreads(data) { const threadsById = {}; let avatars = {}; const ids = []; + if (topicIds) { + topicIds.forEach(topicId => { + threadsInTopic[topicId] = []; + }); + } threads.forEach( thread => { const { topicId, id } = thread; @@ -129,7 +135,7 @@ export function fetchThreads(courseId, { try { dispatch(fetchThreadsRequest({ courseId })); const data = await getThreads(courseId, options); - const normalisedData = normaliseThreads(camelCaseObject(data)); + const normalisedData = normaliseThreads(camelCaseObject(data), topicIds); dispatch(fetchThreadsSuccess({ ...normalisedData, page, author })); } catch (error) { if (getHttpErrorStatus(error) === 403) {