Skip to content

Commit

Permalink
Merge pull request #29 from aMarcireau/bugs
Browse files Browse the repository at this point in the history
Bugs
  • Loading branch information
Alexandre Marcireau authored Dec 1, 2017
2 parents 01f006b + 105e016 commit 890c9b8
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 52 deletions.
3 changes: 2 additions & 1 deletion source/actions/getPublicationFromDoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ export function fetchPublicationFromDoi(doi) {
};
}

export function resolvePublicationFromDoi(doi, crossrefMessage, bibtexRequestId) {
export function resolvePublicationFromDoi(doi, crossrefMessage, bibtexRequestId, timestamp) {
return {
type: RESOLVE_PUBLICATION_FROM_DOI,
doi,
crossrefMessage,
bibtexRequestId,
timestamp,
};
}

Expand Down
6 changes: 2 additions & 4 deletions source/actions/manageMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,10 @@ export function bibtexToPublications(bibtex) {
++position;
switch (status) {
case 'root':
if (character === '%') {
status = 'comment';
} else if (character === '@') {
if (character === '@') {
status = 'type';
} else if (/\S/.test(character)) {
throwError(character);
status = 'comment';
}
break;
case 'comment':
Expand Down
2 changes: 1 addition & 1 deletion source/actions/manageScholarPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function resolveHtml(url, text) {
let metadata = '';
for (let child of metadataCandidates[0].children) {
if (child.type === 'text') {
metadata += child.data;
metadata += child.data.replace(/ /g, ' ');
} else if (
child.type === 'tag'
&& child.name === 'a'
Expand Down
3 changes: 2 additions & 1 deletion source/actors/manageCrossref.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export default function manageCrossref(store) {
store.dispatch(resolvePublicationFromDoi(
doi,
json.message,
Array.from(bytes).map(byte => byte.toString(16)).join('')
Array.from(bytes).map(byte => byte.toString(16)).join(''),
new Date().getTime()
));
})
.catch(error => {
Expand Down
3 changes: 1 addition & 2 deletions source/components/ProgressBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import Radium from 'radium'
import PropTypes from 'prop-types'

class ProgressBar extends React.Component {
Expand Down Expand Up @@ -45,4 +44,4 @@ class ProgressBar extends React.Component {
}
}

export default Radium(ProgressBar);
export default ProgressBar;
2 changes: 1 addition & 1 deletion source/containers/AddDoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AddDoi extends React.Component {
},
}}
onClick={() => {
this.props.dispatch(publicationFromDoi(this.state.value.match(doiPattern)[1]));
this.props.dispatch(publicationFromDoi(this.state.value.match(doiPattern)[1], new Date().getTime()));
this.setState({valid: false, value: ''});
}}
>
Expand Down
12 changes: 6 additions & 6 deletions source/containers/Graph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import Radium from 'radium'
import {connect} from 'react-redux'
import PropTypes from 'prop-types'
import {
Expand Down Expand Up @@ -41,6 +40,10 @@ class Graph extends React.Component {
this.svg = null;
this.nodes = [];
this.edges = [];
this.d3Node = null;
this.d3Edge = null;
this.zoom = null;
this.reheatSimulation = false;
this.simulation = d3.forceSimulation(this.nodes)
.stop()
.force('link', d3.forceLink(this.edges).distance(80).strength(1).id(node => node.doi))
Expand Down Expand Up @@ -68,10 +71,6 @@ class Graph extends React.Component {
}
})
;
this.d3Node = null;
this.d3Edge = null;
this.zoom = null;
this.reheatSimulation = false;
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -388,6 +387,7 @@ class Graph extends React.Component {
})
;
this.svg.call(this.zoom);
this.zoom.scaleTo(this.svg, 2 ** (this.props.zoom / 20));
this.d3Node = this.svg.selectAll('.node');
this.d3Edge = this.svg.selectAll('.edge');
this.simulation.alpha(0);
Expand Down Expand Up @@ -466,4 +466,4 @@ export default connect(
colors: state.colors,
};
}
)(Radium(Graph));
)(Graph);
1 change: 0 additions & 1 deletion source/containers/GraphWithToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class GraphWithToolbar extends React.Component {
xOffset={0}
yOffset={0}
/>

<div style={{
position: 'absolute',
width: '100%',
Expand Down
3 changes: 1 addition & 2 deletions source/containers/HorizontallyMovable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import Radium from 'radium'
import {connect} from 'react-redux'
import PropTypes from 'prop-types'
import {
Expand Down Expand Up @@ -123,4 +122,4 @@ export default connect(
mouseOwner: state.mouseOwner,
};
}
)(Radium(HorizontallyMovable));
)(HorizontallyMovable);
3 changes: 1 addition & 2 deletions source/containers/Menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import Radium from 'radium'
import {connect} from 'react-redux'
import PropTypes from 'prop-types'
import MenuItem from '../containers/MenuItem'
Expand Down Expand Up @@ -122,4 +121,4 @@ export default connect(
isMenuOpen: state.menu.activeItem != null,
};
}
)(Radium(Menu));
)(Menu);
2 changes: 1 addition & 1 deletion source/containers/Recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ export default connect(
url: state.scholar.url,
};
}
)(Radium(Recaptcha));
)(Recaptcha);
2 changes: 1 addition & 1 deletion source/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Origami",
"version": "0.5.0",
"version": "0.5.1",
"main": "main.js",
"private": true,
"devDependencies": {
Expand Down
8 changes: 7 additions & 1 deletion source/reducers/origami.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export default function(state, action) {
tabs,
version,
warnings: (state = {}) => state,
})
}),
(state = {}, action) => {
if (process.env.ORIGAMI_ENV === 'development') {
console.log(action.type, action, state);
}
return state;
}
)(state, action);
}
105 changes: 91 additions & 14 deletions source/reducers/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PUBLICATION_STATUS_IN_COLLECTION,
PAGE_TYPE_INITIALIZE,
} from '../constants/enums'
import {isOlderThan} from '../actions/managePublication'

