@imerss/inat-components 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PUBLISH.md +13 -0
- package/README.md +20 -0
- package/dist/index.d.ts +118 -73
- package/dist/index.js +322 -389
- package/dist/standalone.min.js +3 -0
- package/package.json +17 -5
- package/public/standalone.html +55 -0
- package/rollup.config.js +15 -4
- package/src/__shared/api/common-taxa.ts +3 -3
- package/src/__shared/api/favourites.ts +6 -11
- package/src/__shared/api/recent-observations.ts +3 -3
- package/src/__shared/api/summary.ts +1 -0
- package/src/__shared/constants.ts +3 -1
- package/src/__shared/index.ts +1 -1
- package/src/__shared/typings.ts +58 -44
- package/src/__shared/utils/configUtils.ts +10 -6
- package/src/__shared/utils/dateUtils.ts +1 -1
- package/src/components/common-taxa/common-taxa.tsx +34 -60
- package/src/components/error/error.tsx +1 -1
- package/src/components/favourites/favourites.tsx +35 -60
- package/src/components/hooks/hooks.tsx +20 -10
- package/src/components/loader/loader.tsx +1 -1
- package/src/components/observation/observation.tsx +5 -4
- package/src/components/recent-observations/recent-observations.tsx +43 -60
- package/src/components/shared/css/general.module.scss +5 -1
- package/src/components/summary/ObserverList.tsx +21 -15
- package/src/components/summary/summary.tsx +59 -51
- package/src/components/tabs/tabs.tsx +48 -27
- package/src/components/taxon-panel/taxon-panel.tsx +83 -77
- package/src/components/year-dropdown/year-dropdown.tsx +11 -7
- package/src/hooks/useLoadSourceData.ts +81 -0
- package/src/index.ts +1 -1
- package/src/types/index.d.ts +17 -0
- package/src/types/standalone.d.ts +6 -0
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imerss/inat-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"build": "rollup -c",
|
|
8
|
+
"build": "rollup -c --environment BUILD:production && cd ../inat-components-standalone && npm run build && npm run copyToInatComponentsPackage",
|
|
9
|
+
"clean": "shx rm -rf dist src/__shared",
|
|
8
10
|
"watch": "rollup -cw"
|
|
9
11
|
},
|
|
10
12
|
"dependencies": {
|
|
@@ -14,23 +16,33 @@
|
|
|
14
16
|
"sleep-promise": "^9.1.0"
|
|
15
17
|
},
|
|
16
18
|
"peerDependencies": {
|
|
17
|
-
"react": ">=
|
|
18
|
-
"react-dom": ">=
|
|
19
|
+
"react": ">=18.0.0",
|
|
20
|
+
"react-dom": ">=18.0.0"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"@modular-css/rollup": "^28.2.2",
|
|
22
24
|
"@rollup/plugin-typescript": "^8.3.3",
|
|
25
|
+
"@rollup/plugin-commonjs": "^24.1.0",
|
|
26
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
28
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
23
29
|
"@testing-library/react": "^13.3.0",
|
|
24
30
|
"@types/cli-progress": "^3.11.0",
|
|
31
|
+
"@types/isomorphic-fetch": "0.0.36",
|
|
25
32
|
"@types/jest": "^28.1.4",
|
|
33
|
+
"@types/react": "^18.0.38",
|
|
34
|
+
"@types/react-dom": "^18.0.5",
|
|
26
35
|
"jest": "^28.1.2",
|
|
27
36
|
"node-sass": "^7.0.1",
|
|
28
37
|
"postcss": "^8.4.14",
|
|
29
38
|
"react-charts": "3.0.0-beta.38",
|
|
30
|
-
"rollup": "^2.
|
|
39
|
+
"rollup": "^2.79.1",
|
|
31
40
|
"rollup-plugin-dts": "^4.2.2",
|
|
32
41
|
"rollup-plugin-postcss": "^4.0.2",
|
|
42
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
43
|
+
"rollup-plugin-visualizer": "^5.9.0",
|
|
33
44
|
"tslib": "^2.4.0",
|
|
45
|
+
"shx": "0.3.4",
|
|
34
46
|
"typescript": "^4.7.4"
|
|
35
47
|
},
|
|
36
48
|
"publishConfig": {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<body>
|
|
3
|
+
|
|
4
|
+
<h1>Standalone example</h1>
|
|
5
|
+
|
|
6
|
+
<div id="inat-components-el"></div>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
inatComponents.initTaxonPanel("inat-components-el", {
|
|
10
|
+
taxon: {
|
|
11
|
+
id: 47157,
|
|
12
|
+
str: "leps"
|
|
13
|
+
},
|
|
14
|
+
place: {
|
|
15
|
+
id: 7085,
|
|
16
|
+
str: "bc"
|
|
17
|
+
},
|
|
18
|
+
dataSource: "url",
|
|
19
|
+
dataSourceBaseUrl: "https://sisyphean.ca/inat",
|
|
20
|
+
itemWidth: 180,
|
|
21
|
+
features: {
|
|
22
|
+
recentObservations: {
|
|
23
|
+
numResults: 100,
|
|
24
|
+
desc: "This page lists the most recent butterfly and moth observations made in BC. Click on any of them to go to the inaturalist site for more information.",
|
|
25
|
+
},
|
|
26
|
+
commonTaxa: {
|
|
27
|
+
numResults: 100,
|
|
28
|
+
numYears: 10,
|
|
29
|
+
desc: "This page lists the most commonly reported species in BC. You can use the dropdown at the top right to filter the results to a particular year."
|
|
30
|
+
},
|
|
31
|
+
favourites: {
|
|
32
|
+
numResults: 100,
|
|
33
|
+
numYears: 10,
|
|
34
|
+
desc: "Any time iNaturalist users encounter an observation they like, they can choose to \"favourite\" it. This page lists the most favourited moth and butterfly observations made in BC."
|
|
35
|
+
},
|
|
36
|
+
stats: {
|
|
37
|
+
numTopObservers: 10,
|
|
38
|
+
observersListClass: "inat-observers-list",
|
|
39
|
+
statsCountSummaryClass: "inat-stats-count-summary",
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
generalClasses: {
|
|
43
|
+
tabsElement: "inat-tabs",
|
|
44
|
+
yearsDropdown: "inat-years-dropdown",
|
|
45
|
+
pageHeadings: "inat-page-headings",
|
|
46
|
+
observationLabelTitle: "inat-observation-label-title",
|
|
47
|
+
observationLabelDate: "inat-observation-label-data",
|
|
48
|
+
observationLabelName: "inat-observation-label-name",
|
|
49
|
+
tabDesc: "inat-tab-desc"
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
</body>
|
|
55
|
+
</html>
|
package/rollup.config.js
CHANGED
|
@@ -3,6 +3,7 @@ import postcss from "rollup-plugin-postcss";
|
|
|
3
3
|
import dts from "rollup-plugin-dts";
|
|
4
4
|
|
|
5
5
|
export default [
|
|
6
|
+
|
|
6
7
|
// front-end components + generate() node utils method, exposed as "@imerss/inat-components"
|
|
7
8
|
{
|
|
8
9
|
input: "src/index.ts",
|
|
@@ -10,8 +11,18 @@ export default [
|
|
|
10
11
|
dir: "dist",
|
|
11
12
|
format: "es"
|
|
12
13
|
},
|
|
14
|
+
|
|
15
|
+
// these let's rollup know that these are external scripts + can be excluded from the final bundle without
|
|
16
|
+
// any warnings. TODO: check these are peer deps.
|
|
13
17
|
external: [
|
|
14
|
-
"react"
|
|
18
|
+
"react",
|
|
19
|
+
"fs",
|
|
20
|
+
"react-charts",
|
|
21
|
+
"date-fns",
|
|
22
|
+
"react-spinners",
|
|
23
|
+
"react-spinners/MoonLoader.js",
|
|
24
|
+
"isomorphic-unfetch",
|
|
25
|
+
"react/jsx-runtime"
|
|
15
26
|
],
|
|
16
27
|
plugins: [
|
|
17
28
|
postcss({
|
|
@@ -19,10 +30,10 @@ export default [
|
|
|
19
30
|
plugins: []
|
|
20
31
|
}),
|
|
21
32
|
typescript()
|
|
22
|
-
]
|
|
33
|
+
],
|
|
23
34
|
},
|
|
24
35
|
|
|
25
|
-
//
|
|
36
|
+
// rolls up all typings for export
|
|
26
37
|
{
|
|
27
38
|
input: "src/index.ts",
|
|
28
39
|
output: {
|
|
@@ -33,4 +44,4 @@ export default [
|
|
|
33
44
|
dts()
|
|
34
45
|
]
|
|
35
46
|
}
|
|
36
|
-
];
|
|
47
|
+
];
|
|
@@ -5,7 +5,7 @@ export type CommonTaxaCallProps = {
|
|
|
5
5
|
year: string | number;
|
|
6
6
|
taxonId: string | number;
|
|
7
7
|
placeId: string | number;
|
|
8
|
-
|
|
8
|
+
numResults: number;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export type CommonTaxData = {
|
|
@@ -21,8 +21,8 @@ export type CommonTaxaRespData = {
|
|
|
21
21
|
results: [CommonTaxData]
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export const getCommonTaxa = async ({ year, taxonId, placeId,
|
|
25
|
-
let url = `${C.BASE_API_URL}/v1/observations/species_counts?verifiable=true&spam=false&place_id=${placeId}&taxon_id=${taxonId}&locale=en-US&per_page=${
|
|
24
|
+
export const getCommonTaxa = async ({ year, taxonId, placeId, numResults }: CommonTaxaCallProps): Promise<CommonTaxaRespData> => {
|
|
25
|
+
let url = `${C.BASE_API_URL}/v1/observations/species_counts?verifiable=true&spam=false&place_id=${placeId}&taxon_id=${taxonId}&locale=en-US&per_page=${numResults}`;
|
|
26
26
|
if (year !== "all") {
|
|
27
27
|
url += `&d1=${year}-01-01&d2=${year}-12-31`;
|
|
28
28
|
}
|
|
@@ -5,7 +5,7 @@ export type FavouritesCallProps = {
|
|
|
5
5
|
year: string | number;
|
|
6
6
|
taxonId: string | number;
|
|
7
7
|
placeId: string | number;
|
|
8
|
-
|
|
8
|
+
numResults: number;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export type FavouritesData = {
|
|
@@ -24,20 +24,15 @@ export type FavouritesRespData = {
|
|
|
24
24
|
results: [FavouritesData]
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const getFavourites = async ({ year, taxonId, placeId,
|
|
28
|
-
let url = `${C.BASE_API_URL}/v1/observations?verifiable=true&order_by=votes&order=desc&page=1&spam=false&place_id=${placeId}&taxon_id=${taxonId}&locale=en-US&per_page=${
|
|
27
|
+
export const getFavourites = async ({ year, taxonId, placeId, numResults }: FavouritesCallProps): Promise<FavouritesRespData> => {
|
|
28
|
+
let url = `${C.BASE_API_URL}/v1/observations?verifiable=true&order_by=votes&order=desc&page=1&spam=false&place_id=${placeId}&taxon_id=${taxonId}&locale=en-US&per_page=${numResults}`;
|
|
29
29
|
if (year !== "all") {
|
|
30
30
|
url += `&d1=${year}-01-01&d2=${year}-12-31`;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const response = await fetch(url
|
|
34
|
-
// method: 'GET',
|
|
35
|
-
// headers: {
|
|
36
|
-
// Accept: 'application/json'
|
|
37
|
-
// }
|
|
38
|
-
});
|
|
39
|
-
|
|
33
|
+
const response = await fetch(url);
|
|
40
34
|
const resp = await response.json();
|
|
35
|
+
|
|
41
36
|
const sortedTaxa = resp.results.filter((i: any) => i.faves.length > 0).sort((a: any, b: any) => {
|
|
42
37
|
if (a.faves.length > b.faves.length) {
|
|
43
38
|
return -1;
|
|
@@ -51,7 +46,7 @@ export const getFavourites = async ({ year, taxonId, placeId, perPage }: Favouri
|
|
|
51
46
|
totalResults: resp.total_results,
|
|
52
47
|
results: sortedTaxa.map((row: any) => ({
|
|
53
48
|
id: row.id,
|
|
54
|
-
imageUrl: row.
|
|
49
|
+
imageUrl: row.observation_photos[0].photo.url || "",
|
|
55
50
|
obsDate: row.observed_on_string,
|
|
56
51
|
obsUrl: row.uri,
|
|
57
52
|
taxonName: row.taxon.name || "",
|
|
@@ -4,7 +4,7 @@ import * as C from "../constants";
|
|
|
4
4
|
export type RecentObservationsCallProps = {
|
|
5
5
|
taxonId: string | number;
|
|
6
6
|
placeId: string | number;
|
|
7
|
-
|
|
7
|
+
numResults: number;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export type RecentObservationData = {
|
|
@@ -22,8 +22,8 @@ export type RecentObservationsRespData = {
|
|
|
22
22
|
results: [RecentObservationData]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const getRecentObservations = async ({ taxonId, placeId,
|
|
26
|
-
const url = `${C.BASE_API_URL}/v1/observations?photos=true&per_page=${
|
|
25
|
+
export const getRecentObservations = async ({ taxonId, placeId, numResults }: RecentObservationsCallProps): Promise<RecentObservationsRespData> => {
|
|
26
|
+
const url = `${C.BASE_API_URL}/v1/observations?photos=true&per_page=${numResults}&taxon_id=${taxonId}&place_id=${placeId}&order=desc&order_by=observed_on`;
|
|
27
27
|
const response = await fetch(url);
|
|
28
28
|
const obs = await response.json();
|
|
29
29
|
|
|
@@ -32,6 +32,7 @@ export type SummaryData = {
|
|
|
32
32
|
|
|
33
33
|
export const getObserverSummary = async (taxonId: number, placeId: number, year: string | number): Promise<SummaryData> => {
|
|
34
34
|
let url = `${C.BASE_API_URL}/v1/observations/observers?verifiable=true&order_by=votes&order=desc&page=1&spam=false&place_id=${placeId}&taxon_id=${taxonId}&locale=en-US&per_page=10`;
|
|
35
|
+
|
|
35
36
|
if (year !== "all") {
|
|
36
37
|
url += `&d1=${year}-01-01&d2=${year}-12-31`;
|
|
37
38
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export const BASE_API_URL = 'https://api.inaturalist.org';
|
|
2
|
-
export const
|
|
2
|
+
export const NUM_RESULTS = 100;
|
|
3
|
+
export const DEFAULT_NUM_YEARS = 10;
|
|
3
4
|
export const BASE_URL = "https://www.inaturalist.org"; // /people/name_here
|
|
4
5
|
export const ERROR_LOG_FILENAME = "inat-components-error.log";
|
|
6
|
+
export const DEFAULT_ITEM_WIDTH = 150;
|
package/src/__shared/index.ts
CHANGED
package/src/__shared/typings.ts
CHANGED
|
@@ -1,69 +1,83 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
numResults?: number;
|
|
7
|
-
};
|
|
8
|
-
[Feature.favourites]?: {
|
|
9
|
-
numResults?: number;
|
|
10
|
-
numYears?: number;
|
|
11
|
-
};
|
|
12
|
-
[Feature.recentObservations]?: {
|
|
13
|
-
numResults?: number;
|
|
14
|
-
numYears?: number;
|
|
15
|
-
};
|
|
16
|
-
[Feature.stats]?: {
|
|
17
|
-
numTopObservers?: number;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
1
|
+
export enum Feature {
|
|
2
|
+
commonTaxa = "commonTaxa",
|
|
3
|
+
favourites = "favourites",
|
|
4
|
+
recentObservations = "recentObservations",
|
|
5
|
+
stats = "stats"
|
|
20
6
|
}
|
|
21
7
|
|
|
22
|
-
export enum
|
|
8
|
+
export enum DataSourceEnum {
|
|
23
9
|
autoLoad = "autoLoad",
|
|
24
|
-
dataProp = "dataProp",
|
|
25
10
|
url = "url"
|
|
26
11
|
}
|
|
27
12
|
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
export type DataSource = `${DataSourceEnum}`;
|
|
14
|
+
|
|
15
|
+
// used for places + taxons
|
|
16
|
+
export type ItemConfig = {
|
|
17
|
+
id: number;
|
|
18
|
+
str: string;
|
|
33
19
|
}
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
export type GeneralClasses = {
|
|
22
|
+
tabsElement?: string;
|
|
23
|
+
yearsDropdown?: string;
|
|
24
|
+
pageHeadings?: string;
|
|
25
|
+
tabDesc?: string;
|
|
26
|
+
observationLabelTitle?: string;
|
|
27
|
+
observationLabelDate?: string;
|
|
28
|
+
observationLabelName?: string;
|
|
29
|
+
observationCount?: string;
|
|
41
30
|
}
|
|
42
31
|
|
|
43
32
|
export type BaseComponentProps = {
|
|
44
33
|
taxonId?: number;
|
|
45
34
|
placeId?: number;
|
|
46
|
-
|
|
47
|
-
perPage?: number;
|
|
35
|
+
numResults?: number;
|
|
48
36
|
source?: DataSource;
|
|
49
|
-
data?: any;
|
|
50
37
|
dataUrl?: string;
|
|
51
38
|
className?: string;
|
|
39
|
+
itemWidth?: number;
|
|
52
40
|
components?: {
|
|
53
41
|
label?: any;
|
|
54
42
|
error?: any;
|
|
55
43
|
loader?: any;
|
|
56
44
|
};
|
|
45
|
+
generalClasses?: GeneralClasses;
|
|
46
|
+
tabDesc?: string;
|
|
57
47
|
};
|
|
58
48
|
|
|
59
|
-
export type
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
export type RecentObservationsConfig = {
|
|
50
|
+
feature: Feature.recentObservations,
|
|
51
|
+
title?: string;
|
|
52
|
+
numResults?: number;
|
|
53
|
+
desc?: string;
|
|
54
|
+
className?: string;
|
|
55
|
+
}
|
|
56
|
+
export type CommonTaxaConfig = {
|
|
57
|
+
feature: Feature.commonTaxa,
|
|
58
|
+
title?: string;
|
|
59
|
+
numResults?: number;
|
|
60
|
+
numYears?: number;
|
|
61
|
+
desc?: string;
|
|
62
|
+
className?: string;
|
|
63
|
+
}
|
|
64
|
+
export type FavouritesConfig = {
|
|
65
|
+
feature: Feature.favourites;
|
|
66
|
+
title?: string;
|
|
67
|
+
numResults?: number;
|
|
68
|
+
numYears?: number;
|
|
69
|
+
desc?: string;
|
|
70
|
+
className?: string;
|
|
63
71
|
}
|
|
72
|
+
export type StatsConfig = {
|
|
73
|
+
feature: Feature.stats;
|
|
74
|
+
title?: string;
|
|
75
|
+
numTopObservers?: number;
|
|
76
|
+
numYears?: number;
|
|
77
|
+
desc?: string;
|
|
78
|
+
className?: string;
|
|
79
|
+
observersListClass?: string;
|
|
80
|
+
statsCountSummaryClass?: string;
|
|
81
|
+
};
|
|
64
82
|
|
|
65
|
-
export type
|
|
66
|
-
label: string;
|
|
67
|
-
short: string;
|
|
68
|
-
placeId: number;
|
|
69
|
-
}
|
|
83
|
+
export type TaxonPanelFeatures = (RecentObservationsConfig|CommonTaxaConfig|FavouritesConfig|StatsConfig)[];
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
import {Feature,
|
|
1
|
+
import { Feature, ItemConfig } from "../typings";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Note that right now the source filenames aren't configurable.
|
|
5
5
|
*/
|
|
6
|
-
export const getSourceFile = (api: Feature,
|
|
6
|
+
export const getSourceFile = (api: Feature, taxon: ItemConfig, place: ItemConfig, year?: string | number): string => {
|
|
7
|
+
if (!taxon || !place) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
const yearStr = year === "all" ? "allyears" : year;
|
|
8
12
|
|
|
9
13
|
let filename = "";
|
|
10
14
|
if (api === Feature.recentObservations) {
|
|
11
|
-
filename = `${
|
|
15
|
+
filename = `${taxon.str}-${place.str}-recent.json`;
|
|
12
16
|
} else if (api === Feature.commonTaxa) {
|
|
13
|
-
filename = `${
|
|
17
|
+
filename = `${taxon.str}-${place.str}-${yearStr}-commonTaxa.json`;
|
|
14
18
|
} else if (api === Feature.favourites) {
|
|
15
|
-
filename = `${
|
|
19
|
+
filename = `${taxon.str}-${place.str}-${yearStr}-favourites.json`;
|
|
16
20
|
} else if (api === Feature.stats) {
|
|
17
|
-
filename = `${
|
|
21
|
+
filename = `${taxon.str}-${place.str}-${yearStr}-stats.json`;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
return filename;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {numberWithCommas, C, CommonTaxData, getCommonTaxa, BaseComponentProps,
|
|
3
|
-
import {Observation} from "../observation/observation";
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { numberWithCommas, C, CommonTaxData, getCommonTaxa, BaseComponentProps, GeneralClasses } from "../../__shared";
|
|
3
|
+
import { Observation } from "../observation/observation";
|
|
4
4
|
import Loader from "../loader/loader";
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
5
|
+
import { NoResults } from "../no-results/no-results";
|
|
6
|
+
import { useLoadSourceData } from "../../hooks/useLoadSourceData";
|
|
7
7
|
import styles from "../shared/css/general.module.scss";
|
|
8
8
|
|
|
9
9
|
export type CommonTaxaProps = BaseComponentProps & {
|
|
10
|
-
year:
|
|
10
|
+
year: number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const CommonTaxaLabel = (data: CommonTaxData) => (
|
|
13
|
+
export const CommonTaxaLabel = (data: CommonTaxData & { classes: GeneralClasses }) => (
|
|
14
14
|
<div className={styles.obsLabel}>
|
|
15
|
-
<h3>{data.taxonCommonName || data.taxonName}</h3>
|
|
16
|
-
<label className={styles.count}>{numberWithCommas(data.obsCount)}</label>
|
|
15
|
+
<h3 className={data.classes?.observationLabelTitle}>{data.taxonCommonName || data.taxonName}</h3>
|
|
16
|
+
<label className={`${data.classes?.observationCount || ''} ${styles.count}`}>{numberWithCommas(data.obsCount)}</label>
|
|
17
17
|
</div>
|
|
18
18
|
);
|
|
19
19
|
|
|
@@ -22,75 +22,49 @@ export const CommonTaxa = ({
|
|
|
22
22
|
source,
|
|
23
23
|
taxonId,
|
|
24
24
|
placeId,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
numResults = C.NUM_RESULTS,
|
|
26
|
+
itemWidth = C.DEFAULT_ITEM_WIDTH,
|
|
27
27
|
dataUrl,
|
|
28
28
|
components,
|
|
29
|
-
|
|
29
|
+
generalClasses,
|
|
30
|
+
className,
|
|
31
|
+
tabDesc
|
|
30
32
|
}: CommonTaxaProps) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!placeId) {
|
|
43
|
-
console.error("Please supply a `placeId` prop for the `autoLoad` source prop option.");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
(async () => {
|
|
48
|
-
setLoading(true);
|
|
49
|
-
const resp = await getCommonTaxa({taxonId, placeId, year, perPage});
|
|
50
|
-
setTaxa(resp.results);
|
|
51
|
-
setLoading(false);
|
|
52
|
-
})();
|
|
53
|
-
}, [source, year, placeId, taxonId, perPage]);
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (source !== DataSource.url) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!dataUrl) {
|
|
61
|
-
console.error("Please supply a `dataUrl` prop for the `url` source prop option.");
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
(async () => {
|
|
66
|
-
setLoading(true);
|
|
67
|
-
const obs = await fetch(dataUrl);
|
|
68
|
-
const json = await obs.json();
|
|
69
|
-
setTaxa(json.results);
|
|
70
|
-
setLoading(false);
|
|
71
|
-
})();
|
|
72
|
-
}, [source, dataUrl]);
|
|
33
|
+
const { loading, results: taxa } = useLoadSourceData({
|
|
34
|
+
taxonId,
|
|
35
|
+
placeId,
|
|
36
|
+
numResults,
|
|
37
|
+
dataUrl,
|
|
38
|
+
source,
|
|
39
|
+
year,
|
|
40
|
+
action: getCommonTaxa
|
|
41
|
+
});
|
|
73
42
|
|
|
74
43
|
const Load = components?.loader ? components.loader as any : Loader;
|
|
75
44
|
const Label = components?.label ? components.label as any : CommonTaxaLabel;
|
|
76
|
-
const ErrorMsg = components?.error ? components.error as any : Error;
|
|
77
45
|
|
|
78
|
-
let
|
|
46
|
+
let elClasses = styles.panel;
|
|
79
47
|
if (className) {
|
|
80
|
-
|
|
48
|
+
elClasses += ` ${className}`;
|
|
49
|
+
}
|
|
50
|
+
let descClasses = styles.tabDesc;
|
|
51
|
+
if (generalClasses?.tabDesc) {
|
|
52
|
+
descClasses += ` ${generalClasses.tabDesc}`;
|
|
81
53
|
}
|
|
82
54
|
|
|
83
55
|
return (
|
|
84
|
-
<div className={
|
|
56
|
+
<div className={elClasses}>
|
|
57
|
+
{tabDesc && <p className={descClasses}>{tabDesc}</p>}
|
|
85
58
|
<Load loading={loading}/>
|
|
86
59
|
{!loading && taxa.length === 0 && <NoResults/>}
|
|
87
|
-
<div className={styles.grid}>
|
|
60
|
+
<div className={styles.grid} style={{ gridTemplateColumns: `repeat(auto-fit, minmax(${itemWidth}px, 1fr))` }}>
|
|
88
61
|
{taxa.map((data: CommonTaxData) => (
|
|
89
62
|
<Observation
|
|
90
63
|
key={data.id}
|
|
91
64
|
imageUrl={data.imageUrl.replace(/square/, "medium")}
|
|
65
|
+
itemWidth={itemWidth}
|
|
92
66
|
linkUrl={`${C.BASE_URL}/${data.id}`}>
|
|
93
|
-
<Label {...data} />
|
|
67
|
+
<Label {...data} classes={generalClasses} />
|
|
94
68
|
</Observation>
|
|
95
69
|
))}
|
|
96
70
|
</div>
|