@selfcommunity/react-ui 0.8.0-alpha.0 → 0.8.0-alpha.2

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.
@@ -20,6 +20,8 @@ const Event_1 = tslib_1.__importStar(require("../Event"));
20
20
  const Skeleton_1 = tslib_1.__importDefault(require("../Events/Skeleton"));
21
21
  const constants_1 = require("./constants");
22
22
  const PastEventsFilter_1 = tslib_1.__importDefault(require("./PastEventsFilter"));
23
+ const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
24
+ const PubSub_1 = require("../../constants/PubSub");
23
25
  const classes = {
24
26
  root: `${constants_1.PREFIX}-root`,
25
27
  filters: `${constants_1.PREFIX}-filters`,
@@ -101,6 +103,8 @@ function Events(inProps) {
101
103
  const authUserId = scUserContext.user ? scUserContext.user.id : null;
102
104
  const theme = (0, material_1.useTheme)();
103
105
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
106
+ // REFS
107
+ const updatesSubscription = (0, react_1.useRef)(null);
104
108
  // HANDLERS
105
109
  const handleChipClick = () => {
106
110
  setShowFollowed(!showFollowed);
@@ -146,6 +150,28 @@ function Events(inProps) {
146
150
  query === '' && fetchEvents();
147
151
  }
148
152
  }, [contentAvailability, dateSearch, showFollowed, showPastEvents, showMyEvents, query]);
153
+ /**
154
+ * Subscriber for pubsub callback
155
+ */
156
+ const onDeleteEventHandler = (0, react_1.useCallback)((_msg, deleted) => {
157
+ setEvents((prev) => {
158
+ if (prev.some((e) => e.id === deleted)) {
159
+ return prev.filter((e) => e.id !== deleted);
160
+ }
161
+ return prev;
162
+ });
163
+ }, [events]);
164
+ /**
165
+ * On mount, subscribe to receive event updates (only delete)
166
+ */
167
+ (0, react_1.useEffect)(() => {
168
+ if (events) {
169
+ updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.EVENT}.${PubSub_1.SCGroupEventType.DELETE}`, onDeleteEventHandler);
170
+ }
171
+ return () => {
172
+ updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
173
+ };
174
+ }, [events]);
149
175
  const handleNext = (0, react_1.useMemo)(() => () => {
150
176
  if (!next) {
151
177
  return;
@@ -20,6 +20,8 @@ const Event_1 = tslib_1.__importDefault(require("../Event"));
20
20
  const Widget_1 = tslib_1.__importDefault(require("../Widget"));
21
21
  const constants_1 = require("./constants");
22
22
  const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
23
+ const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
24
+ const PubSub_1 = require("../../constants/PubSub");
23
25
  const classes = {
24
26
  root: `${constants_1.PREFIX}-root`,
25
27
  titleWrapper: `${constants_1.PREFIX}-title-wrapper`,
@@ -66,6 +68,8 @@ function MyEventsWidget(inProps) {
66
68
  const scRoutingContext = (0, react_core_1.useSCRouting)();
67
69
  const { features } = (0, react_core_1.useSCPreferences)();
68
70
  const eventsEnabled = (0, react_1.useMemo)(() => features && features.includes(types_1.SCFeatureName.EVENT) && features.includes(types_1.SCFeatureName.TAGGING), [features]);
71
+ // REFS
72
+ const updatesSubscription = (0, react_1.useRef)(null);
69
73
  /**
70
74
  * Initialize component
71
75
  * Fetch data only if the component is not initialized and it is not loading data
@@ -120,6 +124,30 @@ function MyEventsWidget(inProps) {
120
124
  _fetchNext();
121
125
  }
122
126
  }, [eventIndex, state.results]);
127
+ /**
128
+ * Subscriber for pubsub callback
129
+ */
130
+ const onDeleteEventHandler = (0, react_1.useCallback)((_msg, deleted) => {
131
+ const _events = [...state.results];
132
+ if (_events.some((e) => e.id === deleted)) {
133
+ const updatedEvents = _events.filter((e) => e.id !== deleted);
134
+ dispatch({
135
+ type: widget_1.actionWidgetTypes.SET_RESULTS,
136
+ payload: { results: updatedEvents }
137
+ });
138
+ }
139
+ }, [state.results]);
140
+ /**
141
+ * On mount, subscribe to receive event updates (only delete)
142
+ */
143
+ (0, react_1.useEffect)(() => {
144
+ if (state.results) {
145
+ updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.EVENT}.${PubSub_1.SCGroupEventType.DELETE}`, onDeleteEventHandler);
146
+ }
147
+ return () => {
148
+ updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
149
+ };
150
+ }, [state.results]);
123
151
  // RENDER
