Skip to content

Commit 35379d1

Browse files
lex111Houssein Djirdeh
authored andcommitted
feat(notifications): add button to mark all notifications as read (#371)
* feat(notifications): add button to mark all notifications as read * refactor(notifications): change after PR feedback * fix(notifications): set correct content block height * fix(notifications): fix eslint some problems * fix(notifications): fix content block height and update counter * feat(notifications): show button for mark all as read only on first tab * refactor(notifications): implements PR review feedbacks
1 parent 2d5cd63 commit 35379d1

File tree

12 files changed

+271
-132
lines changed

12 files changed

+271
-132
lines changed

routes.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,48 +263,44 @@ const MainTabNavigator = TabNavigator(
263263
Home: {
264264
screen: HomeStackNavigator,
265265
navigationOptions: {
266-
tabBarIcon: ({ tintColor }) => (
266+
tabBarIcon: ({ tintColor }) =>
267267
<Icon
268268
containerStyle={{ justifyContent: 'center', alignItems: 'center' }}
269269
color={tintColor}
270270
name="home"
271271
size={33}
272-
/>
273-
),
272+
/>,
274273
},
275274
},
276275
Notifications: {
277276
screen: NotificationsStackNavigator,
278277
navigationOptions: {
279-
tabBarIcon: ({ tintColor }) => (
280-
<NotificationIcon iconColor={tintColor} />
281-
),
278+
tabBarIcon: ({ tintColor }) =>
279+
<NotificationIcon iconColor={tintColor} />,
282280
},
283281
},
284282
Search: {
285283
screen: SearchStackNavigator,
286284
navigationOptions: {
287-
tabBarIcon: ({ tintColor }) => (
285+
tabBarIcon: ({ tintColor }) =>
288286
<Icon
289287
containerStyle={{ justifyContent: 'center', alignItems: 'center' }}
290288
color={tintColor}
291289
name="search"
292290
size={33}
293-
/>
294-
),
291+
/>,
295292
},
296293
},
297294
MyProfile: {
298295
screen: MyProfileStackNavigator,
299296
navigationOptions: {
300-
tabBarIcon: ({ tintColor }) => (
297+
tabBarIcon: ({ tintColor }) =>
301298
<Icon
302299
containerStyle={{ justifyContent: 'center', alignItems: 'center' }}
303300
color={tintColor}
304301
name="person"
305302
size={33}
306-
/>
307-
),
303+
/>,
308304
},
309305
},
310306
},
@@ -319,7 +315,7 @@ const MainTabNavigator = TabNavigator(
319315
backgroundColor: colors.alabaster,
320316
},
321317
},
322-
tabBarComponent: ({ jumpToIndex, ...props }) => (
318+
tabBarComponent: ({ jumpToIndex, ...props }) =>
323319
<TabBarBottom
324320
{...props}
325321
jumpToIndex={index => {
@@ -345,8 +341,7 @@ const MainTabNavigator = TabNavigator(
345341
jumpToIndex(index);
346342
}
347343
}}
348-
/>
349-
),
344+
/>,
350345
}
351346
);
352347

src/api/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ export const fetchMarkNotificationAsRead = (notificationID, accessToken) =>
263263
export const fetchMarkRepoNotificationAsRead = (repoFullName, accessToken) =>
264264
v3.put(`/repos/${repoFullName}/notifications`, accessToken);
265265

266+
export const fetchMarkAllNotificationsAsRead = accessToken =>
267+
v3.put('/notifications', accessToken);
268+
266269
export const fetchChangeStarStatusRepo = (owner, repo, starred, accessToken) =>
267270
v3[starred ? 'delete' : 'put'](`/user/starred/${owner}/${repo}`, accessToken);
268271

