fix: display direct link post at top of the list (#226)

This commit is contained in:
Awais Ansari
2022-08-03 13:56:19 +05:00
committed by GitHub
parent 2405040f08
commit 25cf4ce4c8
3 changed files with 21 additions and 4 deletions

View File

@@ -55,8 +55,12 @@ const threadsSlice = createSlice({
state.pages = [];
state.author = payload.author;
}
if (state.pages[payload.page - 1]) {
state.pages[payload.page - 1] = [...state.pages[payload.page - 1], ...payload.ids];
} else {
state.pages[payload.page - 1] = payload.ids;
}
state.status = RequestStatus.SUCCESSFUL;
state.pages[payload.page - 1] = payload.ids;
state.threadsById = { ...state.threadsById, ...payload.threadsById };
state.threadsInTopic = { ...state.threadsInTopic, ...payload.threadsInTopic };
state.avatars = { ...state.avatars, ...payload.avatars };
@@ -78,6 +82,13 @@ const threadsSlice = createSlice({
state.threadsById = { ...state.threadsById, ...payload.threadsById };
state.avatars = { ...state.avatars, ...payload.avatars };
},
fetchThreadByDirectLinkSuccess: (state, { payload }) => {
state.status = RequestStatus.SUCCESSFUL;
state.pages[payload.page - 1] = payload.ids;
state.threadsInTopic = { ...payload.threadsInTopic, ...state.threadsInTopic };
state.threadsById = { ...payload.threadsById, ...state.threadsById };
state.avatars = { ...state.avatars, ...payload.avatars };
},
fetchThreadFailed: (state) => {
state.status = RequestStatus.FAILED;
},
@@ -194,6 +205,7 @@ export const {
fetchThreadsRequest,
fetchThreadsSuccess,
fetchThreadSuccess,
fetchThreadByDirectLinkSuccess,
postThreadDenied,
postThreadFailed,
postThreadRequest,

View File

@@ -14,6 +14,7 @@ import {
deleteThreadFailed,
deleteThreadRequest,
deleteThreadSuccess,
fetchThreadByDirectLinkSuccess,
fetchThreadDenied,
fetchThreadFailed,
fetchThreadRequest,
@@ -148,12 +149,16 @@ export function fetchThreads(courseId, {
};
}
export function fetchThread(threadId) {
export function fetchThread(threadId, isDirectLinkPost = false) {
return async (dispatch) => {
try {
dispatch(fetchThreadRequest({ threadId }));
const data = await getThread(threadId);
dispatch(fetchThreadSuccess(normaliseThreads(camelCaseObject(data))));
if (isDirectLinkPost) {
dispatch(fetchThreadByDirectLinkSuccess({ ...normaliseThreads(camelCaseObject(data)), page: 1 }));
} else {
dispatch(fetchThreadSuccess(normaliseThreads(camelCaseObject(data))));
}
} catch (error) {
if (getHttpErrorStatus(error) === 403) {
dispatch(fetchThreadDenied());