gbs-add-block 0.0.12 → 0.0.13

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": "gbs-add-block",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "React Component Library",
5
5
  "files": [
6
6
  "index.js",
@@ -6,8 +6,8 @@
6
6
  */
7
7
 
8
8
  import React, { useState, useRef, useEffect } from "react";
9
- import { upload, x } from "../../icon/iconPaths";
10
- import Icon from "../../icon/Icon";
9
+ import { upload, x } from "@/src/component-lib/icon/iconPaths";
10
+ import Icon from "@/src/component-lib/icon/Icon";
11
11
  import { GetFileIcon } from "./uploaderIcon";
12
12
  import AestheticProcessingAnimationWithStyles from "./ProgressAnimation";
13
13
 
@@ -163,6 +163,7 @@ export const FileUploader = ({
163
163
  {fileSizeErrors.map((error, index) => (
164
164
  <span key={index} className="text-xs text-red-500">
165
165
  {error}
166
+ <br />
166
167
  </span>
167
168
  ))}
168
169
  </div>
@@ -17,29 +17,54 @@ function processFiles(files: File[], chunkSize: number) {
17
17
  return finalFiles;
18
18
  }
19
19
 
20
- // Converts large files to chunks to send over network and sends
21
20
  export async function sendFiles(
22
21
  files: File[],
23
22
  chunkSize: number,
24
23
  apiUrl = "http://localhost:8080/upload"
25
24
  ) {
26
25
  const processedFiles = processFiles(files, chunkSize);
27
- const totalChunks = processedFiles.length;
26
+
27
+ // Track how many chunks belong to the current file being processed
28
+ const fileChunkCounts: { [key: string]: number } = {};
29
+ files.forEach((file) => {
30
+ fileChunkCounts[file.name] = Math.ceil(file.size / chunkSize);
31
+ });
32
+
33
+ // To track chunk index per file
34
+ const chunkIndexTracker: { [key: string]: number } = {};
28
35
 
29
36
  for (let i = 0; i < processedFiles.length; i++) {
30
37
  const { file, originalFile } = processedFiles[i];
31
38
  const formData = new FormData();
32
39
  formData.append("file", file, originalFile.name);
33
40
  formData.append("originalname", originalFile.name);
41
+ formData.append("originalFileSize", originalFile.size.toString());
34
42
 
35
- if (file.size > chunkSize) {
36
- formData.append("chunkIndex", i.toString());
37
- formData.append("totalChunks", totalChunks.toString());
38
- } else {
39
- formData.append("chunkIndex", "0");
40
- formData.append("totalChunks", "1");
43
+ const chunkCount = fileChunkCounts[originalFile.name];
44
+ const isChunked = chunkCount > 1;
45
+
46
+ // Initialize or reset chunkIndex per file
47
+ if (!chunkIndexTracker[originalFile.name]) {
48
+ chunkIndexTracker[originalFile.name] = 0; // Start at 0 for each file
41
49
  }
42
50
 
51
+ const chunkIndex = isChunked
52
+ ? chunkIndexTracker[originalFile.name].toString()
53
+ : "";
54
+ formData.append("chunkIndex", chunkIndex);
55
+ formData.append("totalChunks", isChunked ? chunkCount.toString() : "");
56
+
57
+ // Increment chunkIndex for the current file
58
+ if (isChunked) {
59
+ chunkIndexTracker[originalFile.name]++;
60
+ }
61
+
62
+ // Don't Remove the following console
63
+ // console.log("FormData contents:");
64
+ // formData.forEach((value, key) => {
65
+ // console.log(`${key}: ${value}`);
66
+ // });
67
+
43
68
  try {
44
69
  const response = await fetch(apiUrl, {
45
70
  method: "POST",
@@ -57,7 +82,9 @@ export async function sendFiles(
57
82
  `File uploaded successfully. Document ID: ${data.documentId}`
58
83
  );
59
84
  } else {
60
- console.log(`Chunk ${i + 1}/${totalChunks} uploaded`);
85
+ console.log(
86
+ `Chunk ${chunkIndexTracker[originalFile.name]}/${chunkCount} uploaded`
87
+ );
61
88
  }
62
89
  } catch (error) {
63
90
  console.error("Error uploading file chunk:", error);
@@ -1,12 +1,23 @@
1
1
  import React from "react";
2
2
 
3
3
  type SvgElement = {
4
- type: "path" | "circle";
4
+ type: "path" | "circle" | "polyline" | "rect" | "line";
5
5
  key: string;
6
6
  d?: string;
7
7
  cx?: number;
8
8
  cy?: number;
9
9
  r?: number;
10
+ points?: string;
11
+ x?: number;
12
+ y?: number;
13
+ width?: number;
14
+ height?: number;
15
+ rx?: number;
16
+ ry?: number;
17
+ x1?: number;
18
+ y1?: number;
19
+ x2?: number;
20
+ y2?: number;
10
21
  };
11
22
 
12
23
  type IconProps = {
@@ -21,6 +32,18 @@ export default function Icon({
21
32
  { type: "path", d: "m11 17-5-5 5-5", key: "13zhaf" },
22
33
  { type: "path", d: "m18 17-5-5 5-5", key: "h8a8et" },
23
34
  { type: "circle", cx: 12, cy: 12, r: 5, key: "circle1" },
35
+ { type: "polyline", points: "20 6 12 13 4 6", key: "polyline1" },
36
+ {
37
+ type: "rect",
38
+ x: 4,
39
+ y: 4,
40
+ width: 16,
41
+ height: 16,
42
+ key: "rect1",
43
+ rx: 2,
44
+ ry: 2,
45
+ },
46
+ { type: "line", x1: 0, y1: 0, x2: 24, y2: 24, key: "line1" }, // Example line
24
47
  ],
25
48
  dimensions = { width: "24", height: "24" },
26
49
  }: IconProps) {
@@ -47,6 +70,30 @@ export default function Icon({
47
70
  key={element.key}
48
71
  />
49
72
  );
73
+ } else if (element.type === "polyline") {
74
+ return <polyline points={element.points} key={element.key} />;
75
+ } else if (element.type === "rect") {
76
+ return (
77
+ <rect
78
+ x={element.x}
79
+ y={element.y}
80
+ width={element.width}
81
+ height={element.height}
82
+ rx={element.rx}
83
+ ry={element.ry}
84
+ key={element.key}
85
+ />
86
+ );
87
+ } else if (element.type === "line") {
88
+ return (
89
+ <line
90
+ x1={element.x1}
91
+ y1={element.y1}
92
+ x2={element.x2}
93
+ y2={element.y2}
94
+ key={element.key}
95
+ />
96
+ );
50
97
  }
51
98
  return null;
52
99
  })}