fix: display direct link post at top of the list (#226)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user