src/locale/languages/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const en = {
135135
allButton: 'All',
136136
retrievingMessage: 'Retrieving notifications',
137137
noneMessage: "You don't have any notifications of this type",
138+
markAllAsRead: 'Mark all as read',
138139
},
139140
},
140141
search: {

src/locale/languages/fr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export const fr = {
137137
allButton: 'Tous',
138138
retrievingMessage: 'Récupération des notifications',
139139
noneMessage: "Vous n'avez aucune notification de ce type",
140+
markAllAsRead: 'Mark all as read',
140141
},
141142
},
142143
search: {

src/locale/languages/nl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const nl = {
133133
allButton: 'Alles',
134134
retrievingMessage: 'Notificaties ophalen',
135135
noneMessage: 'Je hebt geen notificaties met dit type',
136+
markAllAsRead: 'Mark all as read',
136137
},
137138
},
138139
search: {

src/locale/languages/pt-br.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export const ptBr = {
132132
allButton: 'Todas',
133133
retrievingMessage: 'Buscando notificações',
134134
noneMessage: 'Você não tem notificações deste tipo',
135+
markAllAsRead: 'Mark all as read',
135136
},
136137
},
137138
search: {

src/locale/languages/ru.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const ru = {
135135
allButton: 'Все',
136136
retrievingMessage: 'Получение уведомлений',
137137
noneMessage: 'У вас нет уведомлений по этому типу',
138+
markAllAsRead: 'Отметить все как прочитанные',
138139
},
139140
},
140141
search: {

src/locale/languages/tr.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const tr = {
133133
allButton: 'Tümü',
134134
retrievingMessage: 'Bildirim alınıyor',
135135
noneMessage: 'Bu türde hiçbir bildirime sahip değilsiniz',
136+
markAllAsRead: 'Mark all as read',
136137
},
137138
},
138139
search: {

src/notifications/notifications.action.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
fetchMarkRepoNotificationAsRead,
55
fetchNotificationsCount,
66
fetchRepoNotificationsCount,
7+
fetchMarkAllNotificationsAsRead,
78
} from 'api';
89
import {
910
GET_UNREAD_NOTIFICATIONS,
@@ -12,6 +13,7 @@ import {
1213
MARK_NOTIFICATION_AS_READ,
1314
MARK_REPO_AS_READ,
1415
GET_NOTIFICATIONS_COUNT,
16+
MARK_ALL_NOTIFICATIONS_AS_READ,
1517
} from './notifications.type';
1618

1719
export const getUnreadNotifications = () => {
@@ -153,3 +155,24 @@ export const getNotificationsCount = () => {
153155
});
154156
};
155157
};
158+
159+
export const markAllNotificationsAsRead = () => {
160+
return (dispatch, getState) => {
161+
const accessToken = getState().auth.accessToken;
162+
163+
dispatch({ type: MARK_ALL_NOTIFICATIONS_AS_READ.PENDING });
164+
165+
fetchMarkAllNotificationsAsRead(accessToken)
166+
.then(() => {
167+
dispatch({
168+
type: MARK_ALL_NOTIFICATIONS_AS_READ.SUCCESS,
169+
});
170+
})
171+
.catch(error => {
172+
dispatch({
173+
type: MARK_ALL_NOTIFICATIONS_AS_READ.ERROR,
174+
payload: error,
175+
});
176+
});
177+
};
178+
};

src/notifications/notifications.reducer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
MARK_NOTIFICATION_AS_READ,
66
MARK_REPO_AS_READ,
77
GET_NOTIFICATIONS_COUNT,
8+
MARK_ALL_NOTIFICATIONS_AS_READ,
89
} from './notifications.type';
910

1011
const initialState = {
@@ -16,6 +17,7 @@ const initialState = {
1617
isPendingAll: false,
1718
isPendingMarkNotificationAsRead: false,
1819
isPendingRepoMarkAsRead: false,
20+
isPendingMarkAllNotificationsAsRead: false,
1921
error: '',
2022
notificationsCount: null,
2123
};
@@ -150,6 +152,22 @@ export const notificationsReducer = (state = initialState, action = {}) => {
150152
...state,
151153
error: action.payload,
152154
};
155+
case MARK_ALL_NOTIFICATIONS_AS_READ.PENDING:
156+
return {
157+
...state,
158+
isPendingMarkAllNotificationsAsRead: true,
159+
};
160+
case MARK_ALL_NOTIFICATIONS_AS_READ.SUCCESS:
161+
return {
162+
...state,
163+
isPendingMarkAllNotificationsAsRead: false,
164+
};
165+
case MARK_ALL_NOTIFICATIONS_AS_READ.ERROR:
166+
return {
167+
...state,
168+
error: action.payload,
169+
isPendingMarkAllNotificationsAsRead: false,
170+
};
153171
default:
154172
return state;
155173
}

0 commit comments

Comments
 (0)