chayns-components
Version:
A set of beautiful React components for developing chayns® applications.
55 lines (54 loc) • 1.53 kB
JavaScript
import React, { createContext, useEffect, useReducer } from 'react';
import PropTypes from 'prop-types';
import { reducer as DefaultReducer, initialState } from './UacGroupReducer';
import { fetchGroups } from './UacGroupApi';
const ObjectMapping = {
showName: 'showName',
identifier: 'id',
search: ['showName', 'name'],
imageUrl: null,
filter: inputValue => e => ['showName', 'name'].some(key => e[key] && e[key].toLowerCase().startsWith((inputValue || '').toLowerCase()))
};
const UacGroupContext = /*#__PURE__*/createContext({
value: null
});
const UacGroupStateProvider = _ref => {
let {
children = null
} = _ref;
const [data, dispatch] = useReducer(DefaultReducer, initialState);
useEffect(() => {
(async () => {
dispatch({
type: 'REQUEST_DATA',
showWaitCursor: true,
clear: true
});
const groups = await fetchGroups();
if (groups) {
dispatch({
type: 'RECEIVE_DATA',
data: groups,
hasMore: false
});
}
})();
}, []);
return /*#__PURE__*/React.createElement(UacGroupContext.Provider, {
value: {
...data,
dispatch,
onLoadMore: null,
onChange: () => undefined
}
}, children);
};
UacGroupStateProvider.propTypes = {
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
};
export default {
Consumer: UacGroupContext.Consumer,
Provider: UacGroupStateProvider,
ObjectMapping
};
//# sourceMappingURL=UacGroupContext.js.map