@onehat/ui 0.3.134 → 0.3.136

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.134",
3
+ "version": "0.3.136",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -6,7 +6,7 @@ import {
6
6
  } from 'native-base';
7
7
  import {
8
8
  EDITOR_TYPE__WINDOWED,
9
- } from '@onehat/ui/src/Constants/Editor.js';
9
+ } from '../../../../Constants/Editor.js';
10
10
  import withAlert from '../../../Hoc/withAlert.js';
11
11
  import withComponent from '../../../Hoc/withComponent.js';
12
12
  import withData from '../../../Hoc/withData.js';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  EDITOR_TYPE__SIDE,
3
- } from '@onehat/ui/src/Constants/Editor.js';
3
+ } from '../../../Constants/Editor.js';
4
4
  import Container from '../../Container/Container.js';
5
5
  import withSecondaryEditor from './withSecondaryEditor.js';
6
6
  import _ from 'lodash';
@@ -11,7 +11,7 @@ import FormPanel from '../Panel/FormPanel.js';
11
11
  import inArray from '../../Functions/inArray.js';
12
12
  import Pdf from '../Icons/Pdf.js';
13
13
  import useAdjustedWindowSize from '../../Hooks/useAdjustedWindowSize.js';
14
- import { EDITOR_TYPE__PLAIN } from '@onehat/ui/src/Constants/Editor.js';
14
+ import { EDITOR_TYPE__PLAIN } from '../../Constants/Editor.js';
15
15
  import UiGlobals from '../../UiGlobals.js';
16
16
  import _ from 'lodash';
17
17
 
@@ -5,6 +5,7 @@ import {
5
5
  Column,
6
6
  Pressable,
7
7
  Row,
8
+ Spinner,
8
9
  Text,
9
10
  } from 'native-base';
10
11
  import {
@@ -18,8 +19,9 @@ import {
18
19
  FILE_MODE_FILE,
19
20
  } from '../../Constants/File.js';
20
21
  import { Avatar, Dropzone, FileMosaic, FileCard, FileInputButton, } from "@files-ui/react";
21
- import IconButton from '@onehat/ui/src/Components/Buttons/IconButton.js';
22
- import Xmark from '@onehat/ui/src/Components/Icons/Xmark.js'
22
+ import inArray from '../../Functions/inArray.js';
23
+ import IconButton from '../../Components/Buttons/IconButton.js';
24
+ import Xmark from '../../Components/Icons/Xmark.js'
23
25
  import withAlert from '../../Components/Hoc/withAlert.js';
24
26
  import withData from '../../Components/Hoc/withData.js';
25
27
  import _ from 'lodash';
@@ -49,7 +51,9 @@ function FileCardCustom(props) {
49
51
  type: mimetype,
50
52
  onDelete,
51
53
  downloadUrl,
52
- } = props;
54
+ uploadStatus,
55
+ } = props,
56
+ isDownloading = uploadStatus && inArray(uploadStatus, ['preparing', 'uploading', 'success']);
53
57
  return <Pressable
54
58
  px={3}
55
59
  py={1}
@@ -62,8 +66,9 @@ function FileCardCustom(props) {
62
66
  downloadWithFetch(downloadUrl);
63
67
  }}
64
68
  >
69
+ {isDownloading && <Spinner mr={2} />}
65
70
  <Text>{filename}</Text>
66
- <IconButton icon={Xmark} onPress={() => onDelete(id)} />
71
+ {onDelete && <IconButton ml={1} icon={Xmark} onPress={() => onDelete(id)} />}
67
72
  </Pressable>;
68
73
  }
69
74
 
@@ -95,6 +100,7 @@ function AttachmentsElement(props) {
95
100
  Repository,
96
101
 
97
102
  // withAlert
103
+ alert,
98
104
  confirm,
99
105
 
100
106
  } = props,
@@ -136,6 +142,10 @@ function AttachmentsElement(props) {
136
142
  setShowAll(!showAll);
137
143
  },
138
144
  onDropzoneChange = (files) => {
145
+ if (!files.length) {
146
+ alert('No files accepted. Perhaps they were too large or the wrong file type?');
147
+ return;
148
+ }
139
149
  setFiles(files);
140
150
  _.each(files, (file) => {
141
151
  file.extraUploadData = {
@@ -148,7 +158,8 @@ function AttachmentsElement(props) {
148
158
  setIsUploading(true);
149
159
  },
150
160
  onUploadFinish = (files) => {
151
- let isDoneUploading = true;
161
+ let isDoneUploading = true,
162
+ isError = false;
152
163
 
153
164
  _.each(files, (file) => {
154
165
  if (!file.xhr || file.xhr.status !== 200) {
@@ -158,8 +169,18 @@ function AttachmentsElement(props) {
158
169
  });
159
170
 
160
171
  if (isDoneUploading) {
161
- setIsUploading(false);
162
- Repository.reload();
172
+ _.each(files, (file) => {
173
+ if (file.uploadStatus === 'error') {
174
+ isError = true;
175
+ const msg = file.serverResponse?.payload || 'An error occurred';
176
+ alert(msg);
177
+ return false;
178
+ }
179
+ });
180
+ if (!isError) {
181
+ setIsUploading(false);
182
+ Repository.reload();
183
+ }
163
184
  }
164
185
  },
165
186
  onFileDelete = (id) => {
@@ -278,7 +299,7 @@ function AttachmentsElement(props) {
278
299
  {Repository.total <= COLLAPSED_MAX ? null :
279
300
  <Button
280
301
  onPress={toggleShowAll}
281
- marginTop={4}
302
+ mt={4}
282
303
  _text={{
283
304
  color: 'trueGray.600',
284
305
  fontStyle: 'italic',