From 480fd881d1061a07bd0119986ad8c11a7eb17110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Semedo?= <jose.semedo@cern.ch> Date: Thu, 28 Apr 2022 10:22:56 +0200 Subject: [PATCH 1/5] Added action and reducer to update state for subscribed channel. --- .../updates/UpdateSubscribeToChannel.js | 9 ++++++ .../components/ChannelsList/ChannelsList.js | 8 +++-- src/channels/reducers/ChannelsList.js | 29 ++++++++++++------- 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 src/channels/actions/updates/UpdateSubscribeToChannel.js diff --git a/src/channels/actions/updates/UpdateSubscribeToChannel.js b/src/channels/actions/updates/UpdateSubscribeToChannel.js new file mode 100644 index 00000000..0f306dda --- /dev/null +++ b/src/channels/actions/updates/UpdateSubscribeToChannel.js @@ -0,0 +1,9 @@ +// Triggered after subscribing to a channel, to update the state +export const SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS = 'SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS'; + +export const updateSubscribeToChannel = channelId => { + return { + value: channelId, + type: SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, + }; +}; diff --git a/src/channels/components/ChannelsList/ChannelsList.js b/src/channels/components/ChannelsList/ChannelsList.js index 25b9a004..28400de1 100644 --- a/src/channels/components/ChannelsList/ChannelsList.js +++ b/src/channels/components/ChannelsList/ChannelsList.js @@ -17,7 +17,8 @@ import {bindActionCreators} from 'redux'; import * as showSnackBarActionCreator from 'common/actions/Snackbar'; import * as updateChannelActionCreators from 'channels/actions/UpdateChannel'; -import * as subscribeToChannelAcctionCreators from 'channels/actions/SubscribeToChannel'; +import * as subscribeToChannelActionCreators from 'channels/actions/SubscribeToChannel'; +import * as updateSubscribeToChannelActionCreators from 'channels/actions/updates/UpdateSubscribeToChannel'; import * as unsubscribeFromChannelActionCreators from 'channels/actions/UnsubscribeFromChannel'; import * as paginationActioncreators from 'channels/actions/PaginationActions'; import * as getChannelsActionCreators from 'channels/actions/GetChannels'; @@ -37,6 +38,7 @@ const ChannelsList = ({ history, expanded, subscribeToChannel, + updateSubscribeToChannel, unsubscribeFromChannel, toggleFavoriteChannel, getChannelsQuery, @@ -107,6 +109,7 @@ const ChannelsList = ({ 'error' ); } else { + updateSubscribeToChannel(channel.id); setSubscribeId(null); showSnackbar(`Subscribed channel ${channel.name} successfully`, 'success'); } @@ -499,7 +502,8 @@ const mapDispatchToProps = dispatch => { return { ...bindActionCreators(getChannelsActionCreators, dispatch), ...bindActionCreators(updateChannelActionCreators, dispatch), - ...bindActionCreators(subscribeToChannelAcctionCreators, dispatch), + ...bindActionCreators(subscribeToChannelActionCreators, dispatch), + ...bindActionCreators(updateSubscribeToChannelActionCreators, dispatch), ...bindActionCreators(unsubscribeFromChannelActionCreators, dispatch), ...bindActionCreators(paginationActioncreators, dispatch), ...bindActionCreators(getPublicChannelsActionCreators, dispatch), diff --git a/src/channels/reducers/ChannelsList.js b/src/channels/reducers/ChannelsList.js index c8e3f4a2..93669642 100644 --- a/src/channels/reducers/ChannelsList.js +++ b/src/channels/reducers/ChannelsList.js @@ -10,6 +10,7 @@ import { SUBSCRIBE_TO_CHANNEL_FAILURE, SUBSCRIBE_TO_CHANNEL_SUCCESS, } from 'channels/actions/SubscribeToChannel'; +import {SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS} from 'channels/actions/updates/UpdateSubscribeToChannel'; import { UNSUBSCRIBE_FROM_CHANNEL, UNSUBSCRIBE_FROM_CHANNEL_FAILURE, @@ -25,11 +26,6 @@ import { DELETE_CHANNEL_SUCCESS, DELETE_CHANNEL_FAILURE, } from 'channels/actions/DeleteChannel'; -import { - ALL_CHANNELS_I_OWN, - FAVORITE_CHANNELS, - MY_SUBSCRIPTIONS, -} from '../components/ChannelsFilterMenu/ChannelsFilterMenu'; import { GET_USER_SETTINGS, GET_USER_SETTINGS_SUCCESS, @@ -40,6 +36,11 @@ import { TOGGLE_FAVORITE_CHANNEL_SUCCESS, TOGGLE_FAVORITE_CHANNEL_FAILURE, } from 'channels/actions/ToggleFavoriteChannel'; +import { + ALL_CHANNELS_I_OWN, + FAVORITE_CHANNELS, + MY_SUBSCRIPTIONS, +} from '../components/ChannelsFilterMenu/ChannelsFilterMenu'; const INITIAL_STATE = { channels: [], @@ -96,11 +97,15 @@ function processSubscribeToChannel(state) { }; } -function processSubscribeToChannelSuccess(state, channel) { +function processSubscribeToChannelSuccess(state) { + return state; +} + +function processUpdateSubscribeToChannel(state, value) { return { ...state, loadingSubscribe: false, - channels: state.channels.map(c => (c.id === channel.id ? {...c, subscribed: true} : c)), + channels: state.channels.map(c => (c.id === value ? {...c, subscribed: true} : c)), }; } @@ -119,11 +124,11 @@ function processUnsubscribeFromChannel(state) { loadingUnsubscribe: true, }; } -function processUnsubscribeFromChannelSuccess(state, channel) { +function processUnsubscribeFromChannelSuccess(state) { return { ...state, loadingUnsubscribe: false, - channels: state.channels.map(c => (c.id === channel.id ? {...c, subscribed: false} : c)), + // channels: state.channels.map(c => (c.id === channel.id ? {...c, subscribed: false} : c)), }; } @@ -213,8 +218,8 @@ function toggleFavoriteChannel(state) { } function toggleFavoriteChannelSuccess(state, response) { - let updatedFavorites = state.userSettings.favoriteList; - let updatedSettings = { + const updatedFavorites = state.userSettings.favoriteList; + const updatedSettings = { ...state.userSettings, favoriteList: updatedFavorites.includes(response) ? updatedFavorites.filter(f => f !== response) @@ -250,6 +255,8 @@ export default function (state = INITIAL_STATE, action) { return processSubscribeToChannel(state); case SUBSCRIBE_TO_CHANNEL_SUCCESS: return processSubscribeToChannelSuccess(state, action.payload); + case SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS: + return processUpdateSubscribeToChannel(state, action.value); case SUBSCRIBE_TO_CHANNEL_FAILURE: error = action.payload || {message: action.payload.message}; return processSubscribeToChannelFailure(state, error); -- GitLab From cdc2d1048f2f77300fc342fcc47c572c24e3bba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Semedo?= <jose.semedo@cern.ch> Date: Thu, 28 Apr 2022 10:45:06 +0200 Subject: [PATCH 2/5] Added action and reducer to update state for ubsubscribe from channel. --- .../actions/updates/UpdateUnsubscribeFromChannel.js | 9 +++++++++ src/channels/components/ChannelsList/ChannelsList.js | 4 ++++ src/channels/reducers/ChannelsList.js | 9 ++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/channels/actions/updates/UpdateUnsubscribeFromChannel.js diff --git a/src/channels/actions/updates/UpdateUnsubscribeFromChannel.js b/src/channels/actions/updates/UpdateUnsubscribeFromChannel.js new file mode 100644 index 00000000..5cc07886 --- /dev/null +++ b/src/channels/actions/updates/UpdateUnsubscribeFromChannel.js @@ -0,0 +1,9 @@ +// Triggered after unsubscribing from a channel, to update the state +export const UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS = 'UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS'; + +export const updateUnsubscribeFromChannel = channelId => { + return { + value: channelId, + type: UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS, + }; +}; diff --git a/src/channels/components/ChannelsList/ChannelsList.js b/src/channels/components/ChannelsList/ChannelsList.js index 28400de1..d023f8c2 100644 --- a/src/channels/components/ChannelsList/ChannelsList.js +++ b/src/channels/components/ChannelsList/ChannelsList.js @@ -20,6 +20,7 @@ import * as updateChannelActionCreators from 'channels/actions/UpdateChannel'; import * as subscribeToChannelActionCreators from 'channels/actions/SubscribeToChannel'; import * as updateSubscribeToChannelActionCreators from 'channels/actions/updates/UpdateSubscribeToChannel'; import * as unsubscribeFromChannelActionCreators from 'channels/actions/UnsubscribeFromChannel'; +import * as updateUnsubscribeFromChannelActionCreators from 'channels/actions/updates/UpdateUnsubscribeFromChannel'; import * as paginationActioncreators from 'channels/actions/PaginationActions'; import * as getChannelsActionCreators from 'channels/actions/GetChannels'; import * as toggleFavoriteChannelActionCreators from 'channels/actions/ToggleFavoriteChannel'; @@ -40,6 +41,7 @@ const ChannelsList = ({ subscribeToChannel, updateSubscribeToChannel, unsubscribeFromChannel, + updateUnsubscribeFromChannel, toggleFavoriteChannel, getChannelsQuery, setGetChannelsQuery, @@ -94,6 +96,7 @@ const ChannelsList = ({ 'error' ); } else { + updateUnsubscribeFromChannel(channel.id); setUnsubscribeId(null); showSnackbar(`Unsubscribed from channel ${channel.name} successfully`, 'success'); } @@ -505,6 +508,7 @@ const mapDispatchToProps = dispatch => { ...bindActionCreators(subscribeToChannelActionCreators, dispatch), ...bindActionCreators(updateSubscribeToChannelActionCreators, dispatch), ...bindActionCreators(unsubscribeFromChannelActionCreators, dispatch), + ...bindActionCreators(updateUnsubscribeFromChannelActionCreators, dispatch), ...bindActionCreators(paginationActioncreators, dispatch), ...bindActionCreators(getPublicChannelsActionCreators, dispatch), ...bindActionCreators(showSnackBarActionCreator, dispatch), diff --git a/src/channels/reducers/ChannelsList.js b/src/channels/reducers/ChannelsList.js index 93669642..08b3034f 100644 --- a/src/channels/reducers/ChannelsList.js +++ b/src/channels/reducers/ChannelsList.js @@ -16,6 +16,7 @@ import { UNSUBSCRIBE_FROM_CHANNEL_FAILURE, UNSUBSCRIBE_FROM_CHANNEL_SUCCESS, } from 'channels/actions/UnsubscribeFromChannel'; +import {UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS} from 'channels/actions/updates/UpdateUnsubscribeFromChannel'; import { SET_ELEMENTS_PER_PAGE, SET_ACTIVE_PAGE, @@ -125,10 +126,14 @@ function processUnsubscribeFromChannel(state) { }; } function processUnsubscribeFromChannelSuccess(state) { + return state; +} + +function processUpdateUnsubscribeFromChannelSuccess(state, value) { return { ...state, loadingUnsubscribe: false, - // channels: state.channels.map(c => (c.id === channel.id ? {...c, subscribed: false} : c)), + channels: state.channels.map(c => (c.id === value ? {...c, subscribed: false} : c)), }; } @@ -265,6 +270,8 @@ export default function (state = INITIAL_STATE, action) { return processUnsubscribeFromChannel(state); case UNSUBSCRIBE_FROM_CHANNEL_SUCCESS: return processUnsubscribeFromChannelSuccess(state, action.payload); + case UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS: + return processUpdateUnsubscribeFromChannelSuccess(state, action.value); case UNSUBSCRIBE_FROM_CHANNEL_FAILURE: error = action.payload || {message: action.payload.message}; return processUnsubscribeFromChannelFailure(state, error); -- GitLab From 0a8d9fe787f5bd591bb66e9307fc1119968afca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Semedo?= <jose.semedo@cern.ch> Date: Thu, 28 Apr 2022 11:44:37 +0200 Subject: [PATCH 3/5] Moving actions to one single file. --- ...bscribeFromChannel.js => noContentActionsUpdate.js} | 10 ++++++++++ .../actions/updates/UpdateSubscribeToChannel.js | 9 --------- src/channels/components/ChannelsList/ChannelsList.js | 6 ++---- src/channels/reducers/ChannelsList.js | 7 +++++-- 4 files changed, 17 insertions(+), 15 deletions(-) rename src/channels/actions/{updates/UpdateUnsubscribeFromChannel.js => noContentActionsUpdate.js} (51%) delete mode 100644 src/channels/actions/updates/UpdateSubscribeToChannel.js diff --git a/src/channels/actions/updates/UpdateUnsubscribeFromChannel.js b/src/channels/actions/noContentActionsUpdate.js similarity index 51% rename from src/channels/actions/updates/UpdateUnsubscribeFromChannel.js rename to src/channels/actions/noContentActionsUpdate.js index 5cc07886..489204e8 100644 --- a/src/channels/actions/updates/UpdateUnsubscribeFromChannel.js +++ b/src/channels/actions/noContentActionsUpdate.js @@ -1,3 +1,13 @@ +// Triggered after subscribing to a channel, to update the state +export const SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS = 'SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS'; + +export const updateSubscribeToChannel = channelId => { + return { + value: channelId, + type: SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, + }; +}; + // Triggered after unsubscribing from a channel, to update the state export const UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS = 'UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS'; diff --git a/src/channels/actions/updates/UpdateSubscribeToChannel.js b/src/channels/actions/updates/UpdateSubscribeToChannel.js deleted file mode 100644 index 0f306dda..00000000 --- a/src/channels/actions/updates/UpdateSubscribeToChannel.js +++ /dev/null @@ -1,9 +0,0 @@ -// Triggered after subscribing to a channel, to update the state -export const SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS = 'SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS'; - -export const updateSubscribeToChannel = channelId => { - return { - value: channelId, - type: SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, - }; -}; diff --git a/src/channels/components/ChannelsList/ChannelsList.js b/src/channels/components/ChannelsList/ChannelsList.js index d023f8c2..5802cfeb 100644 --- a/src/channels/components/ChannelsList/ChannelsList.js +++ b/src/channels/components/ChannelsList/ChannelsList.js @@ -18,9 +18,8 @@ import {bindActionCreators} from 'redux'; import * as showSnackBarActionCreator from 'common/actions/Snackbar'; import * as updateChannelActionCreators from 'channels/actions/UpdateChannel'; import * as subscribeToChannelActionCreators from 'channels/actions/SubscribeToChannel'; -import * as updateSubscribeToChannelActionCreators from 'channels/actions/updates/UpdateSubscribeToChannel'; +import * as noContentActionCreators from 'channels/actions/noContentActionsUpdate'; import * as unsubscribeFromChannelActionCreators from 'channels/actions/UnsubscribeFromChannel'; -import * as updateUnsubscribeFromChannelActionCreators from 'channels/actions/updates/UpdateUnsubscribeFromChannel'; import * as paginationActioncreators from 'channels/actions/PaginationActions'; import * as getChannelsActionCreators from 'channels/actions/GetChannels'; import * as toggleFavoriteChannelActionCreators from 'channels/actions/ToggleFavoriteChannel'; @@ -506,9 +505,8 @@ const mapDispatchToProps = dispatch => { ...bindActionCreators(getChannelsActionCreators, dispatch), ...bindActionCreators(updateChannelActionCreators, dispatch), ...bindActionCreators(subscribeToChannelActionCreators, dispatch), - ...bindActionCreators(updateSubscribeToChannelActionCreators, dispatch), + ...bindActionCreators(noContentActionCreators, dispatch), ...bindActionCreators(unsubscribeFromChannelActionCreators, dispatch), - ...bindActionCreators(updateUnsubscribeFromChannelActionCreators, dispatch), ...bindActionCreators(paginationActioncreators, dispatch), ...bindActionCreators(getPublicChannelsActionCreators, dispatch), ...bindActionCreators(showSnackBarActionCreator, dispatch), diff --git a/src/channels/reducers/ChannelsList.js b/src/channels/reducers/ChannelsList.js index 08b3034f..b732fd17 100644 --- a/src/channels/reducers/ChannelsList.js +++ b/src/channels/reducers/ChannelsList.js @@ -10,13 +10,16 @@ import { SUBSCRIBE_TO_CHANNEL_FAILURE, SUBSCRIBE_TO_CHANNEL_SUCCESS, } from 'channels/actions/SubscribeToChannel'; -import {SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS} from 'channels/actions/updates/UpdateSubscribeToChannel'; +import { + SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, + UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS, +} from 'channels/actions/noContentActionsUpdate'; import { UNSUBSCRIBE_FROM_CHANNEL, UNSUBSCRIBE_FROM_CHANNEL_FAILURE, UNSUBSCRIBE_FROM_CHANNEL_SUCCESS, } from 'channels/actions/UnsubscribeFromChannel'; -import {UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS} from 'channels/actions/updates/UpdateUnsubscribeFromChannel'; + import { SET_ELEMENTS_PER_PAGE, SET_ACTIVE_PAGE, -- GitLab From 0b84ff32185a0aa3767698c04a70950ddbe9df85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Semedo?= <jose.semedo@cern.ch> Date: Thu, 28 Apr 2022 14:50:48 +0200 Subject: [PATCH 4/5] Using same actino and passing boolean. --- .../actions/NoContentActionsUpdate.js | 10 +++++++++ .../actions/noContentActionsUpdate.js | 19 ----------------- .../components/ChannelsList/ChannelsList.js | 7 +++---- src/channels/reducers/ChannelsList.js | 21 ++++--------------- 4 files changed, 17 insertions(+), 40 deletions(-) create mode 100644 src/channels/actions/NoContentActionsUpdate.js delete mode 100644 src/channels/actions/noContentActionsUpdate.js diff --git a/src/channels/actions/NoContentActionsUpdate.js b/src/channels/actions/NoContentActionsUpdate.js new file mode 100644 index 00000000..33127e09 --- /dev/null +++ b/src/channels/actions/NoContentActionsUpdate.js @@ -0,0 +1,10 @@ +// Triggered after subscribing to a channel, to update the state +export const SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS = 'SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS'; + +export const updateSubscribeToChannel = (channelId, newValue) => { + return { + channelId, + newValue, + type: SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, + }; +}; diff --git a/src/channels/actions/noContentActionsUpdate.js b/src/channels/actions/noContentActionsUpdate.js deleted file mode 100644 index 489204e8..00000000 --- a/src/channels/actions/noContentActionsUpdate.js +++ /dev/null @@ -1,19 +0,0 @@ -// Triggered after subscribing to a channel, to update the state -export const SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS = 'SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS'; - -export const updateSubscribeToChannel = channelId => { - return { - value: channelId, - type: SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, - }; -}; - -// Triggered after unsubscribing from a channel, to update the state -export const UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS = 'UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS'; - -export const updateUnsubscribeFromChannel = channelId => { - return { - value: channelId, - type: UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS, - }; -}; diff --git a/src/channels/components/ChannelsList/ChannelsList.js b/src/channels/components/ChannelsList/ChannelsList.js index 5802cfeb..00d85950 100644 --- a/src/channels/components/ChannelsList/ChannelsList.js +++ b/src/channels/components/ChannelsList/ChannelsList.js @@ -18,7 +18,7 @@ import {bindActionCreators} from 'redux'; import * as showSnackBarActionCreator from 'common/actions/Snackbar'; import * as updateChannelActionCreators from 'channels/actions/UpdateChannel'; import * as subscribeToChannelActionCreators from 'channels/actions/SubscribeToChannel'; -import * as noContentActionCreators from 'channels/actions/noContentActionsUpdate'; +import * as noContentActionCreators from 'channels/actions/NoContentActionsUpdate'; import * as unsubscribeFromChannelActionCreators from 'channels/actions/UnsubscribeFromChannel'; import * as paginationActioncreators from 'channels/actions/PaginationActions'; import * as getChannelsActionCreators from 'channels/actions/GetChannels'; @@ -40,7 +40,6 @@ const ChannelsList = ({ subscribeToChannel, updateSubscribeToChannel, unsubscribeFromChannel, - updateUnsubscribeFromChannel, toggleFavoriteChannel, getChannelsQuery, setGetChannelsQuery, @@ -95,7 +94,7 @@ const ChannelsList = ({ 'error' ); } else { - updateUnsubscribeFromChannel(channel.id); + updateSubscribeToChannel(channel.id, false); setUnsubscribeId(null); showSnackbar(`Unsubscribed from channel ${channel.name} successfully`, 'success'); } @@ -111,7 +110,7 @@ const ChannelsList = ({ 'error' ); } else { - updateSubscribeToChannel(channel.id); + updateSubscribeToChannel(channel.id, true); setSubscribeId(null); showSnackbar(`Subscribed channel ${channel.name} successfully`, 'success'); } diff --git a/src/channels/reducers/ChannelsList.js b/src/channels/reducers/ChannelsList.js index b732fd17..63ef654a 100644 --- a/src/channels/reducers/ChannelsList.js +++ b/src/channels/reducers/ChannelsList.js @@ -10,10 +10,7 @@ import { SUBSCRIBE_TO_CHANNEL_FAILURE, SUBSCRIBE_TO_CHANNEL_SUCCESS, } from 'channels/actions/SubscribeToChannel'; -import { - SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, - UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS, -} from 'channels/actions/noContentActionsUpdate'; +import {SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS} from 'channels/actions/NoContentActionsUpdate'; import { UNSUBSCRIBE_FROM_CHANNEL, UNSUBSCRIBE_FROM_CHANNEL_FAILURE, @@ -105,11 +102,11 @@ function processSubscribeToChannelSuccess(state) { return state; } -function processUpdateSubscribeToChannel(state, value) { +function processUpdateSubscribeToChannel(state, channelId, newValue) { return { ...state, loadingSubscribe: false, - channels: state.channels.map(c => (c.id === value ? {...c, subscribed: true} : c)), + channels: state.channels.map(c => (c.id === channelId ? {...c, subscribed: newValue} : c)), }; } @@ -132,14 +129,6 @@ function processUnsubscribeFromChannelSuccess(state) { return state; } -function processUpdateUnsubscribeFromChannelSuccess(state, value) { - return { - ...state, - loadingUnsubscribe: false, - channels: state.channels.map(c => (c.id === value ? {...c, subscribed: false} : c)), - }; -} - function processUnsubscribeFromChannelFailure(state, error) { return { ...state, @@ -264,7 +253,7 @@ export default function (state = INITIAL_STATE, action) { case SUBSCRIBE_TO_CHANNEL_SUCCESS: return processSubscribeToChannelSuccess(state, action.payload); case SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS: - return processUpdateSubscribeToChannel(state, action.value); + return processUpdateSubscribeToChannel(state, action.channelId, action.newValue); case SUBSCRIBE_TO_CHANNEL_FAILURE: error = action.payload || {message: action.payload.message}; return processSubscribeToChannelFailure(state, error); @@ -273,8 +262,6 @@ export default function (state = INITIAL_STATE, action) { return processUnsubscribeFromChannel(state); case UNSUBSCRIBE_FROM_CHANNEL_SUCCESS: return processUnsubscribeFromChannelSuccess(state, action.payload); - case UNSUBSCRIBE_FROM_CHANNEL_UPDATE_SUCCESS: - return processUpdateUnsubscribeFromChannelSuccess(state, action.value); case UNSUBSCRIBE_FROM_CHANNEL_FAILURE: error = action.payload || {message: action.payload.message}; return processUnsubscribeFromChannelFailure(state, error); -- GitLab From 555724ceaf15b41271064f1de59eb72687f38da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Semedo?= <jose.semedo@cern.ch> Date: Thu, 28 Apr 2022 17:12:32 +0200 Subject: [PATCH 5/5] Changing reducer argument into data. --- src/channels/actions/NoContentActionsUpdate.js | 6 ++++-- src/channels/reducers/ChannelsList.js | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/channels/actions/NoContentActionsUpdate.js b/src/channels/actions/NoContentActionsUpdate.js index 33127e09..63ef0688 100644 --- a/src/channels/actions/NoContentActionsUpdate.js +++ b/src/channels/actions/NoContentActionsUpdate.js @@ -3,8 +3,10 @@ export const SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS = 'SUBSCRIBE_TO_CHANNEL_UPDATE_ export const updateSubscribeToChannel = (channelId, newValue) => { return { - channelId, - newValue, + data: { + channelId, + newValue, + }, type: SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS, }; }; diff --git a/src/channels/reducers/ChannelsList.js b/src/channels/reducers/ChannelsList.js index 63ef654a..36ea75ff 100644 --- a/src/channels/reducers/ChannelsList.js +++ b/src/channels/reducers/ChannelsList.js @@ -102,11 +102,13 @@ function processSubscribeToChannelSuccess(state) { return state; } -function processUpdateSubscribeToChannel(state, channelId, newValue) { +function processUpdateSubscribeToChannel(state, data) { return { ...state, loadingSubscribe: false, - channels: state.channels.map(c => (c.id === channelId ? {...c, subscribed: newValue} : c)), + channels: state.channels.map(c => + c.id === data.channelId ? {...c, subscribed: data.newValue} : c + ), }; } @@ -253,7 +255,7 @@ export default function (state = INITIAL_STATE, action) { case SUBSCRIBE_TO_CHANNEL_SUCCESS: return processSubscribeToChannelSuccess(state, action.payload); case SUBSCRIBE_TO_CHANNEL_UPDATE_SUCCESS: - return processUpdateSubscribeToChannel(state, action.channelId, action.newValue); + return processUpdateSubscribeToChannel(state, action.data); case SUBSCRIBE_TO_CHANNEL_FAILURE: error = action.payload || {message: action.payload.message}; return processSubscribeToChannelFailure(state, error); -- GitLab