Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add notifications settings#144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nursoltan-s wants to merge1 commit intotopcoder-platform:notifications-settings
base:notifications-settings
Choose a base branch
Loading
fromnursoltan-s:notifications-settings
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions__tests__/__snapshots__/index.js.snap
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,6 +96,8 @@ Object {
"notifications": Object {
"dismissChallengeNotificationsDone": [Function],
"dismissChallengeNotificationsInit": [Function],
"getNotificationSettingsDone": [Function],
"getNotificationSettingsInit": [Function],
"getNotificationsDone": [Function],
"getNotificationsInit": [Function],
"markAllNotificationAsReadDone": [Function],
Expand All@@ -104,6 +106,8 @@ Object {
"markAllNotificationAsSeenInit": [Function],
"markNotificationAsReadDone": [Function],
"markNotificationAsReadInit": [Function],
"saveNotificationSettingsDone": [Function],
"saveNotificationSettingsInit": [Function],
},
"profile": Object {
"addSkillDone": [Function],
Expand Down
120 changes: 60 additions & 60 deletionsdist/dev/index.js
View file
Open in desktop

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletionsdist/prod/index.js
View file
Open in desktop

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletionssrc/actions/notifications.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,6 +156,56 @@ async function dismissChallengeNotificationsDone(challengeId, tokenV3) {
return true;
}

/**
* @static
* @desc Creates an action that signals beginning of notification settings
* loading.
* @return {Action}
*/
async function getNotificationSettingsInit() {
return { };
}

/**
* @static
* @desc Creates an action that loads member achievements.
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function getNotificationSettingsDone(tokenV3) {
let settingsData;
try {
settingsData = await getService(tokenV3).getNotificationSettings();
} catch (e) {
return { error: e.message };
}
return settingsData.notifications || [];
}

/**
* @static
* @desc Creates an action that signals beginning of save notification settings
* loading.
* @return {Action}
*/
async function saveNotificationSettingsInit() {
return { };
}

/**
* @static
* @desc Creates an action that saves member achievements.
* @param {String} tokenV3 v3 auth token.
* @return {Action}
*/
async function saveNotificationSettingsDone(data, tokenV3) {
try {
await getService(tokenV3).saveNotificationSettings(data);
} catch (e) {
return { error: e.message };
}
return true;
}

export default createActions({
NOTIFICATIONS: {
Expand All@@ -169,5 +219,9 @@ export default createActions({
MARK_ALL_NOTIFICATION_AS_SEEN_DONE: markAllNotificationAsSeenDone,
DISMISS_CHALLENGE_NOTIFICATIONS_INIT: dismissChallengeNotificationsInit,
DISMISS_CHALLENGE_NOTIFICATIONS_DONE: dismissChallengeNotificationsDone,
GET_NOTIFICATION_SETTINGS_INIT: getNotificationSettingsInit,
GET_NOTIFICATION_SETTINGS_DONE: getNotificationSettingsDone,
SAVE_NOTIFICATION_SETTINGS_INIT: saveNotificationSettingsInit,
SAVE_NOTIFICATION_SETTINGS_DONE: saveNotificationSettingsDone,
},
});
75 changes: 75 additions & 0 deletionssrc/reducers/notifications.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,6 +214,77 @@ function onDismissChallengeNotificationsDone(state, { error, payload }) {
}


/**
* Handles NOTIFICATIONS/GET_NOTIFICATION_SETTINGS_INIT action.
* @param {Object} state
* @return {Object} New state
*/
function onGetNotificationSettingsInit(state) {
return { ...state };
}

/**
* Handles NOTIFICATIONS/GET_NOTIFICATION_SETTINGS_DONE action.
* @param {Object} state
* @param {Object} action
* @return {Object} New state.
*/
function onGetNotificationSettingsDone(state, { error, payload }) {
if (payload.error) {
logger.error('Failed to get notification settings!', error);
fireErrorMessage(
'ERROR: Failed to load the notification settings',
'Please, try again a bit later',
);
return {
...state,
fetchNotificationsFailure: true,
notificationSettings: {},
};
}

return {
...state,
fetchNotificationsFailure: false,
notificationSettings: payload,
};
}

/**
* Handles NOTIFICATIONS/SAVE_NOTIFICATION_SETTINGS_INIT action.
* @param {Object} state
* @return {Object} New state
*/
function onsaveNotificationSettingsInit(state) {
return { ...state };
}

/**
* Handles NOTIFICATIONS/SAVE_NOTIFICATION_SETTINGS_DONE action.
* @param {Object} state
* @param {Object} action
* @return {Object} New state.
*/
function onsaveNotificationSettingsDone(state, { error, payload }) {
if (payload.error) {
logger.error('Failed to get notification settings!', error);
fireErrorMessage(
'ERROR: Failed to load the notification settings',
'Please, try again a bit later',
);
return {
...state,
fetchNotificationsFailure: true,
notificationSettings: {},
};
}

return {
...state,
fetchNotificationsFailure: false,
};
}

/**
* Creates a new Members reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand All@@ -232,6 +303,10 @@ function create(initialState = {}) {
[a.markAllNotificationAsSeenDone]: onMarkAllNotificationAsSeenDone,
[a.dismissChallengeNotificationsInit]: onDismissChallengeNotificationsInit,
[a.dismissChallengeNotificationsDone]: onDismissChallengeNotificationsDone,
[a.getNotificationSettingsInit]: onGetNotificationSettingsInit,
[a.getNotificationSettingsDone]: onGetNotificationSettingsDone,
[a.saveNotificationSettingsInit]: onsaveNotificationSettingsInit,
[a.saveNotificationSettingsDone]: onsaveNotificationSettingsDone,
}, initialState);
}

Expand Down
18 changes: 18 additions & 0 deletionssrc/services/notifications.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,6 +64,24 @@ class NotificationService {
return this.private.apiV5.put(`/notifications/${challengeID}/dismiss`)
.then(res => (res.ok ? null : Promise.reject(new Error(res.statusText))));
}

/**
* Gets member's notification settings.
* @return {Promise} Resolves to the notification information object.
*/
async getNotificationSettings() {
return this.private.apiV5.get('/notifications/settings')
.then(res => (res.ok ? res.json() : new Error(res.statusText)));
}

/**
* Save member's notification settings.
* @return {Promise} Resolves to the notification information object.
*/
async saveNotificationSettings(data) {
return this.private.apiV5.put('/notifications/settings', data)
.then(res => (res.ok ? null : Promise.reject(new Error(res.statusText))));
}
}

let lastInstance = null;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp