@overmap-ai/forms 1.0.14 → 1.0.15

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.
@@ -1 +1 @@
1
- export declare const convertKilobytesToLargestUnit: (kilobytes: number) => string;
1
+ export declare const convertBytesToLargestUnit: (bytes: number) => string;
package/dist/forms.js CHANGED
@@ -1173,17 +1173,17 @@ const previewImage = "_previewImage_1ig84_1";
1173
1173
  const styles$2 = {
1174
1174
  previewImage
1175
1175
  };
1176
- const convertKilobytesToLargestUnit = (kilobytes) => {
1177
- const units = ["kilobyte", "megabyte"];
1178
- let sizeInUnit = kilobytes;
1176
+ const convertBytesToLargestUnit = (bytes) => {
1177
+ const units = ["byte", "kilobyte", "megabyte"];
1178
+ let sizeInUnit = bytes;
1179
1179
  let unitIndex = 0;
1180
- while (sizeInUnit > 1024 && unitIndex < units.length - 1) {
1181
- sizeInUnit /= 1024;
1180
+ while (sizeInUnit > 1e3 && unitIndex < units.length - 1) {
1181
+ sizeInUnit /= 1e3;
1182
1182
  unitIndex++;
1183
1183
  }
1184
1184
  const formatter = new Intl.NumberFormat([], {
1185
- // 0 for kilobytes, 1 for megabytes
1186
- maximumFractionDigits: unitIndex,
1185
+ maximumFractionDigits: Math.max(0, unitIndex - 1),
1186
+ // 0 for bytes and kilobytes, 1 for megabytes
1187
1187
  style: "unit",
1188
1188
  unit: units[unitIndex]
1189
1189
  });
@@ -1267,7 +1267,7 @@ const DisplayFile = memo(function DisplayFile2({ file, field, onRemove, disabled
1267
1267
  }
1268
1268
  if (resolvedFile) {
1269
1269
  name2 = resolvedFile.name;
1270
- size2 = convertKilobytesToLargestUnit(resolvedFile.size);
1270
+ size2 = convertBytesToLargestUnit(resolvedFile.size);
1271
1271
  } else {
1272
1272
  name2 = "Downloading...";
1273
1273
  size2 = "...";
@@ -1276,7 +1276,7 @@ const DisplayFile = memo(function DisplayFile2({ file, field, onRemove, disabled
1276
1276
  }, [resolvedFile]);
1277
1277
  useEffect(() => {
1278
1278
  if (file instanceof Promise) {
1279
- file.then(setResolvedFile);
1279
+ file.then(setResolvedFile).catch(console.error);
1280
1280
  } else {
1281
1281
  setResolvedFile(file);
1282
1282
  }
@@ -1602,11 +1602,7 @@ const FormSubmissionViewer = memo(
1602
1602
  const attachments = selectSubmissionAttachments(submission.offline_id)(sdk.store.getState()) ?? [];
1603
1603
  const downloadedAttachments = {};
1604
1604
  for (const attachment of attachments) {
1605
- const promise = sdk.files.fetchFileFromUrl(attachment.file, attachment.file_sha1, attachment.file_name).then((response) => {
1606
- if (!response.success)
1607
- throw new Error(`Failed to download attachment ${attachment.file_name}.`);
1608
- return response.body;
1609
- });
1605
+ const promise = sdk.files.fetchFileFromUrl(attachment.file, attachment.file_sha1, attachment.file_name);
1610
1606
  const fieldAttachments = downloadedAttachments[attachment.field_identifier];
1611
1607
  if (fieldAttachments) {
1612
1608
  fieldAttachments.push(promise);