124
152
  if (!eventsEnabled || (state.initialized && state.count === 0)) {
125
153
  return (0, jsx_runtime_1.jsx)(HiddenPlaceholder_1.default, {});
@@ -20,6 +20,8 @@ const Widget_1 = tslib_1.__importDefault(require("../Widget"));
20
20
  const Arrow_1 = tslib_1.__importDefault(require("./Arrow"));
21
21
  const constants_1 = require("./constants");
22
22
  const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
23
+ const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
24
+ const PubSub_1 = require("../../constants/PubSub");
23
25
  const classes = {
24
26
  root: `${constants_1.PREFIX}-root`,
25
27
  content: `${constants_1.PREFIX}-content`,
@@ -58,6 +60,8 @@ function SuggestedEventsWidget(inProps) {
58
60
  const scRoutingContext = (0, react_core_1.useSCRouting)();
59
61
  //HOOKS
60
62
  const theme = (0, material_1.useTheme)();
63
+ // REFS
64
+ const updatesSubscription = (0, react_1.useRef)(null);
61
65
  (0, react_1.useEffect)(() => {
62
66
  api_services_1.SuggestionService.getEventSuggestion(Object.assign({}, endpointQueryParams))
63
67
  .then((payload) => {
@@ -106,6 +110,28 @@ function SuggestedEventsWidget(inProps) {
106
110
  }
107
111
  }
108
112
  }, [count, hideMarginLeft, hideMarginRight]);
113
+ /**
114
+ * Subscriber for pubsub callback
115
+ */
116
+ const onDeleteEventHandler = (0, react_1.useCallback)((_msg, deleted) => {
117
+ setEvents((prev) => {
118
+ if (prev.some((e) => e.id === deleted)) {
119
+ return prev.filter((e) => e.id !== deleted);
120
+ }
121
+ return prev;
122
+ });
123
+ }, [events]);
124
+ /**
125
+ * On mount, subscribe to receive event updates (only delete)
126
+ */
127
+ (0, react_1.useEffect)(() => {
128
+ if (events) {
129
+ updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.EVENT}.${PubSub_1.SCGroupEventType.DELETE}`, onDeleteEventHandler);
130
+ }
131
+ return () => {
132
+ updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
133
+ };
134
+ }, [events]);
109
135
  // RENDER
110
136
  if (!events && loading) {
111
137
  return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
@@ -12,6 +12,7 @@ export declare enum SCTopicType {
12
12
  export declare enum SCGroupEventType {
13
13
  CREATE = "create",
14
14
  EDIT = "edit",
15
+ DELETE = "delete",
15
16
  MEMBERS = "members",
16
17
  ADD_MEMBER = "members.add_member",
17
18
  INVITE_MEMBER = "members.invite_member",
@@ -16,6 +16,7 @@ var SCGroupEventType;
16
16
  (function (SCGroupEventType) {
17
17
  SCGroupEventType["CREATE"] = "create";
18
18
  SCGroupEventType["EDIT"] = "edit";
19
+ SCGroupEventType["DELETE"] = "delete";
19
20
  SCGroupEventType["MEMBERS"] = "members";
20
21
  SCGroupEventType["ADD_MEMBER"] = "members.add_member";
21
22
  SCGroupEventType["INVITE_MEMBER"] = "members.invite_member";
@@ -15,6 +15,8 @@ const api_services_1 = require("@selfcommunity/api-services");
15
15
  const EventActionsMenu_1 = require("../../constants/EventActionsMenu");
16
16
  const utils_1 = require("@selfcommunity/utils");
17
17
  const notistack_1 = require("notistack");
18
+ const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
19
+ const PubSub_1 = require("../../constants/PubSub");
18
20
  const PREFIX = 'SCEventActionsMenu';
19
21
  const classes = {
20
22
  root: `${PREFIX}-root`,
@@ -105,6 +107,7 @@ function EventActionsMenu(inProps) {
105
107
  .then(() => {
106
108
  onDeleteConfirm();
107
109
  handleCloseDialog();
110
+ pubsub_js_1.default.publish(`${PubSub_1.SCTopicType.EVENT}.${PubSub_1.SCGroupEventType.DELETE}`, scEvent.id);
108
111
  })
109
112
  .catch((error) => {
110
113
  setOpenConfirmDialog(false);
@@ -8,7 +8,7 @@ import { SCPreferences, SCPreferencesContext, SCUserContext, UserUtils } from '@
8
8
  import { SCEventDateFilterType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
9
9
  import { Logger } from '@selfcommunity/utils';
10
10
  import classNames from 'classnames';
11
- import { useContext, useEffect, useMemo, useState } from 'react';
11
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
12
12
  import { FormattedMessage } from 'react-intl';
13
13
  import { SCOPE_SC_UI } from '../../constants/Errors';
14
14
  import { DEFAULT_PAGINATION_OFFSET } from '../../constants/Pagination';
@@ -17,6 +17,8 @@ import Event, { EventSkeleton } from '../Event';
17
17
  import Skeleton from '../Events/Skeleton';
18
18
  import { PREFIX } from './constants';
19
19
  import PastEventsFilter from './PastEventsFilter';
20
+ import PubSub from 'pubsub-js';
21
+ import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
20
22
  const classes = {
21
23
  root: `${PREFIX}-root`,
22
24
  filters: `${PREFIX}-filters`,
@@ -98,6 +100,8 @@ export default function Events(inProps) {
98
100
  const authUserId = scUserContext.user ? scUserContext.user.id : null;
99
101
  const theme = useTheme();
100
102
  const isMobile = useMediaQuery(theme.breakpoints.down('md'));
103
+ // REFS
104
+ const updatesSubscription = useRef(null);
101
105
  // HANDLERS
102
106
  const handleChipClick = () => {
103
107
  setShowFollowed(!showFollowed);
@@ -143,6 +147,28 @@ export default function Events(inProps) {
143
147
  query === '' && fetchEvents();
144
148
  }
145
149
  }, [contentAvailability, dateSearch, showFollowed, showPastEvents, showMyEvents, query]);
150
+ /**
151
+ * Subscriber for pubsub callback
152
+ */
153
+ const onDeleteEventHandler = useCallback((_msg, deleted) => {
154
+ setEvents((prev) => {
155
+ if (prev.some((e) => e.id === deleted)) {
156
+ return prev.filter((e) => e.id !== deleted);
157
+ }
158
+ return prev;
159
+ });
160
+ }, [events]);
161
+ /**
162
+ * On mount, subscribe to receive event updates (only delete)
163
+ */
164
+ useEffect(() => {
165
+ if (events) {
166
+ updatesSubscription.current = PubSub.subscribe(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, onDeleteEventHandler);
167
+ }
168
+ return () => {
169
+ updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
170
+ };
171
+ }, [events]);
146
172
  const handleNext = useMemo(() => () => {
147
173
  if (!next) {
148
174
  return;
@@ -7,7 +7,7 @@ import { Endpoints, EventService, http } from '@selfcommunity/api-services';
7
7
  import { SCCache, SCRoutes, useSCPreferences, useSCRouting, useSCUser } from '@selfcommunity/react-core';
8
8
  import { SCEventSubscriptionStatusType, SCFeatureName } from '@selfcommunity/types';
9
9
  import { Logger } from '@selfcommunity/utils';
10
- import { useCallback, useEffect, useMemo, useReducer, useState } from 'react';
10
+ import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
11
11
  import { FormattedMessage } from 'react-intl';
12
12
  import { SCOPE_SC_UI } from '../../constants/Errors';
13
13
  import { DEFAULT_PAGINATION_LIMIT, DEFAULT_PAGINATION_OFFSET } from '../../constants/Pagination';
@@ -18,6 +18,8 @@ import Event from '../Event';
18
18
  import Widget from '../Widget';
19
19
  import { PREFIX } from './constants';
20
20
  import Skeleton from './Skeleton';
21
+ import PubSub from 'pubsub-js';
22
+ import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
21
23
  const classes = {
22
24
  root: `${PREFIX}-root`,
23
25
  titleWrapper: `${PREFIX}-title-wrapper`,
@@ -64,6 +66,8 @@ export default function MyEventsWidget(inProps) {
64
66
  const scRoutingContext = useSCRouting();
65
67
  const { features } = useSCPreferences();
66
68
  const eventsEnabled = useMemo(() => features && features.includes(SCFeatureName.EVENT) && features.includes(SCFeatureName.TAGGING), [features]);
69
+ // REFS
70
+ const updatesSubscription = useRef(null);
67
71
  /**
68
72
  * Initialize component
69
73
  * Fetch data only if the component is not initialized and it is not loading data
@@ -118,6 +122,30 @@ export default function MyEventsWidget(inProps) {
118
122
  _fetchNext();
119
123
  }
120
124
  }, [eventIndex, state.results]);
125
+ /**
126
+ * Subscriber for pubsub callback
127
+ */
128
+ const onDeleteEventHandler = useCallback((_msg, deleted) => {
129
+ const _events = [...state.results];
130
+ if (_events.some((e) => e.id === deleted)) {
131
+ const updatedEvents = _events.filter((e) => e.id !== deleted);
132
+ dispatch({
133
+ type: actionWidgetTypes.SET_RESULTS,
134
+ payload: { results: updatedEvents }
135
+ });
136
+ }
137
+ }, [state.results]);
138
+ /**
139
+ * On mount, subscribe to receive event updates (only delete)
140
+ */
141
+ useEffect(() => {
142
+ if (state.results) {
143
+ updatesSubscription.current = PubSub.subscribe(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, onDeleteEventHandler);
144
+ }
145
+ return () => {
146
+ updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
147
+ };
148
+ }, [state.results]);
121
149
  // RENDER
122
150
  if (!eventsEnabled || (state.initialized && state.count === 0)) {
123
151
  return _jsx(HiddenPlaceholder, {});
@@ -6,7 +6,7 @@ import { Endpoints, http, SuggestionService } from '@selfcommunity/api-services'
6
6
  import { Link, SCRoutes, useSCRouting } from '@selfcommunity/react-core';
7
7
  import { Logger } from '@selfcommunity/utils';
8
8
  import classNames from 'classnames';
9
- import { useCallback, useEffect, useState } from 'react';
9
+ import { useCallback, useEffect, useRef, useState } from 'react';
10
10
  import { FormattedMessage } from 'react-intl';
11
11
  import { Swiper, SwiperSlide } from 'swiper/react';
12
12
  import { SCOPE_SC_UI } from '../../constants/Errors';
@@ -18,6 +18,8 @@ import Widget from '../Widget';
18
18
  import Arrow from './Arrow';
19
19
  import { PREFIX } from './constants';
20
20
  import Skeleton from './Skeleton';
21
+ import PubSub from 'pubsub-js';
22
+ import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
21
23
  const classes = {
22
24
  root: `${PREFIX}-root`,
23
25
  content: `${PREFIX}-content`,
@@ -56,6 +58,8 @@ export default function SuggestedEventsWidget(inProps) {
56
58
  const scRoutingContext = useSCRouting();
57
59
  //HOOKS
58
60
  const theme = useTheme();
61
+ // REFS
62
+ const updatesSubscription = useRef(null);
59
63
  useEffect(() => {
60
64
  SuggestionService.getEventSuggestion(Object.assign({}, endpointQueryParams))
61
65
  .then((payload) => {
@@ -104,6 +108,28 @@ export default function SuggestedEventsWidget(inProps) {
104
108
  }
105
109
  }
106
110
  }, [count, hideMarginLeft, hideMarginRight]);
111
+ /**
112
+ * Subscriber for pubsub callback
113
+ */
114
+ const onDeleteEventHandler = useCallback((_msg, deleted) => {
115
+ setEvents((prev) => {
116
+ if (prev.some((e) => e.id === deleted)) {
117
+ return prev.filter((e) => e.id !== deleted);
118
+ }
119
+ return prev;
120
+ });
121
+ }, [events]);
122
+ /**
123
+ * On mount, subscribe to receive event updates (only delete)
124
+ */
125
+ useEffect(() => {
126
+ if (events) {
127
+ updatesSubscription.current = PubSub.subscribe(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, onDeleteEventHandler);
128
+ }
129
+ return () => {
130
+ updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
131
+ };
132
+ }, [events]);
107
133
  // RENDER
108
134
  if (!events && loading) {
109
135
  return _jsx(Skeleton, {});
@@ -12,6 +12,7 @@ export declare enum SCTopicType {
12
12
  export declare enum SCGroupEventType {
13
13
  CREATE = "create",
14
14
  EDIT = "edit",
15
+ DELETE = "delete",
15
16
  MEMBERS = "members",
16
17
  ADD_MEMBER = "members.add_member",
17
18
  INVITE_MEMBER = "members.invite_member",
@@ -13,6 +13,7 @@ export var SCGroupEventType;
13
13
  (function (SCGroupEventType) {
14
14
  SCGroupEventType["CREATE"] = "create";
15
15
  SCGroupEventType["EDIT"] = "edit";
16
+ SCGroupEventType["DELETE"] = "delete";
16
17
  SCGroupEventType["MEMBERS"] = "members";
17
18
  SCGroupEventType["ADD_MEMBER"] = "members.add_member";
18
19
  SCGroupEventType["INVITE_MEMBER"] = "members.invite_member";
@@ -13,6 +13,8 @@ import { EventService } from '@selfcommunity/api-services';
13
13
  import { ADD_EVENT_TO_CALENDAR, CANCEL_EVENT, GET_EVENT_LINK } from '../../constants/EventActionsMenu';
14
14
  import { copyTextToClipboard } from '@selfcommunity/utils';
15
15
  import { enqueueSnackbar } from 'notistack';
16
+ import PubSub from 'pubsub-js';
17
+ import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
16
18
  const PREFIX = 'SCEventActionsMenu';
17
19
  const classes = {
18
20
  root: `${PREFIX}-root`,
@@ -103,6 +105,7 @@ export default function EventActionsMenu(inProps) {
103
105
  .then(() => {
104
106
  onDeleteConfirm();
105
107
  handleCloseDialog();
108
+ PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, scEvent.id);
106
109
  })
107
110
  .catch((error) => {
108
111
  setOpenConfirmDialog(false);