UNPKG

cluedin-widget

Version:

This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.

110 lines (88 loc) 2.34 kB
/* eslint-env browser */ /* eslint no-underscore-dangle: ["error", { "allow": ["__cluedIn"] }]*/ import constants from '../constants'; import { unauthorized } from './generic'; import { followEntity, unFollowEntity } from '../data/follow'; import { getAll } from '../data/insight'; const dispatchFollow = window.__cluedIn.dispatchFollow; const dispatchUnFollow = window.__cluedIn.dispatchUnFollow; const invalidFollow = (id) => ({ type: constants.follow.INVALID_FOLLOW, data: { id, }, }); const receiveFollow = (entity) => ({ type: constants.follow.RECEIVE_FOLLOW, data: { entity, }, }); const requestFollow = (id) => ({ type: constants.follow.REQUEST_FOLLOW, data: { id, }, }); const requestUnFollow = (id) => ({ type: constants.follow.REQUEST_UNFOLLOW, data: { id, }, }); const invalidUnFollow = (id) => ({ type: constants.follow.REQUEST_UNFOLLOW, data: { id, }, }); const receiveUnFollow = (entity) => ({ type: constants.follow.RECEIVE_UNFOLLOW, data: { entity, }, }); export function unFollow(entity) { return (dispatch) => { dispatch(requestUnFollow(entity.id)); return unFollowEntity(entity.id).then(() => { dispatchUnFollow(entity); dispatch(receiveUnFollow(entity)); }).catch(unauthorized(dispatch, invalidUnFollow)); }; } export function follow(entity) { return (dispatch) => { dispatch(requestFollow(entity.id)); return followEntity(entity.id).then(() => { dispatchFollow(entity); dispatch(receiveFollow(entity)); }).catch(unauthorized(dispatch, invalidFollow)); }; } const requestAllFollow = () => ({ type: constants.follow.REQUEST_ALL_FOLLOW, }); const receiveAllFollow = (followers) => ({ type: constants.follow.RECEIVE_ALL_FOLLOW, data: { followers, }, }); const invalidAllFollow = () => ({ type: constants.follow.INVALID_ALL_FOLLOW, }); export const resetNotificationForFollow = () => ({ type: constants.follow.RESET_NOTIFICATION_FOR_FOLLOW, }); export function fetchAllFollow() { return (dispatch, getState) => { if (getState().follow.allFollowers.length > 0) { return; } dispatch(requestAllFollow()); getAll().then((allFollowers) => { dispatch(receiveAllFollow(allFollowers)); }).catch(unauthorized(dispatch, invalidAllFollow)); }; }