cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
116 lines (97 loc) • 2.54 kB
JavaScript
import constants from '../constants';
import { unauthorized } from './generic';
import { followEntity, all, unFollowEntity } from '../data/follow';
var dispatchFollow = __cluedIn.dispatchFollow;
var dispatchUnFollow = __cluedIn.dispatchUnFollow;
var invalidFollow = ( id ) => {
return {
type: constants.follow.INVALID_FOLLOW,
data: {
id: id
}
}
};
var receive_follow = ( entity ) => {
return {
type: constants.follow.RECEIVE_FOLLOW,
data: {
entity: entity
}
};
};
var requestFollow = ( id ) => {
return {
type: constants.follow.REQUEST_FOLLOW,
data: {
id: id
}
};
};
var requestUnFollow = ( id ) => {
return {
type: constants.follow.REQUEST_UNFOLLOW,
data: {
id: id
}
};
};
var invalidUnFollow = ( id ) => {
return {
type: constants.follow.REQUEST_UNFOLLOW,
data: {
id: id
}
};
};
var receive_UnFollow = ( entity ) => {
return {
type: constants.follow.RECEIVE_UNFOLLOW,
data: {
entity: entity
}
};
};
export function unFollow( entity ) {
return function( dispatch ) {
dispatch( requestUnFollow( entity.id ) );
return unFollowEntity( entity.id ).then( function() {
dispatchUnFollow( entity );
dispatch( receive_UnFollow( entity ) );
} ).catch( unauthorized( dispatch, invalidUnFollow ) )
}
}
export function follow( entity ) {
return function( dispatch ) {
dispatch( requestFollow( entity.id ) );
return followEntity( entity.id ).then( function() {
dispatchFollow( entity );
dispatch( receive_follow( entity ) );
} ).catch( unauthorized( dispatch, invalidFollow ) );
};
}
var requestAllFollow = () => {
return {
type: constants.follow.REQUEST_ALL_FOLLOW
}
};
var receiveAllFollow = ( followers ) => {
return {
type: constants.follow.RECEIVE_ALL_FOLLOW,
data: {
followers: followers
}
}
};
var invalidAllFollow = () => {
return {
type: constants / follow.INVALID_ALL_FOLLOW
};
};
export function fetchAllFollow() {
return function( dispatch ) {
dispatch( requestAllFollow() );
return all().then( function( allFollowers ) {
dispatch( receiveAllFollow( allFollowers ) );
} ).catch( unauthorized( dispatch, invalidAllFollow ) );
};
}