@selfcommunity/react-core 0.7.0-alpha.14 → 0.7.0-alpha.15

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.
@@ -12,7 +12,8 @@ import { SCUserAutocompleteType } from '@selfcommunity/types';
12
12
  * @param props
13
13
  */
14
14
  declare const useSCFetchUsers: (props?: {
15
- search?: string;
15
+ search: string;
16
+ exclude?: string;
16
17
  }) => {
17
18
  users: SCUserAutocompleteType[];
18
19
  isLoading: boolean;
@@ -18,33 +18,33 @@ const utils_1 = require("@selfcommunity/utils");
18
18
  * @param props
19
19
  */
20
20
  const useSCFetchUsers = (props) => {
21
- const { search = '' } = props || {};
21
+ const { search = '', exclude = '' } = props || {};
22
22
  const [data, setData] = (0, react_1.useState)({ users: [], isLoading: false });
23
- const fetchUsers = (next = api_services_1.Endpoints.UserAutocomplete.url(), searchParam) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
23
+ const fetchUsers = (next = api_services_1.Endpoints.UserAutocomplete.url(), searchParam, excludeParam) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
24
24
  const response = yield api_services_1.http.request({
25
25
  url: next,
26
26
  method: api_services_1.Endpoints.UserAutocomplete.method,
27
- params: searchParam ? { search: searchParam } : undefined,
27
+ params: Object.assign({ search: searchParam }, (excludeParam && { exclude: excludeParam })),
28
28
  });
29
- const data = response.data;
30
- if (data.next) {
31
- return data.results.concat(yield fetchUsers(data.next, searchParam));
29
+ const result = response.data;
30
+ if (result.next) {
31
+ return result.results.concat(yield fetchUsers(result.next, searchParam, excludeParam));
32
32
  }
33
- return data.results;
33
+ return result.results;
34
34
  });
35
35
  (0, react_1.useEffect)(() => {
36
36
  if (!search)
37
37
  return;
38
- fetchUsers(undefined, search)
39
- .then((data) => {
40
- setData({ users: data, isLoading: false });
38
+ fetchUsers(undefined, search, exclude)
39
+ .then((users) => {
40
+ setData({ users, isLoading: false });
41
41
  })
42
42
  .catch((error) => {
43
43
  console.error(error);
44
44
  utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, 'Unable to retrieve users');
45
45
  setData((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
46
46
  });
47
- }, [search]);
47
+ }, [search, exclude]);
48
48
  return data;
49
49
  };
50
50
  exports.default = useSCFetchUsers;
@@ -12,7 +12,8 @@ import { SCUserAutocompleteType } from '@selfcommunity/types';
12
12
  * @param props
13
13
  */
14
14
  declare const useSCFetchUsers: (props?: {
15
- search?: string;
15
+ search: string;
16
+ exclude?: string;
16
17
  }) => {
17
18
  users: SCUserAutocompleteType[];
18
19
  isLoading: boolean;
@@ -16,33 +16,33 @@ import { Logger } from '@selfcommunity/utils';
16
16
  * @param props
17
17
  */
18
18
  const useSCFetchUsers = (props) => {
19
- const { search = '' } = props || {};
19
+ const { search = '', exclude = '' } = props || {};
20
20
  const [data, setData] = useState({ users: [], isLoading: false });
21
- const fetchUsers = (next = Endpoints.UserAutocomplete.url(), searchParam) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const fetchUsers = (next = Endpoints.UserAutocomplete.url(), searchParam, excludeParam) => __awaiter(void 0, void 0, void 0, function* () {
22
22
  const response = yield http.request({
23
23
  url: next,
24
24
  method: Endpoints.UserAutocomplete.method,
25
- params: searchParam ? { search: searchParam } : undefined,
25
+ params: Object.assign({ search: searchParam }, (excludeParam && { exclude: excludeParam })),
26
26
  });
27
- const data = response.data;
28
- if (data.next) {
29
- return data.results.concat(yield fetchUsers(data.next, searchParam));
27
+ const result = response.data;
28
+ if (result.next) {
29
+ return result.results.concat(yield fetchUsers(result.next, searchParam, excludeParam));
30
30
  }
31
- return data.results;
31
+ return result.results;
32
32
  });
33
33
  useEffect(() => {
34
34
  if (!search)
35
35
  return;
36
- fetchUsers(undefined, search)
37
- .then((data) => {
38
- setData({ users: data, isLoading: false });
36
+ fetchUsers(undefined, search, exclude)
37
+ .then((users) => {
38
+ setData({ users, isLoading: false });
39
39
  })
40
40
  .catch((error) => {
41
41
  console.error(error);
42
42
  Logger.error(SCOPE_SC_CORE, 'Unable to retrieve users');
43
43
  setData((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
44
44
  });
45
- }, [search]);
45
+ }, [search, exclude]);
46
46
  return data;
47
47
  };
48
48
  export default useSCFetchUsers;