@imposium-hub/components 1.38.9 → 1.38.10

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": "@imposium-hub/components",
3
- "version": "1.38.9",
3
+ "version": "1.38.10",
4
4
  "description": "React & Typescript component / asset library for Imposium front-ends",
5
5
  "main": "dist/components.js",
6
6
  "scripts": {
@@ -46,6 +46,7 @@
46
46
  "cogo-toast": "^4.2.3",
47
47
  "imposium-js-sdk": "^2.3.1",
48
48
  "js-cookie": "^2.2.1",
49
+ "lodash": "^4.17.21",
49
50
  "react-color": "^2.18.0",
50
51
  "react-merge-refs": "^1.1.0",
51
52
  "react-moveable": "^0.26.1",
@@ -92,6 +93,7 @@
92
93
  "@storybook/react": "^5.3.19",
93
94
  "@types/enzyme": "^3.10.2",
94
95
  "@types/jest": "^24.0.15",
96
+ "@types/lodash": "^4.14.178",
95
97
  "@types/react": "^17.0.3",
96
98
  "axios": "^0.21.1",
97
99
  "babel-loader": "^8.0.2",
@@ -1,5 +1,6 @@
1
1
  import IImposiumAPI from '../../services/API';
2
2
  import {doAssetTableHydration} from './asset-list';
3
+ import {chunk} from 'lodash';
3
4
 
4
5
  const assetUploadsActions : any = {
5
6
  TOGGLE_AUTO_TAG: 'assetUploads/TOGGLE_AUTO_TAG',
@@ -13,13 +14,16 @@ const POLL_INTERVAL : number = 5000;
13
14
 
14
15
  export const toggleAutoTag = (toggle : boolean) : any => ({type: assetUploadsActions.TOGGLE_AUTO_TAG, toggle});
15
16
 
16
- export const toggleAssignToStory = (toggle : boolean) : any => ({type: assetUploadsActions.TOGGLE_ASSIGN_TO_STORY, toggle});
17
+ export const toggleAssignToStory = (toggle : boolean) : any => ({
18
+ type: assetUploadsActions.TOGGLE_ASSIGN_TO_STORY,
19
+ toggle
20
+ });
17
21
 
18
22
  export const uploadAssets = (api : IImposiumAPI, files : File[], storyId : string, bindToOverlay? : (f : any) => any) : any => {
19
23
  return (dispatch, getStore) => {
20
24
  const {assetUploads: {autoTag, uploads, assignToStory}} = getStore();
21
- const sId = (assignToStory && storyId) ? storyId : null;
22
- const processingTimeout : number = -1;
25
+ let currentQueue : number = 0;
26
+ let ongoingJobs : any[] = [];
23
27
 
24
28
  const uploadBlobs : any[] = files.map((file : File) => {
25
29
  const uploadsWithSameName : any[] = uploads.filter((u : any) => (u.filename.includes(file.name)));
@@ -40,51 +44,66 @@ export const uploadAssets = (api : IImposiumAPI, files : File[], storyId : strin
40
44
  return {file, tags, filename, onUploadProgress};
41
45
  });
42
46
 
43
- const uploadPromises : Array<Promise<any | Error>> = uploadBlobs
44
- .map((u : any) => (
45
- api.uploadAsset(sId, u.tags, u.file, u.onUploadProgress)
46
- ));
47
-
48
- Promise.all(uploadPromises)
49
- .then((results : any[]) => {
50
- let ongoingJobs : any[] = results.map((f : any[], i : number) => {
51
- if (bindToOverlay) {
52
- bindToOverlay(f[0]);
53
- }
54
-
55
- return {
56
- footageId: f[0].id,
57
- jobId: f[0].job_id,
58
- onProcessed: () => {
59
- dispatch({
60
- type: assetUploadsActions.REMOVE_UPLOAD,
61
- filename: uploadBlobs[i].filename
62
- });
63
- doAssetTableHydration(api, storyId);
64
- }
65
- };
66
- });
67
-
68
- ongoingJobs = ongoingJobs.filter((j : any, i : number) => {
69
- const jobIdExists : boolean = (typeof j.jobId === 'string');
70
-
71
- if (!jobIdExists) {
72
- dispatch({
73
- type: assetUploadsActions.REMOVE_UPLOAD,
74
- filename: uploadBlobs[i].filename
75
- });
76
- doAssetTableHydration(api, storyId);
77
- }
78
-
79
- return jobIdExists;
80
- });
81
- if (ongoingJobs.length > 0) {
82
- pollAssetJobs(api, ongoingJobs, processingTimeout);
83
- }
84
- })
85
- .catch((e : Error) => {
86
- console.error('Error(s) uploading footage: ', e);
87
- });
47
+ const createPromise = (activeIndex : number) => {
48
+ const queueLength : number = uploadBlobs.length;
49
+ const sId = (assignToStory && storyId) ? storyId : null;
50
+ const processingTimeout : number = -1;
51
+
52
+ api.uploadAsset(
53
+ sId,
54
+ uploadBlobs[activeIndex].tags,
55
+ uploadBlobs[activeIndex].file,
56
+ uploadBlobs[activeIndex].onUploadProgress
57
+ )
58
+ .then((result) => {
59
+ const currentOngoingJobs = () => {
60
+ if (bindToOverlay) {
61
+ bindToOverlay(result[0]);
62
+ }
63
+ return {
64
+ footageId: result[0].id,
65
+ jobId: result[0].job_id,
66
+ filename: uploadBlobs[activeIndex].filename,
67
+ onProcessed: () => {
68
+ const fileName = ongoingJobs.filter((job : any) => job.jobId === result[0].job_id)[0].filename;
69
+ dispatch({
70
+ type: assetUploadsActions.REMOVE_UPLOAD,
71
+ filename: fileName
72
+ });
73
+ doAssetTableHydration(api, storyId);
74
+ }
75
+ };
76
+ };
77
+ ongoingJobs.push(currentOngoingJobs());
78
+ if (currentQueue !== (queueLength - 1)) {
79
+ currentQueue = currentQueue + 1;
80
+ createPromise(currentQueue);
81
+ } else {
82
+ ongoingJobs = ongoingJobs.filter((j : any, i : number) => {
83
+ const jobIdExists : boolean = (typeof j.jobId === 'string');
84
+ if (!jobIdExists) {
85
+ dispatch({
86
+ type: assetUploadsActions.REMOVE_UPLOAD,
87
+ filename: j.filename
88
+ });
89
+ doAssetTableHydration(api, storyId);
90
+ }
91
+ return jobIdExists;
92
+ });
93
+ if (ongoingJobs.length > 0) {
94
+ pollAssetJobs(api, ongoingJobs, processingTimeout);
95
+ }
96
+ }
97
+
98
+ })
99
+ .catch((e : Error[]) => {
100
+ console.error('Error(s) uploading footage: ', e);
101
+ });
102
+ };
103
+ for (let i = 0; i < 5; i++) {
104
+ createPromise(i);
105
+ currentQueue = i;
106
+ }
88
107
  };
89
108
  };
90
109
 
@@ -93,32 +112,32 @@ const pollAssetJobs = (api, ongoingJobs : any[], timeout : number) : void => {
93
112
  const promises : Array<Promise<any | Error>> = ongoingJobs.map((b : any) => (api.getJob(b.jobId)));
94
113
 
95
114
  Promise.all(promises)
96
- .then((ongoingJobResults : any[]) => {
97
- clearTimeout(timeout);
98
- let processedJob : any;
115
+ .then((ongoingJobResults : any[]) => {
116
+ clearTimeout(timeout);
117
+ let processedJob : any;
99
118
 
100
- ongoingJobResults.forEach((ongoingJobResult : any) => {
119
+ ongoingJobResults.forEach((ongoingJobResult : any) => {
101
120
 
102
- if (ongoingJobResult.status === 'processing' || ongoingJobResult.status === 'completed') {
103
- processedJob = ongoingJobs
104
- .find((ongoingJob : any) => (ongoingJob.jobId === ongoingJobResult.id));
121
+ if (ongoingJobResult.status === 'processing' || ongoingJobResult.status === 'completed') {
122
+ processedJob = ongoingJobs
123
+ .find((ongoingJob : any) => (ongoingJob.jobId === ongoingJobResult.id));
105
124
 
106
- if (processedJob) {
107
- processedJob.onProcessed();
108
- ongoingJobs = ongoingJobs
109
- .filter((ongoingJob : any) => (ongoingJob.jobId !== ongoingJobResult.id));
125
+ if (processedJob) {
126
+ processedJob.onProcessed();
127
+ ongoingJobs = ongoingJobs
128
+ .filter((ongoingJob : any) => (ongoingJob.jobId !== ongoingJobResult.id));
129
+ }
110
130
  }
131
+ // TODO: handle errored out
132
+ });
133
+
134
+ if (ongoingJobs.length > 0) {
135
+ pollAssetJobs(api, ongoingJobs, timeout);
111
136
  }
112
- // TODO: handle errored out
137
+ })
138
+ .catch((e : Error[]) => {
139
+ console.error('Failed to poll for processing jobs:', e);
113
140
  });
114
-
115
- if (ongoingJobs.length > 0) {
116
- pollAssetJobs(api, ongoingJobs, timeout);
117
- }
118
- })
119
- .catch((e : Error[]) => {
120
- console.error('Failed to poll for processing jobs:', e);
121
- });
122
141
  }, POLL_INTERVAL);
123
142
  };
124
143