@opencloning/ui 1.3.3 → 1.4.1

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.
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import getHttpClient from '@opencloning/utils/getHttpClient';
3
+ import { useConfig } from '../providers';
4
+ import useRequestForEffect from './useRequestForEffect';
5
+
6
+
7
+ export const localFilesHttpClient = getHttpClient([]);
8
+
9
+ function sequencesToCategories(sequences) {
10
+ const allCategories = sequences
11
+ .map((s) => s.categories)
12
+ .flat()
13
+ .filter(Boolean);
14
+ return Array.from(new Set(allCategories)).sort((a, b) => a.localeCompare(b));
15
+ }
16
+ export default function useServerStaticFiles() {
17
+ const [index, setIndex] = React.useState(null);
18
+
19
+ const config = useConfig();
20
+ const httpClient = localFilesHttpClient;
21
+ const staticContentPath = `${import.meta.env.BASE_URL}${config.staticContentPath}`;
22
+
23
+ const requestFunction = React.useCallback(async () => {
24
+ const resp = await httpClient.get(`${staticContentPath}/index.json`);
25
+ return resp.data;
26
+ }, [staticContentPath, httpClient]);
27
+
28
+ const onSuccess = React.useCallback((data) => {
29
+ const sequences = !data.sequences ? [] : data.sequences;
30
+ const syntaxes = !data.syntaxes ? [] : data.syntaxes;
31
+ const categories = sequencesToCategories(sequences);
32
+ setIndex({ sequences, syntaxes, categories });
33
+ }, []);
34
+
35
+ const { requestStatus: indexRequestStatus, retry: indexRetry } = useRequestForEffect({ requestFunction, onSuccess });
36
+
37
+ const requestFile = React.useCallback(async (path) => {
38
+ const resp = await httpClient.get(`${staticContentPath}/${path}`);
39
+ return resp.data;
40
+ }, [staticContentPath, httpClient]);
41
+
42
+ return React.useMemo(() => (
43
+ !staticContentPath ? null :
44
+ {
45
+ index,
46
+ indexRequestStatus,
47
+ indexRetry,
48
+ requestFile
49
+ }),
50
+ [
51
+ index,
52
+ indexRequestStatus,
53
+ indexRetry,
54
+ requestFile,
55
+ staticContentPath]);
56
+ }
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Version placeholder - replaced at publish time via prepack script
2
- export const version = "1.3.3";
2
+ export const version = "1.4.1";