@selfcommunity/react-ui 0.7.9-alpha.10 → 0.7.9-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -173,13 +173,14 @@ function GroupRequestsWidget(inProps) {
173
173
  };
174
174
  const handleSubscribeAction = (0, react_1.useMemo)(() => (userId) => {
175
175
  const newRequests = [...state.results];
176
- const index = newRequests.findIndex((u) => u.id === userId);
177
- if (index !== -1) {
178
- dispatch({ type: widget_1.actionWidgetTypes.SET_RESULTS, payload: { results: newRequests } });
179
- }
176
+ const _updated = newRequests.findIndex((u) => u.id !== userId);
177
+ dispatch({
178
+ type: widget_1.actionWidgetTypes.SET_RESULTS,
179
+ payload: { results: newRequests.length > 1 ? _updated : [] }
180
+ });
180
181
  }, [dispatch, state.count, state.results]);
181
182
  // RENDER
182
- if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count) {
183
+ if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count || !state.results.length) {
183
184
  return react_1.default.createElement(HiddenPlaceholder_1.default, null);
184
185
  }
185
186
  if (!state.initialized) {
@@ -113,6 +113,11 @@ function Groups(inProps) {
113
113
  });
114
114
  }
115
115
  }, [contentAvailability, authUserId, prefetchedGroups.length]);
116
+ const handleSubscribe = (group) => {
117
+ const newGroups = [...groups];
118
+ const _updated = newGroups.filter((g) => g.id !== group.id);
119
+ setGroups(_updated);
120
+ };
116
121
  // RENDER
117
122
  if (!contentAvailability && !scUserContext.user) {
118
123
  return react_1.default.createElement(HiddenPlaceholder_1.default, null);
@@ -122,7 +127,7 @@ function Groups(inProps) {
122
127
  react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groups.noGroups.title", defaultMessage: "ui.groups.noGroups.title" })),
123
128
  react_1.default.createElement(material_1.Typography, { variant: "body1" },
124
129
  react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groups.noGroups.subtitle", defaultMessage: "ui.groups.noGroups.subtitle" })))) : (react_1.default.createElement(react_1.default.Fragment, null, groups.map((group) => (react_1.default.createElement(material_1.Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
125
- react_1.default.createElement(Group_1.default, Object.assign({ group: group, groupId: group.id }, GroupComponentProps)))))))))));
130
+ react_1.default.createElement(Group_1.default, Object.assign({ group: group, groupId: group.id, groupSubscribeButtonProps: { onSubscribe: handleSubscribe } }, GroupComponentProps)))))))))));
126
131
  return (react_1.default.createElement(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest), content));
127
132
  }
128
133
  exports.default = Groups;
@@ -171,13 +171,14 @@ export default function GroupRequestsWidget(inProps) {
171
171
  };
172
172
  const handleSubscribeAction = useMemo(() => (userId) => {
173
173
  const newRequests = [...state.results];
174
- const index = newRequests.findIndex((u) => u.id === userId);
175
- if (index !== -1) {
176
- dispatch({ type: actionWidgetTypes.SET_RESULTS, payload: { results: newRequests } });
177
- }
174
+ const _updated = newRequests.findIndex((u) => u.id !== userId);
175
+ dispatch({
176
+ type: actionWidgetTypes.SET_RESULTS,
177
+ payload: { results: newRequests.length > 1 ? _updated : [] }
178
+ });
178
179
  }, [dispatch, state.count, state.results]);
179
180
  // RENDER
180
- if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count) {
181
+ if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count || !state.results.length) {
181
182
  return React.createElement(HiddenPlaceholder, null);
182
183
  }
183
184
  if (!state.initialized) {
@@ -111,6 +111,11 @@ export default function Groups(inProps) {
111
111
  });
112
112
  }
113
113
  }, [contentAvailability, authUserId, prefetchedGroups.length]);
114
+ const handleSubscribe = (group) => {
115
+ const newGroups = [...groups];
116
+ const _updated = newGroups.filter((g) => g.id !== group.id);
117
+ setGroups(_updated);
118
+ };
114
119
  // RENDER
115
120
  if (!contentAvailability && !scUserContext.user) {
116
121
  return React.createElement(HiddenPlaceholder, null);
@@ -120,6 +125,6 @@ export default function Groups(inProps) {
120
125
  React.createElement(FormattedMessage, { id: "ui.groups.noGroups.title", defaultMessage: "ui.groups.noGroups.title" })),
121
126
  React.createElement(Typography, { variant: "body1" },
122
127
  React.createElement(FormattedMessage, { id: "ui.groups.noGroups.subtitle", defaultMessage: "ui.groups.noGroups.subtitle" })))) : (React.createElement(React.Fragment, null, groups.map((group) => (React.createElement(Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
123
- React.createElement(Group, Object.assign({ group: group, groupId: group.id }, GroupComponentProps)))))))))));
128
+ React.createElement(Group, Object.assign({ group: group, groupId: group.id, groupSubscribeButtonProps: { onSubscribe: handleSubscribe } }, GroupComponentProps)))))))))));
124
129
  return (React.createElement(Root, Object.assign({ className: classNames(classes.root, className) }, rest), content));
125
130
  }