diff --git a/package-lock.json b/package-lock.json index 7321da7..f1aa7f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7910,6 +7910,25 @@ "requires": { "normalizeurl": "~0.1.3", "superagent": "^3.8.3" + }, + "dependencies": { + "superagent": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.3.tgz", + "integrity": "sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==", + "requires": { + "component-emitter": "^1.2.0", + "cookiejar": "^2.1.0", + "debug": "^3.1.0", + "extend": "^3.0.0", + "form-data": "^2.3.1", + "formidable": "^1.2.0", + "methods": "^1.1.1", + "mime": "^1.4.1", + "qs": "^6.5.1", + "readable-stream": "^2.3.5" + } + } } }, "json-parse-better-errors": { @@ -14172,20 +14191,49 @@ "integrity": "sha1-zRhz+/Kn2smm8prKHq2hr3UTz58=" }, "superagent": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.3.tgz", - "integrity": "sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-4.0.0.tgz", + "integrity": "sha512-qaGDf+QUYxgMYdJBWCezHnc3UjrCUwxm5bCfxBhTXI5BbCluVzmVNYzxvCw1jP9PXmwUZeOW2yPpGm9fLbhtFg==", "requires": { "component-emitter": "^1.2.0", - "cookiejar": "^2.1.0", - "debug": "^3.1.0", - "extend": "^3.0.0", - "form-data": "^2.3.1", + "cookiejar": "^2.1.2", + "debug": "^4.0.0", + "form-data": "^2.3.2", "formidable": "^1.2.0", "methods": "^1.1.1", - "mime": "^1.4.1", + "mime": "^2.0.3", "qs": "^6.5.1", - "readable-stream": "^2.3.5" + "readable-stream": "^3.0.3" + }, + "dependencies": { + "debug": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", + "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", + "requires": { + "ms": "^2.1.1" + } + }, + "mime": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.0.tgz", + "integrity": "sha512-ikBcWwyqXQSHKtciCcctu9YfPbFYZ4+gbHEmE0Q8jzcTYQg5dHCr3g2wwAZjPoJfQVXZq6KXAjpXOTf5/cjT7w==" + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + }, + "readable-stream": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.0.6.tgz", + "integrity": "sha512-9E1oLoOWfhSXHGv6QlwXJim7uNzd9EVlWK+21tCU9Ju/kR0/p2AZYPz4qSchgO8PlLIH4FpZYfzwS+rEksZjIg==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } }, "supports-color": { diff --git a/package.json b/package.json index fbaa5e7..44878a4 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "react": "^16.5.2", "react-dom": "^16.5.2", "react-scripts": "2.0.3", + "superagent": "^4.0.0", "zoo-grommet": "~0.3.0", "zooniverse-react-components": "github:zooniverse/Zooniverse-React-Components#v0.7.1" }, diff --git a/src/badges/badge-icon-legend.js b/src/badges/badge-icon-legend.js new file mode 100644 index 0000000..f541558 --- /dev/null +++ b/src/badges/badge-icon-legend.js @@ -0,0 +1,199 @@ +// DECADE +import year10s from './decade/year-10s.png'; +import year10s2x from './decade/year-10s@2x.png'; +import year20s from './decade/year-20s.png'; +import year20s2x from './decade/year-20s@2x.png'; +import year30s from './decade/year-30s.png'; +import year30s2x from './decade/year-30s@2x.png'; +import year40s from './decade/year-40s.png'; +import year40s2x from './decade/year-40s@2x.png'; +import year50s from './decade/year-50s.png'; +import year50s2x from './decade/year-50s@2x.png'; +import year60s from './decade/year-60s.png'; +import year60s2x from './decade/year-60s@2x.png'; +import year70s from './decade/year-70s.png'; +import year70s2x from './decade/year-70s@2x.png'; +import year80s from './decade/year-80s.png'; +import year80s2x from './decade/year-80s@2x.png'; +import year90s from './decade/year-90s.png'; +import year90s2x from './decade/year-90s@2x.png'; +import year2000s from './decade/year-2000s.png'; +import year2000s2x from './decade/year-2000s@2x.png'; + +// TIME +import dinner from './time/time-dinner.png'; +import dinner2x from './time/time-dinner@2x.png'; +import earlybird from './time/time-earlybird.png'; +import earlybird2x from './time/time-earlybird@2x.png'; +import earthday from './time/time-earthday.png'; +import earthday2x from './time/time-earthday@2x.png'; +import lunch from './time/time-lunch.png'; +import lunch2x from './time/time-lunch@2x.png'; +import nightowl from './time/time-nightowl.png'; +import nightowl2x from './time/time-nightowl@2x.png'; + +// WORKFLOW +// -- BUTTERFLY +import butterflies from './workflow/butterfly/butterflies.png'; +import butterfly from './workflow/butterfly/butterfly.png'; +// -- HERBARIUM +import matureGrove from './workflow/herbarium/mature-grove.png'; +import matureTree from './workflow/herbarium/mature-tree.png'; +import oak from './workflow/herbarium/oak.png'; +import sapling from './workflow/herbarium/sapling.png'; +import seed from './workflow/herbarium/seed.png'; +import seedling from './workflow/herbarium/seedling.png'; +import tree from './workflow/herbarium/tree.png'; +// -- LABS +import blossom from './workflow/labs/blossom.png'; +import blossoms from './workflow/labs/blossoms.png'; +import fruit from './workflow/labs/fruit.png'; +// -- PINNED_SPECIMEN +import caterpillar from './workflow/pinned_specimen/caterpillar.png'; +import egg from './workflow/pinned_specimen/egg.png'; + +export const decade = [ + year10s, + year10s2x, + year20s, + year20s2x, + year30s, + year30s2x, + year40s, + year40s2x, + year50s, + year50s2x, + year60s, + year60s2x, + year70s, + year70s2x, + year80s, + year80s2x, + year90s, + year90s2x, + year2000s, + year2000s2x +]; + +export const time = [ + dinner, + dinner2x, + earlybird, + earlybird2x, + earthday, + earthday2x, + lunch, + lunch2x, + nightowl, + nightowl2x +]; + +export const workflow = [ + butterflies, + butterfly, + matureGrove, + matureTree, + oak, + sapling, + seed, + seedling, + tree, + blossom, + blossoms, + fruit, + caterpillar, + egg +]; + +const badgeIconLegend = { + decade: { + '10s': { + 1: year10s, + 10: year10s2x + }, + '20s': { + 1: year20s, + 10: year20s2x + }, + '30s': { + 1: year30s, + 10: year30s2x + }, + '40s': { + 1: year40s, + 10: year40s2x + }, + '50s': { + 1: year50s, + 10: year50s2x + }, + '60s': { + 1: year60s, + 10: year60s2x + }, + '70s': { + 1: year70s, + 10: year70s2x + }, + '80s': { + 1: year80s, + 10: year80s2x + }, + '90s': { + 1: year90s, + 10: year90s2x + }, + '00s': { + 1: year2000s, + 10: year2000s2x + } + }, + time: { + dinnertime: { + 1: dinner, + 10: dinner2x + }, + earlybird: { + 1: earlybird, + 10: earlybird2x + }, + lunchbreak: { + 1: lunch, + 10: lunch2x + }, + nightowl: { + 1: nightowl, + 10: nightowl2x + } + }, + earth_day: { + 1: earthday, + 10: earthday2x + }, + workflow_type: { + butterfly: { + 1: butterfly, + 100: butterflies + }, + labs: { + 1: blossom, + 100: blossoms, + 500: fruit + }, + herbarium: { + 1: seed, + 10: seedling, + 25: sapling, + 75: tree, + 250: oak, + 1000: matureTree, + 5000: matureGrove + }, + pinned_specimen: { + 1: egg, + 100: caterpillar + } + } +}; + +export default badgeIconLegend; diff --git a/src/badges/decade/year-10s.png b/src/badges/decade/year-10s.png new file mode 100644 index 0000000..0f9c449 Binary files /dev/null and b/src/badges/decade/year-10s.png differ diff --git a/src/badges/decade/year-10s@2x.png b/src/badges/decade/year-10s@2x.png new file mode 100644 index 0000000..ab3d185 Binary files /dev/null and b/src/badges/decade/year-10s@2x.png differ diff --git a/src/badges/decade/year-2000s.png b/src/badges/decade/year-2000s.png new file mode 100644 index 0000000..66c1b24 Binary files /dev/null and b/src/badges/decade/year-2000s.png differ diff --git a/src/badges/decade/year-2000s@2x.png b/src/badges/decade/year-2000s@2x.png new file mode 100644 index 0000000..d3f7b2b Binary files /dev/null and b/src/badges/decade/year-2000s@2x.png differ diff --git a/src/badges/decade/year-20s.png b/src/badges/decade/year-20s.png new file mode 100644 index 0000000..0ab73ff Binary files /dev/null and b/src/badges/decade/year-20s.png differ diff --git a/src/badges/decade/year-20s@2x.png b/src/badges/decade/year-20s@2x.png new file mode 100644 index 0000000..33d7040 Binary files /dev/null and b/src/badges/decade/year-20s@2x.png differ diff --git a/src/badges/decade/year-30s.png b/src/badges/decade/year-30s.png new file mode 100644 index 0000000..3a940f8 Binary files /dev/null and b/src/badges/decade/year-30s.png differ diff --git a/src/badges/decade/year-30s@2x.png b/src/badges/decade/year-30s@2x.png new file mode 100644 index 0000000..1225d1a Binary files /dev/null and b/src/badges/decade/year-30s@2x.png differ diff --git a/src/badges/decade/year-40s.png b/src/badges/decade/year-40s.png new file mode 100644 index 0000000..e9c67ae Binary files /dev/null and b/src/badges/decade/year-40s.png differ diff --git a/src/badges/decade/year-40s@2x.png b/src/badges/decade/year-40s@2x.png new file mode 100644 index 0000000..a2dc44c Binary files /dev/null and b/src/badges/decade/year-40s@2x.png differ diff --git a/src/badges/decade/year-50s.png b/src/badges/decade/year-50s.png new file mode 100644 index 0000000..755156a Binary files /dev/null and b/src/badges/decade/year-50s.png differ diff --git a/src/badges/decade/year-50s@2x.png b/src/badges/decade/year-50s@2x.png new file mode 100644 index 0000000..255cb52 Binary files /dev/null and b/src/badges/decade/year-50s@2x.png differ diff --git a/src/badges/decade/year-60s.png b/src/badges/decade/year-60s.png new file mode 100644 index 0000000..60301f0 Binary files /dev/null and b/src/badges/decade/year-60s.png differ diff --git a/src/badges/decade/year-60s@2x.png b/src/badges/decade/year-60s@2x.png new file mode 100644 index 0000000..0a6c242 Binary files /dev/null and b/src/badges/decade/year-60s@2x.png differ diff --git a/src/badges/decade/year-70s.png b/src/badges/decade/year-70s.png new file mode 100644 index 0000000..6859694 Binary files /dev/null and b/src/badges/decade/year-70s.png differ diff --git a/src/badges/decade/year-70s@2x.png b/src/badges/decade/year-70s@2x.png new file mode 100644 index 0000000..0c334d2 Binary files /dev/null and b/src/badges/decade/year-70s@2x.png differ diff --git a/src/badges/decade/year-80s.png b/src/badges/decade/year-80s.png new file mode 100644 index 0000000..7c02630 Binary files /dev/null and b/src/badges/decade/year-80s.png differ diff --git a/src/badges/decade/year-80s@2x.png b/src/badges/decade/year-80s@2x.png new file mode 100644 index 0000000..84a3ff5 Binary files /dev/null and b/src/badges/decade/year-80s@2x.png differ diff --git a/src/badges/decade/year-90s.png b/src/badges/decade/year-90s.png new file mode 100644 index 0000000..429aec2 Binary files /dev/null and b/src/badges/decade/year-90s.png differ diff --git a/src/badges/decade/year-90s@2x.png b/src/badges/decade/year-90s@2x.png new file mode 100644 index 0000000..19ed465 Binary files /dev/null and b/src/badges/decade/year-90s@2x.png differ diff --git a/src/badges/time/time-dinner.png b/src/badges/time/time-dinner.png new file mode 100644 index 0000000..9c23b1a Binary files /dev/null and b/src/badges/time/time-dinner.png differ diff --git a/src/badges/time/time-dinner@2x.png b/src/badges/time/time-dinner@2x.png new file mode 100644 index 0000000..d59b758 Binary files /dev/null and b/src/badges/time/time-dinner@2x.png differ diff --git a/src/badges/time/time-earlybird.png b/src/badges/time/time-earlybird.png new file mode 100644 index 0000000..38bf8b2 Binary files /dev/null and b/src/badges/time/time-earlybird.png differ diff --git a/src/badges/time/time-earlybird@2x.png b/src/badges/time/time-earlybird@2x.png new file mode 100644 index 0000000..34997f6 Binary files /dev/null and b/src/badges/time/time-earlybird@2x.png differ diff --git a/src/badges/time/time-earthday.png b/src/badges/time/time-earthday.png new file mode 100644 index 0000000..ef06084 Binary files /dev/null and b/src/badges/time/time-earthday.png differ diff --git a/src/badges/time/time-earthday@2x.png b/src/badges/time/time-earthday@2x.png new file mode 100644 index 0000000..2b98469 Binary files /dev/null and b/src/badges/time/time-earthday@2x.png differ diff --git a/src/badges/time/time-lunch.png b/src/badges/time/time-lunch.png new file mode 100644 index 0000000..fef590a Binary files /dev/null and b/src/badges/time/time-lunch.png differ diff --git a/src/badges/time/time-lunch@2x.png b/src/badges/time/time-lunch@2x.png new file mode 100644 index 0000000..2f7531a Binary files /dev/null and b/src/badges/time/time-lunch@2x.png differ diff --git a/src/badges/time/time-nightowl.png b/src/badges/time/time-nightowl.png new file mode 100644 index 0000000..3498630 Binary files /dev/null and b/src/badges/time/time-nightowl.png differ diff --git a/src/badges/time/time-nightowl@2x.png b/src/badges/time/time-nightowl@2x.png new file mode 100644 index 0000000..5ab72c9 Binary files /dev/null and b/src/badges/time/time-nightowl@2x.png differ diff --git a/src/badges/workflow/aquatics/wet1.png b/src/badges/workflow/aquatics/wet1.png new file mode 100644 index 0000000..9407cd7 Binary files /dev/null and b/src/badges/workflow/aquatics/wet1.png differ diff --git a/src/badges/workflow/aquatics/wet2.png b/src/badges/workflow/aquatics/wet2.png new file mode 100644 index 0000000..6224e12 Binary files /dev/null and b/src/badges/workflow/aquatics/wet2.png differ diff --git a/src/badges/workflow/aquatics/wet3.png b/src/badges/workflow/aquatics/wet3.png new file mode 100644 index 0000000..6eb9c2a Binary files /dev/null and b/src/badges/workflow/aquatics/wet3.png differ diff --git a/src/badges/workflow/butterfly/butterflies.png b/src/badges/workflow/butterfly/butterflies.png new file mode 100755 index 0000000..93825c0 Binary files /dev/null and b/src/badges/workflow/butterfly/butterflies.png differ diff --git a/src/badges/workflow/butterfly/butterfly.png b/src/badges/workflow/butterfly/butterfly.png new file mode 100644 index 0000000..13b1621 Binary files /dev/null and b/src/badges/workflow/butterfly/butterfly.png differ diff --git a/src/badges/workflow/fossils/paleon1.png b/src/badges/workflow/fossils/paleon1.png new file mode 100644 index 0000000..1eae4b9 Binary files /dev/null and b/src/badges/workflow/fossils/paleon1.png differ diff --git a/src/badges/workflow/fossils/paleon2.png b/src/badges/workflow/fossils/paleon2.png new file mode 100644 index 0000000..2981d8d Binary files /dev/null and b/src/badges/workflow/fossils/paleon2.png differ diff --git a/src/badges/workflow/fossils/paleon3.png b/src/badges/workflow/fossils/paleon3.png new file mode 100644 index 0000000..e58bf29 Binary files /dev/null and b/src/badges/workflow/fossils/paleon3.png differ diff --git a/src/badges/workflow/herbarium/mature-grove.png b/src/badges/workflow/herbarium/mature-grove.png new file mode 100644 index 0000000..d8ee22a Binary files /dev/null and b/src/badges/workflow/herbarium/mature-grove.png differ diff --git a/src/badges/workflow/herbarium/mature-tree.png b/src/badges/workflow/herbarium/mature-tree.png new file mode 100755 index 0000000..75a908f Binary files /dev/null and b/src/badges/workflow/herbarium/mature-tree.png differ diff --git a/src/badges/workflow/herbarium/oak.png b/src/badges/workflow/herbarium/oak.png new file mode 100644 index 0000000..fd7e79a Binary files /dev/null and b/src/badges/workflow/herbarium/oak.png differ diff --git a/src/badges/workflow/herbarium/sapling.png b/src/badges/workflow/herbarium/sapling.png new file mode 100644 index 0000000..5bb5b4e Binary files /dev/null and b/src/badges/workflow/herbarium/sapling.png differ diff --git a/src/badges/workflow/herbarium/seed.png b/src/badges/workflow/herbarium/seed.png new file mode 100644 index 0000000..f33489c Binary files /dev/null and b/src/badges/workflow/herbarium/seed.png differ diff --git a/src/badges/workflow/herbarium/seedling.png b/src/badges/workflow/herbarium/seedling.png new file mode 100644 index 0000000..e598c5a Binary files /dev/null and b/src/badges/workflow/herbarium/seedling.png differ diff --git a/src/badges/workflow/herbarium/tree.png b/src/badges/workflow/herbarium/tree.png new file mode 100644 index 0000000..f14d6f7 Binary files /dev/null and b/src/badges/workflow/herbarium/tree.png differ diff --git a/src/badges/workflow/labs/blossom.png b/src/badges/workflow/labs/blossom.png new file mode 100644 index 0000000..0581f7d Binary files /dev/null and b/src/badges/workflow/labs/blossom.png differ diff --git a/src/badges/workflow/labs/blossoms.png b/src/badges/workflow/labs/blossoms.png new file mode 100644 index 0000000..bde57c8 Binary files /dev/null and b/src/badges/workflow/labs/blossoms.png differ diff --git a/src/badges/workflow/labs/fruit.png b/src/badges/workflow/labs/fruit.png new file mode 100644 index 0000000..87a1a07 Binary files /dev/null and b/src/badges/workflow/labs/fruit.png differ diff --git a/src/badges/workflow/macrofungi/mushroom.png b/src/badges/workflow/macrofungi/mushroom.png new file mode 100755 index 0000000..ab987df Binary files /dev/null and b/src/badges/workflow/macrofungi/mushroom.png differ diff --git a/src/badges/workflow/macrofungi/mycelium.png b/src/badges/workflow/macrofungi/mycelium.png new file mode 100755 index 0000000..7a27710 Binary files /dev/null and b/src/badges/workflow/macrofungi/mycelium.png differ diff --git a/src/badges/workflow/macrofungi/spore.png b/src/badges/workflow/macrofungi/spore.png new file mode 100755 index 0000000..b913c1f Binary files /dev/null and b/src/badges/workflow/macrofungi/spore.png differ diff --git a/src/badges/workflow/magnified/NfN_Parasitoid-02.png b/src/badges/workflow/magnified/NfN_Parasitoid-02.png new file mode 100644 index 0000000..d443353 Binary files /dev/null and b/src/badges/workflow/magnified/NfN_Parasitoid-02.png differ diff --git a/src/badges/workflow/magnified/NfN_Parasitoid-03.png b/src/badges/workflow/magnified/NfN_Parasitoid-03.png new file mode 100644 index 0000000..e0cc7c0 Binary files /dev/null and b/src/badges/workflow/magnified/NfN_Parasitoid-03.png differ diff --git a/src/badges/workflow/magnified/NfN_Parasitoid-04.png b/src/badges/workflow/magnified/NfN_Parasitoid-04.png new file mode 100644 index 0000000..bc9f74e Binary files /dev/null and b/src/badges/workflow/magnified/NfN_Parasitoid-04.png differ diff --git a/src/badges/workflow/pinned_specimen/caterpillar.png b/src/badges/workflow/pinned_specimen/caterpillar.png new file mode 100644 index 0000000..4fc9e58 Binary files /dev/null and b/src/badges/workflow/pinned_specimen/caterpillar.png differ diff --git a/src/badges/workflow/pinned_specimen/egg.png b/src/badges/workflow/pinned_specimen/egg.png new file mode 100644 index 0000000..cded063 Binary files /dev/null and b/src/badges/workflow/pinned_specimen/egg.png differ diff --git a/src/components/App.jsx b/src/components/App.jsx index d109858..5d19b5a 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -12,13 +12,12 @@ import { ProjectProvider, ProjectContext } from '../context/ProjectContext'; import { UserProvider, UserContext } from '../context/UserContext'; import AuthContainer from '../containers/AuthContainer'; +import BadgeContainer from '../containers/BadgeContainer'; import UserHeading from './UserHeading'; import RecentsContainer from '../containers/RecentsContainer'; import FavoritesContainer from '../containers/FavoritesContainer'; import StatsContainer from '../containers/StatsContainer'; -import Title from './Title'; // remove with completion of Badge section - const App = () => ( @@ -58,13 +57,11 @@ const App = () => (
- {matchesUser ? ( - - ) : null} +
)} @@ -72,14 +69,7 @@ const App = () => ( - - Your Badges - + )} diff --git a/src/components/Histogram.jsx b/src/components/Histogram.jsx index 9b227c2..f1f877a 100644 --- a/src/components/Histogram.jsx +++ b/src/components/Histogram.jsx @@ -72,7 +72,7 @@ export default function Histogram({ return ( - Histogram + Weekly Histogram diff --git a/src/containers/BadgeContainer.jsx b/src/containers/BadgeContainer.jsx new file mode 100644 index 0000000..4ca5ce9 --- /dev/null +++ b/src/containers/BadgeContainer.jsx @@ -0,0 +1,113 @@ +import PropTypes from 'prop-types'; +import React from 'react'; +import apiClient from 'panoptes-client'; +import superagent from 'superagent'; +import Box from 'grommet/components/Box'; +import Image from 'grommet/components/Image'; + +import { config } from '../config'; +import badgeIconLegend, { + decade, + time, + workflow +} from '../badges/badge-icon-legend'; +import locationMatch from '../lib/location-match'; +import Title from '../components/Title'; + +import mockData from '../mock-badge-data'; + +class BadgeContainer extends React.Component { + constructor() { + super(); + this.state = { + data: [], + showAllBadges: false + }; + } + + componentDidMount() { + this.fetchBadges(); + } + + componentDidUpdate(prevProps) { + const { explorer } = this.props; + if (prevProps.explorer !== explorer) { + this.fetchBadges(); + } + } + + fetchBadges() { + const showAllBadges = locationMatch(/\W?badges=(\w+)/); + if (showAllBadges === 'all') { + this.setState({ showAllBadges: true }); + } else { + const { explorer } = this.props; + if (explorer && explorer.id) { + this.setState({ data: mockData }); + + const requestUrl = `${config.caesar}/projects/${ + config.projectId + }/users/${explorer.id}/user_reductions`; + + superagent + .get(requestUrl) + .set('Accept', 'application/json') + .set('Content-Type', 'application/json') + .set('Authorization', apiClient.headers.Authorization) + .query() + .then(response => { + if (response.ok && response.body) { + console.log('badge data = ', response.body); + } else { + console.warn('Failed to fetch badge data.'); + } + }) + .catch(() => console.warn('Failed to fetch badge data.')); + } + } + } + + render() { + const { data, showAllBadges } = this.state; + let badgeIcons = []; + + if (showAllBadges) { + badgeIcons = [...decade, ...time, ...workflow]; + } else if (data && data.length) { + data.forEach(badgeData => { + const { reducer_key, subgroup } = badgeData; + const levels = Object.keys(badgeIconLegend[reducer_key][subgroup]); + levels.forEach(level => { + if (badgeData.data.classifications >= level) { + badgeIcons.push(badgeIconLegend[reducer_key][subgroup][level]); + } + }); + }); + } + + return ( + + Your Badges + + {badgeIcons.map(badgeIcon => ( + + + + ))} + + + ); + } +} + +BadgeContainer.propTypes = { + explorer: PropTypes.shape({ + id: PropTypes.string + }) +}; + +BadgeContainer.defaultProps = { + explorer: null +}; + +export default BadgeContainer; diff --git a/src/containers/FavoritesContainer.jsx b/src/containers/FavoritesContainer.jsx index bc616a7..d24578b 100644 --- a/src/containers/FavoritesContainer.jsx +++ b/src/containers/FavoritesContainer.jsx @@ -32,9 +32,9 @@ class FavoritesContainer extends React.Component { } fetchFavoriteSubjects(page = 1) { - const { favoriteCollection, linkedSubjects } = this.props; + const { favoriteCollection, linkedSubjects, matchesUser } = this.props; - if (favoriteCollection && linkedSubjects.length) { + if (matchesUser && favoriteCollection && linkedSubjects.length) { const query = { page, page_size: 3 @@ -42,12 +42,14 @@ class FavoritesContainer extends React.Component { favoriteCollection .get('subjects', query) - .then(favoriteSubjects => - this.setState({ - favoriteSubjects, - meta: favoriteSubjects[0].getMeta() - }) - ) + .then(favoriteSubjects => { + if (favoriteSubjects.length) { + this.setState({ + favoriteSubjects, + meta: favoriteSubjects[0].getMeta() + }); + } + }) .catch(() => { if (console) { console.warn('Failed to fetch favorites'); @@ -88,12 +90,14 @@ FavoritesContainer.propTypes = { favoriteCollection: PropTypes.shape({ id: PropTypes.string }), - linkedSubjects: PropTypes.arrayOf(PropTypes.string) + linkedSubjects: PropTypes.arrayOf(PropTypes.string), + matchesUser: PropTypes.bool }; FavoritesContainer.defaultProps = { favoriteCollection: null, - linkedSubjects: [] + linkedSubjects: [], + matchesUser: false }; export default FavoritesContainer; diff --git a/src/context/ExplorerContext.jsx b/src/context/ExplorerContext.jsx index 5a8d065..a11f0e3 100644 --- a/src/context/ExplorerContext.jsx +++ b/src/context/ExplorerContext.jsx @@ -10,7 +10,7 @@ export class ExplorerProvider extends Component { super(props); this.state = { explorer: null, - matchesUser: true + matchesUser: false }; } @@ -37,7 +37,7 @@ export class ExplorerProvider extends Component { } else if (user) { this.setState({ explorer: user, matchesUser: true }); } else { - this.setState({ explorer: null, matchesUser: true }); + this.setState({ explorer: null, matchesUser: false }); } } diff --git a/src/mock-badge-data.js b/src/mock-badge-data.js new file mode 100644 index 0000000..4905a5f --- /dev/null +++ b/src/mock-badge-data.js @@ -0,0 +1,48 @@ +const data = [ + { + id: 501, + reducer_key: 'decade', + workflow_id: 7389, + user_id: 1405412, + data: { + extracts: 3, + classifications: 3 + }, + subgroup: '90s' + }, + { + id: 502, + reducer_key: 'decade', + workflow_id: 7389, + user_id: 1405412, + data: { + extracts: 20, + classifications: 20 + }, + subgroup: '80s' + }, + { + id: 503, + reducer_key: 'decade', + workflow_id: 7389, + user_id: 1405412, + data: { + extracts: 1, + classifications: 1 + }, + subgroup: '70s' + }, + { + id: 504, + reducer_key: 'workflow_type', + workflow_id: 7389, + user_id: 1405412, + data: { + extracts: 100, + classifications: 100 + }, + subgroup: 'herbarium' + } +]; + +export default data;