export default function publications(state = new Map(), action, appState) {
switch (action.type) {
Expand Down Expand Up @@ -98,9 +99,24 @@ export default function publications(state = new Map(), action, appState) {
newState.set(action.doi, {
...state.get(action.doi),
title: action.crossrefMessage.title[0] == null ? '' : action.crossrefMessage.title[0],
authors: action.crossrefMessage.author.map(author => `${author.given} ${author.family}`),
authors: action.crossrefMessage.author.filter(
author => author.given != null || author.family != null
).map(
author => {
if (author.given == null) {
return author.family;
}
if (author.family == null) {
return author.given;
}
return `${author.given} ${author.family}`;
}
),
journal: action.crossrefMessage.publisher,
date: action.crossrefMessage.created['date-parts'][0],
date: (isOlderThan(action.crossrefMessage.created['date-parts'][0], action.crossrefMessage.issued['date-parts'][0]) ?
action.crossrefMessage.created['date-parts'][0]
: action.crossrefMessage.issued['date-parts'][0]
),
status: PUBLICATION_STATUS_IN_COLLECTION,
updated: action.timestamp,
validating: false,
Expand Down Expand Up @@ -144,17 +160,18 @@ export default function publications(state = new Map(), action, appState) {
if (!state.has(action.doi) || state.get(action.doi).status !== PUBLICATION_STATUS_IN_COLLECTION) {
return state;
}
const doisToRemove = new Set([
...state.get(action.doi).citers.filter(citer => state.get(citer).status === PUBLICATION_STATUS_DEFAULT),
action.doi,
]);
const newState = new Map(state);
newState.set(action.doi, {
...state.get(action.doi),
status: PUBLICATION_STATUS_DEFAULT,
bibtex: null,
locked: false,
citers: [],
});
const doisToRemove = new Set([
...state.get(action.doi).citers.filter(citer => state.get(citer).status === PUBLICATION_STATUS_DEFAULT),
action.doi,
]);
for (const publication of newState.values()) {
if (publication.status === PUBLICATION_STATUS_IN_COLLECTION) {
for (const citer of publication.citers) {
Expand Down Expand Up @@ -246,17 +263,47 @@ export default function publications(state = new Map(), action, appState) {
newState.set(doi, {
...newState.get(doi),
title: action.crossrefMessage.title[0],
authors: action.crossrefMessage.author.map(author => `${author.given ? `${author.given} ` : ''}${author.family}`),
authors: action.crossrefMessage.author.filter(
author => author.given != null || author.family != null
).map(
author => {
if (author.given == null) {
return author.family;
}
if (author.family == null) {
return author.given;
}
return `${author.given} ${author.family}`;
}
),
journal: action.crossrefMessage.publisher,
date: action.crossrefMessage.created['date-parts'][0],
date: (isOlderThan(action.crossrefMessage.created['date-parts'][0], action.crossrefMessage.issued['date-parts'][0]) ?
action.crossrefMessage.created['date-parts'][0]
: action.crossrefMessage.issued['date-parts'][0]
),
});
} else {
newState.set(doi, {
status: PUBLICATION_STATUS_DEFAULT,
title: action.crossrefMessage.title[0],
authors: action.crossrefMessage.author.map(author => `${author.given ? `${author.given} ` : ''}${author.family}`),
authors: action.crossrefMessage.author.filter(
author => author.given != null || author.family != null
).map(
author => {
if (author.given == null) {
return author.family;
}
if (author.family == null) {
return author.given;
}
return `${author.given} ${author.family}`;
}
),
journal: action.crossrefMessage.publisher,
date: action.crossrefMessage.created['date-parts'][0],
date: (isOlderThan(action.crossrefMessage.created['date-parts'][0], action.crossrefMessage.issued['date-parts'][0]) ?
action.crossrefMessage.created['date-parts'][0]
: action.crossrefMessage.issued['date-parts'][0]
),
citers: [],
updated: null,
selected: false,
Expand Down Expand Up @@ -289,18 +336,48 @@ export default function publications(state = new Map(), action, appState) {
...newState.get(doi),
status: PUBLICATION_STATUS_IN_COLLECTION,
title: action.crossrefMessage.title[0],
authors: action.crossrefMessage.author.map(author => `${author.given ? `${author.given} ` : ''}${author.family}`),
authors: action.crossrefMessage.author.filter(
author => author.given != null || author.family != null
).map(
author => {
if (author.given == null) {
return author.family;
}
if (author.family == null) {
return author.given;
}
return `${author.given} ${author.family}`;
}
),
journal: action.crossrefMessage.publisher,
date: action.crossrefMessage.created['date-parts'][0],
date: (isOlderThan(action.crossrefMessage.created['date-parts'][0], action.crossrefMessage.issued['date-parts'][0]) ?
action.crossrefMessage.created['date-parts'][0]
: action.crossrefMessage.issued['date-parts'][0]
),
updated: action.timestamp,
});
} else {
newState.set(doi, {
status: PUBLICATION_STATUS_IN_COLLECTION,
title: action.crossrefMessage.title[0],
authors: action.crossrefMessage.author.map(author => `${author.given ? `${author.given} ` : ''}${author.family}`),
authors: action.crossrefMessage.author.filter(
author => author.given != null || author.family != null
).map(
author => {
if (author.given == null) {
return author.family;
}
if (author.family == null) {
return author.given;
}
return `${author.given} ${author.family}`;
}
),
journal: action.crossrefMessage.publisher,
date: action.crossrefMessage.created['date-parts'][0],
date: (isOlderThan(action.crossrefMessage.created['date-parts'][0], action.crossrefMessage.issued['date-parts'][0]) ?
action.crossrefMessage.created['date-parts'][0]
: action.crossrefMessage.issued['date-parts'][0]
),
citers: [],
updated: action.timestamp,
selected: false,
Expand Down
18 changes: 17 additions & 1 deletion source/reducers/scholar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
REMOVE_PUBLICATION,
UPDATE_PUBLICATION,
UPDATE_ALL_PUBLICATIONS,
PUBLICATION_FROM_DOI,
RESOLVE_PUBLICATION_FROM_DOI,
FETCH_SCHOLAR_PAGE,
RESOLVE_SCHOLAR_INITIAL_PAGE,
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function scholar(
url: `https://scholar.google.com/scholar?hl=en&q=${encodeURIComponent(action.doi)}`,
}],
};
case RESOLVE_PUBLICATION_FROM_IMPORTED_METADATA:
case RESOLVE_PUBLICATION_FROM_IMPORTED_METADATA: {
const doi = action.crossrefMessage.DOI.toLowerCase();
if (appState.publications.has(doi) && appState.publications.get(doi).status !== PUBLICATION_STATUS_DEFAULT) {
return state;
Expand All @@ -71,6 +72,7 @@ export default function scholar(
url: `https://scholar.google.com/scholar?hl=en&q=${encodeURIComponent(doi)}`,
}],
};
}
case REMOVE_PUBLICATION:
return {
...state,
Expand Down Expand Up @@ -120,6 +122,20 @@ export default function scholar(
}),
],
}
case PUBLICATION_FROM_DOI: {
const doi = action.doi.toLowerCase();
if (!appState.publications.has(doi) || appState.publications.get(doi).status !== PUBLICATION_STATUS_DEFAULT) {
return state;
}
return {
...state,
pages: [...state.pages, {
type: PAGE_TYPE_INITIALIZE,
doi,
url: `https://scholar.google.com/scholar?hl=en&q=${encodeURIComponent(doi)}`,
}],
};
}
case RESOLVE_PUBLICATION_FROM_DOI:
if (!appState.publications.has(action.doi) || appState.publications.get(action.doi).status !== PUBLICATION_STATUS_UNVALIDATED) {
return state;
Expand Down
Loading

0 comments on commit 890c9b8

Please sign in to comment.