@selfcommunity/react-ui 0.8.0-alpha.0 → 0.8.0-alpha.1
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.
- package/lib/cjs/components/Events/Events.js +21 -0
- package/lib/cjs/constants/PubSub.d.ts +1 -0
- package/lib/cjs/constants/PubSub.js +1 -0
- package/lib/cjs/shared/EventActionsMenu/index.js +3 -0
- package/lib/esm/components/Events/Events.js +22 -1
- package/lib/esm/constants/PubSub.d.ts +1 -0
- package/lib/esm/constants/PubSub.js +1 -0
- package/lib/esm/shared/EventActionsMenu/index.js +3 -0
- package/lib/umd/react-ui.js +1 -1
- package/package.json +2 -2
|
@@ -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,23 @@ 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) => prev.filter((e) => e.id !== deleted));
|
|
158
|
+
}, [events]);
|
|
159
|
+
/**
|
|
160
|
+
* On mount, subscribe to receive event updates (only delete)
|
|
161
|
+
*/
|
|
162
|
+
(0, react_1.useEffect)(() => {
|
|
163
|
+
if (events) {
|
|
164
|
+
updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.EVENT}.${PubSub_1.SCGroupEventType.DELETE}`, onDeleteEventHandler);
|
|
165
|
+
}
|
|
166
|
+
return () => {
|
|
167
|
+
updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
|
|
168
|
+
};
|
|
169
|
+
}, [events]);
|
|
149
170
|
const handleNext = (0, react_1.useMemo)(() => () => {
|
|
150
171
|
if (!next) {
|
|
151
172
|
return;
|
|
@@ -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,23 @@ 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) => prev.filter((e) => e.id !== deleted));
|
|
155
|
+
}, [events]);
|
|
156
|
+
/**
|
|
157
|
+
* On mount, subscribe to receive event updates (only delete)
|
|
158
|
+
*/
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (events) {
|
|
161
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.EVENT}.${SCGroupEventType.DELETE}`, onDeleteEventHandler);
|
|
162
|
+
}
|
|
163
|
+
return () => {
|
|
164
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
165
|
+
};
|
|
166
|
+
}, [events]);
|
|
146
167
|
const handleNext = useMemo(() => () => {
|
|
147
168
|
if (!next) {
|
|
148
169
|
return;
|
|
@@ -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);
|