Skip to content

Commit 6be0697

Browse files
committed
no need for config
1 parent 51932f3 commit 6be0697

File tree

2 files changed

+12
-88
lines changed

2 files changed

+12
-88
lines changed

src/biorepo_components/BiorepoChecklistsContent.jsx

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,74 +54,36 @@ function renderNode(nodes: any[], depth = 0) {
5454
}
5555

5656
export default function BiorepoChecklistsContent() {
57-
const [config, setConfig] = useState(null);
5857
const [invertebrateNodesData, setInvertebrateNodes] = useState([]);
5958
const [vertebrateNodesData, setVertebrateNodes] = useState([]);
6059
const [plantNodesData, setPlantNodes] = useState([]);
6160

6261
useEffect(() => {
63-
// Fetch configuration from getSymbiniConfig.php
64-
const fetchConfig = async () => {
65-
const basePath = window.location.origin;
66-
const currentPath = window.location.pathname.split('/').slice(0, -1).join('/');
67-
const pathSegments = currentPath.split('/').filter(Boolean);
68-
let clientRootPath = '/';
69-
for (let i = 1; i <= pathSegments.length; i += 1) {
70-
const candidatePath = `/${pathSegments.slice(0, i).join('/')}/neon-react`;
71-
// Check if the resource exists (use HEAD request to test for existence)
72-
const xhr = new XMLHttpRequest();
73-
xhr.open('HEAD', `${basePath}${candidatePath}`, false);
74-
xhr.send();
75-
if (xhr.status === 200) {
76-
clientRootPath = `/${pathSegments.slice(0, i).join('/')}`;
77-
break;
78-
}
79-
}
80-
const fetchUrl = `${basePath}${clientRootPath}/neon-react/biorepo_lib/getSymbiniConfig.php`;
81-
try {
82-
const response = await fetch(fetchUrl);
83-
if (!response.ok) {
84-
throw new Error('Failed to fetch configuration');
85-
}
86-
const data = await response.json();
87-
setConfig(data);
88-
} catch (error) {
89-
console.error('Error fetching configuration:', error);
90-
}
91-
};
92-
93-
fetchConfig();
94-
}, []);
95-
96-
useEffect(() => {
97-
if (!config) return;
98-
fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/checklists-invertebrates.json`)
62+
fetch('../neon-react/biorepo_lib/checklists-invertebrates.json')
9963
.then((response) => response.json())
10064
.then((data) => {
10165
setInvertebrateNodes(data);
10266
})
10367
.catch((error) => console.error('Error loading nodes data:', error));
104-
}, [config]);
68+
}, []);
10569

10670
useEffect(() => {
107-
if (!config) return;
108-
fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/checklists-vertebrates.json`)
71+
fetch('../neon-react/biorepo_lib/checklists-vertebrates.json')
10972
.then((response) => response.json())
11073
.then((data) => {
11174
setVertebrateNodes(data);
11275
})
11376
.catch((error) => console.error('Error loading nodes data:', error));
114-
}, [config]);
77+
}, []);
11578

11679
useEffect(() => {
117-
if (!config) return;
118-
fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/checklists-plants.json`)
80+
fetch('../neon-react/biorepo_lib/checklists-plants.json')
11981
.then((response) => response.json())
12082
.then((data) => {
12183
setPlantNodes(data);
12284
})
12385
.catch((error) => console.error('Error loading nodes data:', error));
124-
}, [config]);
86+
}, []);
12587

12688
return (
12789
<div id="callout-cards">

src/biorepo_components/BiorepoCollectionsContent.jsx

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ function renderNode(nodes: any[], depth = 0) {
8888
}
8989

9090
export default function BiorepoCollectionsContent() {
91-
const [config, setConfig] = useState(null);
9291
const [value, setValue] = React.useState(0);
9392
const [taxonomicNodesData, setTaxonomicNodes] = useState([]);
9493
const [sampletypeNodesData, setSampletypeNodes] = useState([]);
@@ -99,68 +98,31 @@ export default function BiorepoCollectionsContent() {
9998
};
10099

101100
useEffect(() => {
102-
// Fetch configuration from getSymbiniConfig.php
103-
const fetchConfig = async () => {
104-
const basePath = window.location.origin;
105-
const currentPath = window.location.pathname.split('/').slice(0, -1).join('/');
106-
const pathSegments = currentPath.split('/').filter(Boolean);
107-
let clientRootPath = '/';
108-
for (let i = 1; i <= pathSegments.length; i += 1) {
109-
const candidatePath = `/${pathSegments.slice(0, i).join('/')}/neon-react`;
110-
// Check if the resource exists (use HEAD request to test for existence)
111-
const xhr = new XMLHttpRequest();
112-
xhr.open('HEAD', `${basePath}${candidatePath}`, false);
113-
xhr.send();
114-
if (xhr.status === 200) {
115-
clientRootPath = `/${pathSegments.slice(0, i).join('/')}`;
116-
break;
117-
}
118-
}
119-
const fetchUrl = `${basePath}${clientRootPath}/neon-react/biorepo_lib/getSymbiniConfig.php`;
120-
try {
121-
const response = await fetch(fetchUrl);
122-
if (!response.ok) {
123-
throw new Error('Failed to fetch configuration');
124-
}
125-
const data = await response.json();
126-
setConfig(data);
127-
} catch (error) {
128-
console.error('Error fetching configuration:', error);
129-
}
130-
};
131-
132-
fetchConfig();
133-
}, []);
134-
135-
useEffect(() => {
136-
if (!config) return;
137-
fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/collections-taxonomic.json`)
101+
fetch('../../neon-react/biorepo_lib/collections-taxonomic.json')
138102
.then((response) => response.json())
139103
.then((data) => {
140104
setTaxonomicNodes(data);
141105
})
142106
.catch((error) => console.error('Error loading nodes data:', error));
143-
}, [config]);
107+
}, []);
144108

145109
useEffect(() => {
146-
if (!config) return;
147-
fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/collections-sampletype.json`)
110+
fetch('../../neon-react/biorepo_lib/collections-sampletype.json')
148111
.then((response) => response.json())
149112
.then((data) => {
150113
setSampletypeNodes(data);
151114
})
152115
.catch((error) => console.error('Error loading nodes data:', error));
153-
}, [config]);
116+
}, []);
154117

155118
useEffect(() => {
156-
if (!config) return;
157-
fetch(`${config.CLIENT_ROOT}/neon-react/biorepo_lib/collections-protocol.json`)
119+
fetch('../../neon-react/biorepo_lib/collections-protocol.json')
158120
.then((response) => response.json())
159121
.then((data) => {
160122
setProtocolNodes(data);
161123
})
162124
.catch((error) => console.error('Error loading nodes data:', error));
163-
}, [config]);
125+
}, []);
164126

165127
return (
166128
<div>

0 commit comments

Comments
 (0)