@jsb188/react 1.1.6 → 1.1.8
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/package.json +2 -2
- package/states/index.ts +1 -0
- package/states/modal.ts +1 -1
- package/states/uploads.ts +58 -0
- package/utils/schema.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Contains react (and DOM) related utils and hooks.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"./types/PopOver.d": "./types/PopOver.d.ts"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@jsb188/app": "1.1.
|
|
15
|
+
"@jsb188/app": "1.1.8",
|
|
16
16
|
"jotai": "^2.13.1",
|
|
17
17
|
"react": "^19.1.1"
|
|
18
18
|
},
|
package/states/index.ts
CHANGED
package/states/modal.ts
CHANGED
|
@@ -211,7 +211,7 @@ class ModalPopUp extends ModalScreen {
|
|
|
211
211
|
id: `gql-${errorCode}`,
|
|
212
212
|
iconName: error.iconName || defIconName,
|
|
213
213
|
title: error.title || defTitle || i18n.t('error.error'),
|
|
214
|
-
message: error.message || defMessage || i18n.t('error.
|
|
214
|
+
message: error.message || defMessage || i18n.t('error.unknown_error_msg'),
|
|
215
215
|
...values,
|
|
216
216
|
};
|
|
217
217
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface UploadEntry {
|
|
9
|
+
progress: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type UploadsMap = Record<string, UploadEntry>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Uploads; state
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const uploadsState = atom<UploadsMap>({});
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Export; get uploads state value
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function useUploadsValue() {
|
|
25
|
+
return useAtomValue(uploadsState);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Export; upload state helpers
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export function useUploadActions() {
|
|
33
|
+
const uploads = useAtomValue(uploadsState);
|
|
34
|
+
const setUploads = useSetAtom(uploadsState);
|
|
35
|
+
|
|
36
|
+
const startUploadProgress = useCallback((signedUrl: string) => {
|
|
37
|
+
setUploads((prev) => ({
|
|
38
|
+
...prev,
|
|
39
|
+
[signedUrl]: { progress: 0 },
|
|
40
|
+
}));
|
|
41
|
+
}, [setUploads]);
|
|
42
|
+
|
|
43
|
+
const updateUploadProgress = useCallback((signedUrl: string, progress: number) => {
|
|
44
|
+
setUploads((prev) => ({
|
|
45
|
+
...prev,
|
|
46
|
+
[signedUrl]: { progress },
|
|
47
|
+
}));
|
|
48
|
+
}, [setUploads]);
|
|
49
|
+
|
|
50
|
+
const removeUploadProgress = useCallback((signedUrl: string) => {
|
|
51
|
+
setUploads((prev) => {
|
|
52
|
+
const { [signedUrl]: _, ...rest } = prev;
|
|
53
|
+
return rest;
|
|
54
|
+
});
|
|
55
|
+
}, [setUploads]);
|
|
56
|
+
|
|
57
|
+
return { uploads, startUploadProgress, updateUploadProgress, removeUploadProgress };
|
|
58
|
+
}
|
package/utils/schema.ts
CHANGED