-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollectionSwitcher.js
75 lines (69 loc) · 1.83 KB
/
CollectionSwitcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { useContext } from "react";
import Context from "../data/Context";
import Dropdown from "../ui/Dropdown";
const CollectionSwitcher = () => {
const {
collection_id,
collection_ids,
setAPIEndpoint,
setCollectionId,
setCollectionBasePath,
setQueryField,
setQueryString,
setResults,
} = useContext(Context);
const default_api = "https://kosh.uni-koeln.de";
const selectCollection = (e) => {
const uid = e.target.value;
setCollectionId(uid);
document.getElementById("query").value = "";
setQueryString("");
setResults("");
switch (uid) {
case "CDSD":
setAPIEndpoint(default_api);
setCollectionBasePath("cdsd");
setQueryField("headword");
break;
case "Creole":
setAPIEndpoint(default_api);
setCollectionBasePath("creole");
setQueryField("lemma");
break;
case "Freedict":
setAPIEndpoint(default_api);
setCollectionBasePath("freedict");
setQueryField("headword");
break;
case "Kosh Data":
setAPIEndpoint(default_api);
setCollectionBasePath("api");
setQueryField("lemma");
break;
case "MPCD Glossaries":
setAPIEndpoint(default_api);
setCollectionBasePath("mpcd");
setQueryField("trc");
break;
case "C-SALT Sanskrit":
setAPIEndpoint("https://api.c-salt.uni-koeln.de");
setCollectionBasePath("dicts");
setQueryField("headword_slp1");
break;
default:
setAPIEndpoint("");
setCollectionBasePath("api");
setQueryField("lemma");
break;
}
};
return (
<Dropdown
label="Collection: "
items={collection_ids}
preselected={collection_id}
onChange={selectCollection}
/>
);
};
export default CollectionSwitcher;