diff --git a/app/components/dashboard/SearchBoxes.jsx b/app/components/dashboard/SearchBoxes.jsx index d6270137aa706eed0e88c1b353a0b53ffe89ab1f..c9aacc7d4f0d6f9b514e631bcedc0c170c6e832a 100644 --- a/app/components/dashboard/SearchBoxes.jsx +++ b/app/components/dashboard/SearchBoxes.jsx @@ -27,6 +27,9 @@ const SearchArea = styled.div` flex-wrap: wrap; } ` + +let errorTimer + class SearchBoxes extends React.Component { state = { id: SearchBoxes.id ? SearchBoxes.id : '', @@ -34,19 +37,32 @@ class SearchBoxes extends React.Component { errors: [], } componentDidUpdate() { - if (this.state.errors && this.area) { - setTimeout(() => { + const { errors } = this.state + + if (errorTimer) { + clearTimeout(errorTimer) + } + + if (errors && this.area) { + errorTimer = setTimeout(() => { this.setState({ errors: [] }) }, 10000) } } + componentWillUnmount() { + clearTimeout(errorTimer) + } + static id = '' static search = '' setRef = area => { this.area = area } onSearchValChanged = e => { - this.setState({ [e.target.name]: e.target.value }) + this.setState({ + [e.target.name]: e.target.value, + errors: [], + }) SearchBoxes[e.target.name] = e.target.value } onSearchValSubmitted = (where, e) => { diff --git a/server/eutils/api.js b/server/eutils/api.js index e6938086d6c197a905570935bd0f6f2b734c12d1..62ae77d10bbb88cfe6116e3ce1a5a615df521ab6 100755 --- a/server/eutils/api.js +++ b/server/eutils/api.js @@ -8,10 +8,12 @@ try { // console.log("eutils-api-key is not defined") } -// const authBearer = passport.authenticate('bearer', { session: false }) - module.exports = app => { - app.get('/eutils/esearch', (req, res) => { + const authBearer = app.locals.passport.authenticate('bearer', { + session: false, + }) + + app.get('/eutils/esearch', authBearer, (req, res) => { res.set({ 'Content-Type': 'application/json' }) const { term, db, retstart, sort } = req.query @@ -32,7 +34,7 @@ module.exports = app => { } }) }) - app.get('/eutils/efetch', (req, res) => { + app.get('/eutils/efetch', authBearer, (req, res) => { res.set({ 'Content-Type': 'application/xml' }) const { id, db } = req.query @@ -48,7 +50,7 @@ module.exports = app => { res.send(response.text.toString()) }) }) - app.get('/eutils/esummary', (req, res) => { + app.get('/eutils/esummary', authBearer, (req, res) => { res.set({ 'Content-Type': 'application/json' }) const { id, db } = req.query