@selfcommunity/react-ui 0.8.0 → 0.8.1-alpha.0
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/Categories/Categories.js +22 -0
- package/lib/cjs/components/CategoriesPopularWidget/CategoriesPopularWidget.js +21 -0
- package/lib/cjs/components/CategoriesSuggestionWidget/CategoriesSuggestionWidget.js +21 -0
- package/lib/cjs/components/OnBoardingWidget/OnBoardingWidget.js +25 -0
- package/lib/cjs/constants/PubSub.d.ts +8 -1
- package/lib/cjs/constants/PubSub.js +9 -1
- package/lib/esm/components/Categories/Categories.js +23 -1
- package/lib/esm/components/CategoriesPopularWidget/CategoriesPopularWidget.js +22 -1
- package/lib/esm/components/CategoriesSuggestionWidget/CategoriesSuggestionWidget.js +22 -1
- package/lib/esm/components/OnBoardingWidget/OnBoardingWidget.js +26 -1
- package/lib/esm/constants/PubSub.d.ts +8 -1
- package/lib/esm/constants/PubSub.js +8 -0
- package/lib/umd/react-ui.js +1 -1
- package/package.json +7 -7
|
@@ -16,6 +16,8 @@ const Errors_1 = require("../../constants/Errors");
|
|
|
16
16
|
const utils_1 = require("@selfcommunity/utils");
|
|
17
17
|
const HiddenPlaceholder_1 = tslib_1.__importDefault(require("../../shared/HiddenPlaceholder"));
|
|
18
18
|
const constants_1 = require("./constants");
|
|
19
|
+
const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
|
|
20
|
+
const PubSub_1 = require("../../constants/PubSub");
|
|
19
21
|
const classes = {
|
|
20
22
|
root: `${constants_1.PREFIX}-root`,
|
|
21
23
|
filters: `${constants_1.PREFIX}-filter`,
|
|
@@ -73,6 +75,7 @@ function Categories(inProps) {
|
|
|
73
75
|
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
74
76
|
// REFS
|
|
75
77
|
const isMountedRef = (0, react_core_1.useIsComponentMountedRef)();
|
|
78
|
+
const updatesSubscription = (0, react_1.useRef)(null);
|
|
76
79
|
/**
|
|
77
80
|
* Fetches categories list
|
|
78
81
|
*/
|
|
@@ -104,6 +107,25 @@ function Categories(inProps) {
|
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
}, [contentAvailability, authUserId, prefetchedCategories.length]);
|
|
110
|
+
/**
|
|
111
|
+
* Subscriber for pubsub callback
|
|
112
|
+
*/
|
|
113
|
+
const onEditCategoryHandler = (0, react_1.useCallback)((_msg, edited) => {
|
|
114
|
+
setCategories((prev) => {
|
|
115
|
+
return prev.map((c) => (c.id === edited.id ? Object.assign(Object.assign({}, c), edited) : c));
|
|
116
|
+
});
|
|
117
|
+
}, [categories]);
|
|
118
|
+
/**
|
|
119
|
+
* On mount, subscribe to receive event updates (only edit)
|
|
120
|
+
*/
|
|
121
|
+
(0, react_1.useEffect)(() => {
|
|
122
|
+
if (categories) {
|
|
123
|
+
updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.CATEGORY}.${PubSub_1.SCCategoryEventType.EDIT}`, onEditCategoryHandler);
|
|
124
|
+
}
|
|
125
|
+
return () => {
|
|
126
|
+
updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
|
|
127
|
+
};
|
|
128
|
+
}, [categories]);
|
|
107
129
|
/**
|
|
108
130
|
* Get categories filtered
|
|
109
131
|
*/
|
|
@@ -20,6 +20,8 @@ const HiddenPlaceholder_1 = tslib_1.__importDefault(require("../../shared/Hidden
|
|
|
20
20
|
const react_core_1 = require("@selfcommunity/react-core");
|
|
21
21
|
const widget_1 = require("../../utils/widget");
|
|
22
22
|
const constants_1 = require("./constants");
|
|
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
|
title: `${constants_1.PREFIX}-title`,
|
|
@@ -89,6 +91,8 @@ function CategoriesPopularWidget(inProps) {
|
|
|
89
91
|
// HOOKS
|
|
90
92
|
const theme = (0, material_1.useTheme)();
|
|
91
93
|
const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
|
|
94
|
+
// REFS
|
|
95
|
+
const updatesSubscription = (0, react_1.useRef)(null);
|
|
92
96
|
/**
|
|
93
97
|
* Initialize component
|
|
94
98
|
* Fetch data only if the component is not initialized and it is not loading data
|
|
@@ -106,6 +110,23 @@ function CategoriesPopularWidget(inProps) {
|
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
}, [state.isLoadingNext, state.initialized, limit, dispatch]);
|
|
113
|
+
/**
|
|
114
|
+
* Subscriber for pubsub callback
|
|
115
|
+
*/
|
|
116
|
+
const onEditCategoryHandler = (0, react_1.useCallback)((_msg, edited) => {
|
|
117
|
+
const _categories = [...state.results];
|
|
118
|
+
const updatedCategories = _categories.map((c) => (c.id === edited.id ? Object.assign(Object.assign({}, c), edited) : c));
|
|
119
|
+
dispatch({ type: widget_1.actionWidgetTypes.SET_RESULTS, payload: { results: updatedCategories } });
|
|
120
|
+
}, [dispatch]);
|
|
121
|
+
/**
|
|
122
|
+
* On mount, subscribe to receive event updates (only edit)
|
|
123
|
+
*/
|
|
124
|
+
(0, react_1.useEffect)(() => {
|
|
125
|
+
updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.CATEGORY}.${PubSub_1.SCCategoryEventType.EDIT}`, onEditCategoryHandler);
|
|
126
|
+
return () => {
|
|
127
|
+
updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
|
|
128
|
+
};
|
|
129
|
+
}, [onEditCategoryHandler]);
|
|
109
130
|
// EFFECTS
|
|
110
131
|
(0, react_1.useEffect)(() => {
|
|
111
132
|
var _a;
|
|
@@ -20,6 +20,8 @@ const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"))
|
|
|
20
20
|
const Errors_1 = require("../../constants/Errors");
|
|
21
21
|
const InfiniteScroll_1 = tslib_1.__importDefault(require("../../shared/InfiniteScroll"));
|
|
22
22
|
const constants_1 = require("./constants");
|
|
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
|
title: `${constants_1.PREFIX}-title`,
|
|
@@ -85,6 +87,8 @@ function CategoriesSuggestionWidget(inProps) {
|
|
|
85
87
|
// HOOKS
|
|
86
88
|
const theme = (0, material_1.useTheme)();
|
|
87
89
|
const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
|
|
90
|
+
// REFS
|
|
91
|
+
const updatesSubscription = (0, react_1.useRef)(null);
|
|
88
92
|
/**
|
|
89
93
|
* Initialize component
|
|
90
94
|
* Fetch data only if the component is not initialized and it is not loading data
|
|
@@ -102,6 +106,23 @@ function CategoriesSuggestionWidget(inProps) {
|
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
108
|
}, [state.isLoadingNext, state.initialized, limit, dispatch]);
|
|
109
|
+
/**
|
|
110
|
+
* Subscriber for pubsub callback
|
|
111
|
+
*/
|
|
112
|
+
const onEditCategoryHandler = (0, react_1.useCallback)((_msg, edited) => {
|
|
113
|
+
const _categories = [...state.results];
|
|
114
|
+
const updatedCategories = _categories.map((c) => (c.id === edited.id ? Object.assign(Object.assign({}, c), edited) : c));
|
|
115
|
+
dispatch({ type: widget_1.actionWidgetTypes.SET_RESULTS, payload: { results: updatedCategories } });
|
|
116
|
+
}, [dispatch]);
|
|
117
|
+
/**
|
|
118
|
+
* On mount, subscribe to receive event updates (only edit)
|
|
119
|
+
*/
|
|
120
|
+
(0, react_1.useEffect)(() => {
|
|
121
|
+
updatesSubscription.current = pubsub_js_1.default.subscribe(`${PubSub_1.SCTopicType.CATEGORY}.${PubSub_1.SCCategoryEventType.EDIT}`, onEditCategoryHandler);
|
|
122
|
+
return () => {
|
|
123
|
+
updatesSubscription.current && pubsub_js_1.default.unsubscribe(updatesSubscription.current);
|
|
124
|
+
};
|
|
125
|
+
}, [onEditCategoryHandler]);
|
|
105
126
|
// EFFECTS
|
|
106
127
|
(0, react_1.useEffect)(() => {
|
|
107
128
|
let _t;
|
|
@@ -26,6 +26,8 @@ const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
|
|
|
26
26
|
const notistack_1 = require("notistack");
|
|
27
27
|
const header_1 = tslib_1.__importDefault(require("../../assets/onBoarding/header"));
|
|
28
28
|
const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
|
|
29
|
+
const pubsub_js_1 = tslib_1.__importDefault(require("pubsub-js"));
|
|
30
|
+
const PubSub_1 = require("../../constants/PubSub");
|
|
29
31
|
const classes = {
|
|
30
32
|
root: `${constants_1.PREFIX}-root`,
|
|
31
33
|
content: `${constants_1.PREFIX}-content`,
|
|
@@ -191,6 +193,13 @@ const OnBoardingWidget = (inProps) => {
|
|
|
191
193
|
fetchPlatform('/contents/interests/');
|
|
192
194
|
setShowCategoriesModal(false);
|
|
193
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Notify when a category info changes
|
|
198
|
+
* @param data
|
|
199
|
+
*/
|
|
200
|
+
const notifyCategoryChanges = (0, react_1.useCallback)((data) => {
|
|
201
|
+
pubsub_js_1.default.publish(`${PubSub_1.SCTopicType.CATEGORY}.${PubSub_1.SCCategoryEventType.EDIT}`, data);
|
|
202
|
+
}, []);
|
|
194
203
|
// EFFECTS
|
|
195
204
|
(0, react_1.useEffect)(() => {
|
|
196
205
|
if (prevContentsStep &&
|
|
@@ -226,6 +235,22 @@ const OnBoardingWidget = (inProps) => {
|
|
|
226
235
|
return () => clearInterval(intervalId);
|
|
227
236
|
}
|
|
228
237
|
}, [scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user, isGenerating, isAdmin]);
|
|
238
|
+
/**
|
|
239
|
+
* updates categories info when generating category content
|
|
240
|
+
*/
|
|
241
|
+
(0, react_1.useEffect)(() => {
|
|
242
|
+
const categoryStep = steps.find((step) => step.step === types_1.SCOnBoardingStepType.CATEGORIES);
|
|
243
|
+
if ((categoryStep === null || categoryStep === void 0 ? void 0 : categoryStep.status) === types_1.SCOnBoardingStepStatusType.IN_PROGRESS && categoryStep.results.length !== 0) {
|
|
244
|
+
categoryStep.results.forEach((c) => {
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
246
|
+
// @ts-ignore
|
|
247
|
+
const isAlreadyNotified = prevCategoriesStep === null || prevCategoriesStep === void 0 ? void 0 : prevCategoriesStep.results.some((result) => result.id === c.id);
|
|
248
|
+
if (!isAlreadyNotified) {
|
|
249
|
+
notifyCategoryChanges(c);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}, [steps, prevCategoriesStep]);
|
|
229
254
|
/**
|
|
230
255
|
* Render _step content section
|
|
231
256
|
*/
|
|
@@ -4,7 +4,8 @@ import { SCUserType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare enum SCTopicType {
|
|
6
6
|
GROUP = "group",
|
|
7
|
-
EVENT = "event"
|
|
7
|
+
EVENT = "event",
|
|
8
|
+
CATEGORY = "category"
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Group/Event event types
|
|
@@ -18,6 +19,12 @@ export declare enum SCGroupEventType {
|
|
|
18
19
|
INVITE_MEMBER = "members.invite_member",
|
|
19
20
|
REMOVE_MEMBER = "members.remove_member"
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Category event types
|
|
24
|
+
*/
|
|
25
|
+
export declare enum SCCategoryEventType {
|
|
26
|
+
EDIT = "edit"
|
|
27
|
+
}
|
|
21
28
|
export interface SCGroupMembersEventType {
|
|
22
29
|
group: SCGroupType;
|
|
23
30
|
user?: SCUserType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SCGroupEventType = exports.SCTopicType = void 0;
|
|
3
|
+
exports.SCCategoryEventType = exports.SCGroupEventType = exports.SCTopicType = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Define topics for pubsub
|
|
6
6
|
*/
|
|
@@ -8,6 +8,7 @@ var SCTopicType;
|
|
|
8
8
|
(function (SCTopicType) {
|
|
9
9
|
SCTopicType["GROUP"] = "group";
|
|
10
10
|
SCTopicType["EVENT"] = "event";
|
|
11
|
+
SCTopicType["CATEGORY"] = "category";
|
|
11
12
|
})(SCTopicType = exports.SCTopicType || (exports.SCTopicType = {}));
|
|
12
13
|
/**
|
|
13
14
|
* Group/Event event types
|
|
@@ -22,3 +23,10 @@ var SCGroupEventType;
|
|
|
22
23
|
SCGroupEventType["INVITE_MEMBER"] = "members.invite_member";
|
|
23
24
|
SCGroupEventType["REMOVE_MEMBER"] = "members.remove_member";
|
|
24
25
|
})(SCGroupEventType = exports.SCGroupEventType || (exports.SCGroupEventType = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Category event types
|
|
28
|
+
*/
|
|
29
|
+
var SCCategoryEventType;
|
|
30
|
+
(function (SCCategoryEventType) {
|
|
31
|
+
SCCategoryEventType["EDIT"] = "edit";
|
|
32
|
+
})(SCCategoryEventType = exports.SCCategoryEventType || (exports.SCCategoryEventType = {}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import { Box, Grid, TextField, Typography } from '@mui/material';
|
|
6
6
|
import { CategoryService, Endpoints } from '@selfcommunity/api-services';
|
|
@@ -14,6 +14,8 @@ import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
|
14
14
|
import { Logger, sortByAttr } from '@selfcommunity/utils';
|
|
15
15
|
import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
|
|
16
16
|
import { PREFIX } from './constants';
|
|
17
|
+
import PubSub from 'pubsub-js';
|
|
18
|
+
import { SCCategoryEventType, SCTopicType } from '../../constants/PubSub';
|
|
17
19
|
const classes = {
|
|
18
20
|
root: `${PREFIX}-root`,
|
|
19
21
|
filters: `${PREFIX}-filter`,
|
|
@@ -71,6 +73,7 @@ export default function Categories(inProps) {
|
|
|
71
73
|
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
72
74
|
// REFS
|
|
73
75
|
const isMountedRef = useIsComponentMountedRef();
|
|
76
|
+
const updatesSubscription = useRef(null);
|
|
74
77
|
/**
|
|
75
78
|
* Fetches categories list
|
|
76
79
|
*/
|
|
@@ -102,6 +105,25 @@ export default function Categories(inProps) {
|
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
}, [contentAvailability, authUserId, prefetchedCategories.length]);
|
|
108
|
+
/**
|
|
109
|
+
* Subscriber for pubsub callback
|
|
110
|
+
*/
|
|
111
|
+
const onEditCategoryHandler = useCallback((_msg, edited) => {
|
|
112
|
+
setCategories((prev) => {
|
|
113
|
+
return prev.map((c) => (c.id === edited.id ? Object.assign(Object.assign({}, c), edited) : c));
|
|
114
|
+
});
|
|
115
|
+
}, [categories]);
|
|
116
|
+
/**
|
|
117
|
+
* On mount, subscribe to receive event updates (only edit)
|
|
118
|
+
*/
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (categories) {
|
|
121
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.CATEGORY}.${SCCategoryEventType.EDIT}`, onEditCategoryHandler);
|
|
122
|
+
}
|
|
123
|
+
return () => {
|
|
124
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
125
|
+
};
|
|
126
|
+
}, [categories]);
|
|
105
127
|
/**
|
|
106
128
|
* Get categories filtered
|
|
107
129
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useContext, useEffect, useMemo, useReducer, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import { Button, CardContent, List, ListItem, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
6
6
|
import { CategoryService, Endpoints, http } from '@selfcommunity/api-services';
|
|
@@ -18,6 +18,8 @@ import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
|
|
|
18
18
|
import { SCCache, SCPreferences, SCPreferencesContext, SCUserContext } from '@selfcommunity/react-core';
|
|
19
19
|
import { actionWidgetTypes, dataWidgetReducer, stateWidgetInitializer } from '../../utils/widget';
|
|
20
20
|
import { PREFIX } from './constants';
|
|
21
|
+
import PubSub from 'pubsub-js';
|
|
22
|
+
import { SCCategoryEventType, SCTopicType } from '../../constants/PubSub';
|
|
21
23
|
const classes = {
|
|
22
24
|
root: `${PREFIX}-root`,
|
|
23
25
|
title: `${PREFIX}-title`,
|
|
@@ -87,6 +89,8 @@ export default function CategoriesPopularWidget(inProps) {
|
|
|
87
89
|
// HOOKS
|
|
88
90
|
const theme = useTheme();
|
|
89
91
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
92
|
+
// REFS
|
|
93
|
+
const updatesSubscription = useRef(null);
|
|
90
94
|
/**
|
|
91
95
|
* Initialize component
|
|
92
96
|
* Fetch data only if the component is not initialized and it is not loading data
|
|
@@ -104,6 +108,23 @@ export default function CategoriesPopularWidget(inProps) {
|
|
|
104
108
|
});
|
|
105
109
|
}
|
|
106
110
|
}, [state.isLoadingNext, state.initialized, limit, dispatch]);
|
|
111
|
+
/**
|
|
112
|
+
* Subscriber for pubsub callback
|
|
113
|
+
*/
|
|
114
|
+
const onEditCategoryHandler = useCallback((_msg, edited) => {
|
|
115
|
+
const _categories = [...state.results];
|
|
116
|
+
const updatedCategories = _categories.map((c) => (c.id === edited.id ? Object.assign(Object.assign({}, c), edited) : c));
|
|
117
|
+
dispatch({ type: actionWidgetTypes.SET_RESULTS, payload: { results: updatedCategories } });
|
|
118
|
+
}, [dispatch]);
|
|
119
|
+
/**
|
|
120
|
+
* On mount, subscribe to receive event updates (only edit)
|
|
121
|
+
*/
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.CATEGORY}.${SCCategoryEventType.EDIT}`, onEditCategoryHandler);
|
|
124
|
+
return () => {
|
|
125
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
126
|
+
};
|
|
127
|
+
}, [onEditCategoryHandler]);
|
|
107
128
|
// EFFECTS
|
|
108
129
|
useEffect(() => {
|
|
109
130
|
var _a;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useEffect, useMemo, useReducer, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import { Button, CardContent, List, ListItem, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
6
6
|
import { Endpoints, http, SuggestionService } from '@selfcommunity/api-services';
|
|
@@ -18,6 +18,8 @@ import BaseDialog from '../../shared/BaseDialog';
|
|
|
18
18
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
19
19
|
import InfiniteScroll from '../../shared/InfiniteScroll';
|
|
20
20
|
import { PREFIX } from './constants';
|
|
21
|
+
import PubSub from 'pubsub-js';
|
|
22
|
+
import { SCCategoryEventType, SCTopicType } from '../../constants/PubSub';
|
|
21
23
|
const classes = {
|
|
22
24
|
root: `${PREFIX}-root`,
|
|
23
25
|
title: `${PREFIX}-title`,
|
|
@@ -83,6 +85,8 @@ export default function CategoriesSuggestionWidget(inProps) {
|
|
|
83
85
|
// HOOKS
|
|
84
86
|
const theme = useTheme();
|
|
85
87
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
88
|
+
// REFS
|
|
89
|
+
const updatesSubscription = useRef(null);
|
|
86
90
|
/**
|
|
87
91
|
* Initialize component
|
|
88
92
|
* Fetch data only if the component is not initialized and it is not loading data
|
|
@@ -100,6 +104,23 @@ export default function CategoriesSuggestionWidget(inProps) {
|
|
|
100
104
|
});
|
|
101
105
|
}
|
|
102
106
|
}, [state.isLoadingNext, state.initialized, limit, dispatch]);
|
|
107
|
+
/**
|
|
108
|
+
* Subscriber for pubsub callback
|
|
109
|
+
*/
|
|
110
|
+
const onEditCategoryHandler = useCallback((_msg, edited) => {
|
|
111
|
+
const _categories = [...state.results];
|
|
112
|
+
const updatedCategories = _categories.map((c) => (c.id === edited.id ? Object.assign(Object.assign({}, c), edited) : c));
|
|
113
|
+
dispatch({ type: actionWidgetTypes.SET_RESULTS, payload: { results: updatedCategories } });
|
|
114
|
+
}, [dispatch]);
|
|
115
|
+
/**
|
|
116
|
+
* On mount, subscribe to receive event updates (only edit)
|
|
117
|
+
*/
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.CATEGORY}.${SCCategoryEventType.EDIT}`, onEditCategoryHandler);
|
|
120
|
+
return () => {
|
|
121
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
122
|
+
};
|
|
123
|
+
}, [onEditCategoryHandler]);
|
|
103
124
|
// EFFECTS
|
|
104
125
|
useEffect(() => {
|
|
105
126
|
let _t;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import { Accordion, AccordionDetails, AccordionSummary, Box, Button, CardContent, CardMedia, Checkbox, Chip, Fade, Icon, IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
5
5
|
import { FormattedMessage } from 'react-intl';
|
|
6
6
|
import { styled } from '@mui/material/styles';
|
|
@@ -24,6 +24,8 @@ import OnBoardingWidgetSkeleton from './Skeleton';
|
|
|
24
24
|
import { closeSnackbar, useSnackbar } from 'notistack';
|
|
25
25
|
import HeaderPlaceholder from '../../assets/onBoarding/header';
|
|
26
26
|
import BaseDialog from '../../shared/BaseDialog';
|
|
27
|
+
import PubSub from 'pubsub-js';
|
|
28
|
+
import { SCCategoryEventType, SCTopicType } from '../../constants/PubSub';
|
|
27
29
|
const classes = {
|
|
28
30
|
root: `${PREFIX}-root`,
|
|
29
31
|
content: `${PREFIX}-content`,
|
|
@@ -189,6 +191,13 @@ const OnBoardingWidget = (inProps) => {
|
|
|
189
191
|
fetchPlatform('/contents/interests/');
|
|
190
192
|
setShowCategoriesModal(false);
|
|
191
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* Notify when a category info changes
|
|
196
|
+
* @param data
|
|
197
|
+
*/
|
|
198
|
+
const notifyCategoryChanges = useCallback((data) => {
|
|
199
|
+
PubSub.publish(`${SCTopicType.CATEGORY}.${SCCategoryEventType.EDIT}`, data);
|
|
200
|
+
}, []);
|
|
192
201
|
// EFFECTS
|
|
193
202
|
useEffect(() => {
|
|
194
203
|
if (prevContentsStep &&
|
|
@@ -224,6 +233,22 @@ const OnBoardingWidget = (inProps) => {
|
|
|
224
233
|
return () => clearInterval(intervalId);
|
|
225
234
|
}
|
|
226
235
|
}, [scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user, isGenerating, isAdmin]);
|
|
236
|
+
/**
|
|
237
|
+
* updates categories info when generating category content
|
|
238
|
+
*/
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
const categoryStep = steps.find((step) => step.step === SCOnBoardingStepType.CATEGORIES);
|
|
241
|
+
if ((categoryStep === null || categoryStep === void 0 ? void 0 : categoryStep.status) === SCOnBoardingStepStatusType.IN_PROGRESS && categoryStep.results.length !== 0) {
|
|
242
|
+
categoryStep.results.forEach((c) => {
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
const isAlreadyNotified = prevCategoriesStep === null || prevCategoriesStep === void 0 ? void 0 : prevCategoriesStep.results.some((result) => result.id === c.id);
|
|
246
|
+
if (!isAlreadyNotified) {
|
|
247
|
+
notifyCategoryChanges(c);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}, [steps, prevCategoriesStep]);
|
|
227
252
|
/**
|
|
228
253
|
* Render _step content section
|
|
229
254
|
*/
|
|
@@ -4,7 +4,8 @@ import { SCUserType, SCGroupType, SCEventType } from '@selfcommunity/types';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare enum SCTopicType {
|
|
6
6
|
GROUP = "group",
|
|
7
|
-
EVENT = "event"
|
|
7
|
+
EVENT = "event",
|
|
8
|
+
CATEGORY = "category"
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Group/Event event types
|
|
@@ -18,6 +19,12 @@ export declare enum SCGroupEventType {
|
|
|
18
19
|
INVITE_MEMBER = "members.invite_member",
|
|
19
20
|
REMOVE_MEMBER = "members.remove_member"
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Category event types
|
|
24
|
+
*/
|
|
25
|
+
export declare enum SCCategoryEventType {
|
|
26
|
+
EDIT = "edit"
|
|
27
|
+
}
|
|
21
28
|
export interface SCGroupMembersEventType {
|
|
22
29
|
group: SCGroupType;
|
|
23
30
|
user?: SCUserType;
|
|
@@ -5,6 +5,7 @@ export var SCTopicType;
|
|
|
5
5
|
(function (SCTopicType) {
|
|
6
6
|
SCTopicType["GROUP"] = "group";
|
|
7
7
|
SCTopicType["EVENT"] = "event";
|
|
8
|
+
SCTopicType["CATEGORY"] = "category";
|
|
8
9
|
})(SCTopicType || (SCTopicType = {}));
|
|
9
10
|
/**
|
|
10
11
|
* Group/Event event types
|
|
@@ -19,3 +20,10 @@ export var SCGroupEventType;
|
|
|
19
20
|
SCGroupEventType["INVITE_MEMBER"] = "members.invite_member";
|
|
20
21
|
SCGroupEventType["REMOVE_MEMBER"] = "members.remove_member";
|
|
21
22
|
})(SCGroupEventType || (SCGroupEventType = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Category event types
|
|
25
|
+
*/
|
|
26
|
+
export var SCCategoryEventType;
|
|
27
|
+
(function (SCCategoryEventType) {
|
|
28
|
+
SCCategoryEventType["EDIT"] = "edit";
|
|
29
|
+
})(SCCategoryEventType || (SCCategoryEventType = {}));
|