Skip to content

Commit

Permalink
WIP set unread comments threads indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhsaxena committed Jun 20, 2021
1 parent 598a48c commit 62690b6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/client/src/actions/commentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,12 @@ export const setAreCommentsEnabled = (flag: boolean) => ({
type: ReduxActionTypes.SET_ARE_COMMENTS_ENABLED,
payload: flag,
});

export const fetchUnreadCommentThreadsCountRequest = () => ({
type: ReduxActionTypes.FETCH_UNREAD_COMMENT_THREADS_COUNT_REQUEST,
});

export const fetchUnreadCommentThreadsCountSuccess = (flag: boolean) => ({
type: ReduxActionTypes.FETCH_UNREAD_COMMENT_THREADS_COUNT_SUCCESS,
payload: flag,
});
5 changes: 5 additions & 0 deletions app/client/src/api/CommentsAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class CommentsApi extends Api {
data: request,
});
}

// eslint-disable-next-line
static fetchUnreadCommentThreads(applicationId: string) {
return Promise.resolve({ data: { count: 10 } });
}
}

export default CommentsApi;
4 changes: 4 additions & 0 deletions app/client/src/constants/ReduxActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const ReduxSagaChannels: { [key: string]: string } = {
};

export const ReduxActionTypes: { [key: string]: string } = {
FETCH_UNREAD_COMMENT_THREADS_COUNT_REQUEST:
"FETCH_UNREAD_COMMENT_THREADS_COUNT_REQUEST",
FETCH_UNREAD_COMMENT_THREADS_COUNT_SUCCESS:
"FETCH_UNREAD_COMMENT_THREADS_COUNT_SUCCESS",
MARK_ALL_NOTIFICATIONS_AS_READ_REQUEST:
"MARK_ALL_NOTIFICATIONS_AS_READ_REQUEST",
MARK_ALL_NOTIFICATIONS_AS_READ_SUCCESS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const commentsReducer = createReducer(initialState, {
) => ({
...state,
isCommentMode: action.payload,
showUnreadIndicator: false,
isIntroCarouselVisible: false,
}),
[ReduxActionTypes.CREATE_COMMENT_THREAD_REQUEST]: (
Expand Down Expand Up @@ -116,9 +115,7 @@ const commentsReducer = createReducer(initialState, {
),
};

const showUnreadIndicator = !state.isCommentMode;

return { ...state, showUnreadIndicator };
return { ...state };
},
[ReduxActionTypes.UPDATE_COMMENT_THREAD_SUCCESS]: (
state: CommentsReduxState,
Expand Down Expand Up @@ -260,6 +257,13 @@ const commentsReducer = createReducer(initialState, {
) => {
return handleUpdateCommentEvent(state, action);
},
[ReduxActionTypes.FETCH_UNREAD_COMMENT_THREADS_COUNT_SUCCESS]: (
state: CommentsReduxState,
action: ReduxAction<boolean>,
) => ({
...state,
showUnreadIndicator: action.payload,
}),
});

export default commentsReducer;
24 changes: 24 additions & 0 deletions app/client/src/sagas/CommentSagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
deleteCommentThreadSuccess,
setAreCommentsEnabled,
setCommentMode,
fetchUnreadCommentThreadsCountSuccess,
fetchUnreadCommentThreadsCountRequest,
} from "actions/commentActions";
import {
transformPublishedCommentActionPayload,
Expand Down Expand Up @@ -112,6 +114,7 @@ function* fetchApplicationComments() {

if (isValidResponse) {
yield put(fetchApplicationCommentsSuccess(response.data));
yield put(fetchUnreadCommentThreadsCountRequest());
} else {
// todo invalid response
}
Expand Down Expand Up @@ -181,6 +184,7 @@ function* markThreadAsRead(action: ReduxAction<{ threadId: string }>) {
const isValidResponse = yield validateResponse(response);
if (isValidResponse) {
yield put(updateCommentThreadSuccess(response.data));
yield put(fetchUnreadCommentThreadsCountRequest());
}
} catch (e) {
console.log(e, "handle error");
Expand Down Expand Up @@ -264,6 +268,22 @@ function* deleteCommentReaction(
}
}

function* fetchUnreadCommentsCount() {
try {
const applicationId = yield select(getCurrentApplicationId);
const response = yield call(
CommentsApi.fetchUnreadCommentThreads,
applicationId,
);
// const isValidResponse = yield validateResponse(response);
// if (isValidResponse) {
yield put(fetchUnreadCommentThreadsCountSuccess(response.data.count > 0));
// }
} catch (e) {
console.log(e, "handle error");
}
}

export default function* commentSagas() {
yield all([
takeLatest(
Expand Down Expand Up @@ -294,5 +314,9 @@ export default function* commentSagas() {
takeLatest(ReduxActionTypes.ADD_COMMENT_REACTION, addCommentReaction),
takeLatest(ReduxActionTypes.REMOVE_COMMENT_REACTION, deleteCommentReaction),
fork(setIfCommentsAreEnabled),
takeLatest(
ReduxActionTypes.FETCH_UNREAD_COMMENT_THREADS_COUNT_REQUEST,
fetchUnreadCommentsCount,
),
]);
}
5 changes: 5 additions & 0 deletions app/client/src/sagas/WebsocketSagas/handleSocketEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
newCommentThreadEvent,
updateCommentThreadEvent,
updateCommentEvent,
fetchUnreadCommentThreadsCountRequest,
} from "actions/commentActions";

import { newNotificationEvent } from "actions/notificationActions";
Expand All @@ -15,18 +16,22 @@ export default function* handleSocketEvent(event: any) {
// comments
case SOCKET_EVENTS.INSERT_COMMENT_THREAD: {
yield put(newCommentThreadEvent(event.payload[0]));
yield put(fetchUnreadCommentThreadsCountRequest());
return;
}
case SOCKET_EVENTS.INSERT_COMMENT: {
yield put(newCommentEvent(event.payload[0]));
yield put(fetchUnreadCommentThreadsCountRequest());
return;
}
case SOCKET_EVENTS.UPDATE_COMMENT_THREAD: {
yield put(updateCommentThreadEvent(event.payload[0].thread));
yield put(fetchUnreadCommentThreadsCountRequest());
return;
}
case SOCKET_EVENTS.UPDATE_COMMENT: {
yield put(updateCommentEvent(event.payload[0].comment));
yield put(fetchUnreadCommentThreadsCountRequest());
return;
}
// notifications
Expand Down

0 comments on commit 62690b6

Please sign in to comment.