Skip to content

Commit

Permalink
Merge b78eb82 into 60df2e1
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Oct 15, 2020
2 parents 60df2e1 + b78eb82 commit 21bfd19
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/js/react/Recommender/components/RecommendedList.jsx.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
define([
'react',
'react-prop-types',
'react-redux',
'react-bootstrap',
'../actions',
], function(
define(['react', 'react-prop-types', 'react-redux', '../actions'], function(
React,
PropTypes,
{ useSelector, useDispatch },
{ Button },
{ getRecommendations, getFullList, emitAnalytics }
{ getRecommendations, emitAnalytics }
) {
const Paper = ({ title, bibcode, author, totalAuthors, onClick }) => {
const el = React.useRef(null);
Expand Down Expand Up @@ -71,61 +64,65 @@ define([

var executed = 0;
var userName = null;
var reported = false;
const selector = (state) => {
// reset if it is a different user
if (state.userName !== userName) {
executed = 0;
userName = state.userName;
reported = false;
}

return {
getRecommendationsRequest: state.requests.GET_RECOMMENDATIONS,
getDocsRequest: state.requests.GET_DOCS,
docs: state.docs,
queryParams: state.queryParams,
executed: executed
executed: executed,
reported: reported,
};
};

const RecommendedList = () => {
const dispatch = useDispatch();
/*
const onGetMore = () => {
dispatch(getFullList());
};
*/

const {
getRecommendationsRequest,
getDocsRequest,
docs,
queryParams,
userName
userName // eslint-disable-line
} = useSelector(selector);

React.useEffect(() => {
if ((executed + 12*60*60*1000) < Date.now()) {
if (executed + 12 * 60 * 60 * 1000 < Date.now()) {
// the hook gets called too many times even with [docs] in the args to useEffect
// (and oracle returns 404 when nothing is found; which is IMHO wrong) but we can't
// rely on status.failure for that reason
executed = Date.now();
dispatch(getRecommendations());
}
else {
if (executed && getDocsRequest && getDocsRequest.status && docs.length === 0) {
// we are rendered (send the signal everytime -- even if it was sent already)
dispatch(
emitAnalytics([
'send',
'event',
'interaction.recommendation', // category
'no-useful-recommendations', // action
'', // label,
0, // value
])
);
}
reported = false;
} else if (executed && docs.length === 0 && !reported) {
// we are rendered (send the signal everytime -- even if it was sent already)
dispatch(
emitAnalytics([
'send',
'event',
'interaction.no-recommendation', // category
'no-useful-recommendations', // action
'', // label,
0, // value
])
);
reported = true;
}
});


const onPaperSelect = ({ bibcode }, index) => {
dispatch(
emitAnalytics([
Expand Down Expand Up @@ -173,7 +170,12 @@ define([
if (docs.length === 0) {
return (
<Message>
Sorry, we don't have any recommendations for you just yet! ADS provides users recommendations based on their reading history, and we suggest that you create an ADS account to take advantage of this feature. If you already have an account, then be sure you are logged in while searching and reading papers. In due time we will be able to provide you with suggestions based on your inferred interests.
Sorry, we do not have any recommendations for you just yet! ADS
provides users recommendations based on their reading history, and we
suggest that you create an ADS account to take advantage of this
feature. If you already have an account, then be sure you are logged
in while searching and reading papers. In due time we will be able to
provide you with suggestions based on your inferred interests.
</Message>
);
}
Expand Down

0 comments on commit 21bfd19

Please sign in to comment.