code7-leia 0.1.49 → 0.1.53

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,5 +1,6 @@
1
- import React, { forwardRef, useRef, useCallback, useEffect, useState, useMemo, Suspense } from 'react';
2
- import { useLocation, useRouteMatch, useHistory, Switch, Route } from 'react-router-dom';
1
+ import React, { forwardRef, useRef, useCallback, useEffect, useState, createContext, useContext, useMemo, Suspense } from 'react';
2
+ import { useRouteMatch, useLocation, useHistory, Switch, Route } from 'react-router-dom';
3
+ import { useDispatch, useSelector, Provider } from 'react-redux';
3
4
  import PropTypes from 'prop-types';
4
5
  import cc from 'classcat';
5
6
  import styled from 'styled-components';
@@ -7,8 +8,342 @@ import { FaSearch, FaUpload, FaList, FaPlus, FaMicrophone } from 'react-icons/fa
7
8
  import unorm from 'unorm';
8
9
  import { MdClose, MdPerson2 } from 'react-icons/md';
9
10
  import { useDropzone } from 'react-dropzone';
11
+ import axios from 'axios';
10
12
  import { PiWaveformBold } from 'react-icons/pi';
13
+ import { createStore, applyMiddleware, combineReducers } from 'redux';
14
+ import reduxPromise from 'redux-promise';
11
15
 
16
+ function _regeneratorRuntime() {
17
+ _regeneratorRuntime = function () {
18
+ return e;
19
+ };
20
+ var t,
21
+ e = {},
22
+ r = Object.prototype,
23
+ n = r.hasOwnProperty,
24
+ o = Object.defineProperty || function (t, e, r) {
25
+ t[e] = r.value;
26
+ },
27
+ i = "function" == typeof Symbol ? Symbol : {},
28
+ a = i.iterator || "@@iterator",
29
+ c = i.asyncIterator || "@@asyncIterator",
30
+ u = i.toStringTag || "@@toStringTag";
31
+ function define(t, e, r) {
32
+ return Object.defineProperty(t, e, {
33
+ value: r,
34
+ enumerable: !0,
35
+ configurable: !0,
36
+ writable: !0
37
+ }), t[e];
38
+ }
39
+ try {
40
+ define({}, "");
41
+ } catch (t) {
42
+ define = function (t, e, r) {
43
+ return t[e] = r;
44
+ };
45
+ }
46
+ function wrap(t, e, r, n) {
47
+ var i = e && e.prototype instanceof Generator ? e : Generator,
48
+ a = Object.create(i.prototype),
49
+ c = new Context(n || []);
50
+ return o(a, "_invoke", {
51
+ value: makeInvokeMethod(t, r, c)
52
+ }), a;
53
+ }
54
+ function tryCatch(t, e, r) {
55
+ try {
56
+ return {
57
+ type: "normal",
58
+ arg: t.call(e, r)
59
+ };
60
+ } catch (t) {
61
+ return {
62
+ type: "throw",
63
+ arg: t
64
+ };
65
+ }
66
+ }
67
+ e.wrap = wrap;
68
+ var h = "suspendedStart",
69
+ l = "suspendedYield",
70
+ f = "executing",
71
+ s = "completed",
72
+ y = {};
73
+ function Generator() {}
74
+ function GeneratorFunction() {}
75
+ function GeneratorFunctionPrototype() {}
76
+ var p = {};
77
+ define(p, a, function () {
78
+ return this;
79
+ });
80
+ var d = Object.getPrototypeOf,
81
+ v = d && d(d(values([])));
82
+ v && v !== r && n.call(v, a) && (p = v);
83
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
84
+ function defineIteratorMethods(t) {
85
+ ["next", "throw", "return"].forEach(function (e) {
86
+ define(t, e, function (t) {
87
+ return this._invoke(e, t);
88
+ });
89
+ });
90
+ }
91
+ function AsyncIterator(t, e) {
92
+ function invoke(r, o, i, a) {
93
+ var c = tryCatch(t[r], t, o);
94
+ if ("throw" !== c.type) {
95
+ var u = c.arg,
96
+ h = u.value;
97
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
98
+ invoke("next", t, i, a);
99
+ }, function (t) {
100
+ invoke("throw", t, i, a);
101
+ }) : e.resolve(h).then(function (t) {
102
+ u.value = t, i(u);
103
+ }, function (t) {
104
+ return invoke("throw", t, i, a);
105
+ });
106
+ }
107
+ a(c.arg);
108
+ }
109
+ var r;
110
+ o(this, "_invoke", {
111
+ value: function (t, n) {
112
+ function callInvokeWithMethodAndArg() {
113
+ return new e(function (e, r) {
114
+ invoke(t, n, e, r);
115
+ });
116
+ }
117
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
118
+ }
119
+ });
120
+ }
121
+ function makeInvokeMethod(e, r, n) {
122
+ var o = h;
123
+ return function (i, a) {
124
+ if (o === f) throw new Error("Generator is already running");
125
+ if (o === s) {
126
+ if ("throw" === i) throw a;
127
+ return {
128
+ value: t,
129
+ done: !0
130
+ };
131
+ }
132
+ for (n.method = i, n.arg = a;;) {
133
+ var c = n.delegate;
134
+ if (c) {
135
+ var u = maybeInvokeDelegate(c, n);
136
+ if (u) {
137
+ if (u === y) continue;
138
+ return u;
139
+ }
140
+ }
141
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
142
+ if (o === h) throw o = s, n.arg;
143
+ n.dispatchException(n.arg);
144
+ } else "return" === n.method && n.abrupt("return", n.arg);
145
+ o = f;
146
+ var p = tryCatch(e, r, n);
147
+ if ("normal" === p.type) {
148
+ if (o = n.done ? s : l, p.arg === y) continue;
149
+ return {
150
+ value: p.arg,
151
+ done: n.done
152
+ };
153
+ }
154
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
155
+ }
156
+ };
157
+ }
158
+ function maybeInvokeDelegate(e, r) {
159
+ var n = r.method,
160
+ o = e.iterator[n];
161
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
162
+ var i = tryCatch(o, e.iterator, r.arg);
163
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
164
+ var a = i.arg;
165
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
166
+ }
167
+ function pushTryEntry(t) {
168
+ var e = {
169
+ tryLoc: t[0]
170
+ };
171
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
172
+ }
173
+ function resetTryEntry(t) {
174
+ var e = t.completion || {};
175
+ e.type = "normal", delete e.arg, t.completion = e;
176
+ }
177
+ function Context(t) {
178
+ this.tryEntries = [{
179
+ tryLoc: "root"
180
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
181
+ }
182
+ function values(e) {
183
+ if (e || "" === e) {
184
+ var r = e[a];
185
+ if (r) return r.call(e);
186
+ if ("function" == typeof e.next) return e;
187
+ if (!isNaN(e.length)) {
188
+ var o = -1,
189
+ i = function next() {
190
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
191
+ return next.value = t, next.done = !0, next;
192
+ };
193
+ return i.next = i;
194
+ }
195
+ }
196
+ throw new TypeError(typeof e + " is not iterable");
197
+ }
198
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
199
+ value: GeneratorFunctionPrototype,
200
+ configurable: !0
201
+ }), o(GeneratorFunctionPrototype, "constructor", {
202
+ value: GeneratorFunction,
203
+ configurable: !0
204
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
205
+ var e = "function" == typeof t && t.constructor;
206
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
207
+ }, e.mark = function (t) {
208
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
209
+ }, e.awrap = function (t) {
210
+ return {
211
+ __await: t
212
+ };
213
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
214
+ return this;
215
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
216
+ void 0 === i && (i = Promise);
217
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
218
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
219
+ return t.done ? t.value : a.next();
220
+ });
221
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
222
+ return this;
223
+ }), define(g, "toString", function () {
224
+ return "[object Generator]";
225
+ }), e.keys = function (t) {
226
+ var e = Object(t),
227
+ r = [];
228
+ for (var n in e) r.push(n);
229
+ return r.reverse(), function next() {
230
+ for (; r.length;) {
231
+ var t = r.pop();
232
+ if (t in e) return next.value = t, next.done = !1, next;
233
+ }
234
+ return next.done = !0, next;
235
+ };
236
+ }, e.values = values, Context.prototype = {
237
+ constructor: Context,
238
+ reset: function (e) {
239
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
240
+ },
241
+ stop: function () {
242
+ this.done = !0;
243
+ var t = this.tryEntries[0].completion;
244
+ if ("throw" === t.type) throw t.arg;
245
+ return this.rval;
246
+ },
247
+ dispatchException: function (e) {
248
+ if (this.done) throw e;
249
+ var r = this;
250
+ function handle(n, o) {
251
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
252
+ }
253
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
254
+ var i = this.tryEntries[o],
255
+ a = i.completion;
256
+ if ("root" === i.tryLoc) return handle("end");
257
+ if (i.tryLoc <= this.prev) {
258
+ var c = n.call(i, "catchLoc"),
259
+ u = n.call(i, "finallyLoc");
260
+ if (c && u) {
261
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
262
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
263
+ } else if (c) {
264
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
265
+ } else {
266
+ if (!u) throw new Error("try statement without catch or finally");
267
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
268
+ }
269
+ }
270
+ }
271
+ },
272
+ abrupt: function (t, e) {
273
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
274
+ var o = this.tryEntries[r];
275
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
276
+ var i = o;
277
+ break;
278
+ }
279
+ }
280
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
281
+ var a = i ? i.completion : {};
282
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
283
+ },
284
+ complete: function (t, e) {
285
+ if ("throw" === t.type) throw t.arg;
286
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
287
+ },
288
+ finish: function (t) {
289
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
290
+ var r = this.tryEntries[e];
291
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
292
+ }
293
+ },
294
+ catch: function (t) {
295
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
296
+ var r = this.tryEntries[e];
297
+ if (r.tryLoc === t) {
298
+ var n = r.completion;
299
+ if ("throw" === n.type) {
300
+ var o = n.arg;
301
+ resetTryEntry(r);
302
+ }
303
+ return o;
304
+ }
305
+ }
306
+ throw new Error("illegal catch attempt");
307
+ },
308
+ delegateYield: function (e, r, n) {
309
+ return this.delegate = {
310
+ iterator: values(e),
311
+ resultName: r,
312
+ nextLoc: n
313
+ }, "next" === this.method && (this.arg = t), y;
314
+ }
315
+ }, e;
316
+ }
317
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
318
+ try {
319
+ var info = gen[key](arg);
320
+ var value = info.value;
321
+ } catch (error) {
322
+ reject(error);
323
+ return;
324
+ }
325
+ if (info.done) {
326
+ resolve(value);
327
+ } else {
328
+ Promise.resolve(value).then(_next, _throw);
329
+ }
330
+ }
331
+ function _asyncToGenerator(fn) {
332
+ return function () {
333
+ var self = this,
334
+ args = arguments;
335
+ return new Promise(function (resolve, reject) {
336
+ var gen = fn.apply(self, args);
337
+ function _next(value) {
338
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
339
+ }
340
+ function _throw(err) {
341
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
342
+ }
343
+ _next(undefined);
344
+ });
345
+ };
346
+ }
12
347
  function _extends() {
13
348
  _extends = Object.assign ? Object.assign.bind() : function (target) {
14
349
  for (var i = 1; i < arguments.length; i++) {
@@ -562,7 +897,7 @@ var getColor = function getColor(props) {
562
897
  }
563
898
  return '#979aa5';
564
899
  };
565
- var Container$3 = /*#__PURE__*/styled.div(_templateObject$7 || (_templateObject$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: #f3f5f9;\n flex: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 20px;\n border-width: 2px;\n border-radius: 4px;\n border-color: var(", ");\n border-style: dashed;\n color: #5a5d68;\n outline: none;\n transition: border 0.24s ease-in-out;\n\n & > span {\n margin: 8px 10px 0 0;\n display: flex;\n }\n"])), function (props) {
900
+ var Container$3 = /*#__PURE__*/styled.div(_templateObject$7 || (_templateObject$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: #f3f5f9;\n flex: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n padding: 20px;\n border-width: 2px;\n border-radius: 4px;\n border-color: var(", ");\n border-style: dashed;\n color: #5a5d68;\n outline: none;\n transition: border 0.24s ease-in-out;\n\n & > span {\n margin: 8px 10px 0 0;\n display: flex;\n }\n\n button {\n padding: 8px 16px 8px 16px;\n border-radius: 4px;\n border: 2px #102693 solid;\n margin-top: 10px;\n }\n"])), function (props) {
566
901
  return getColor(props);
567
902
  });
568
903
 
@@ -653,6 +988,58 @@ AreaUpload.defaultProps = {
653
988
  hasListFiles: true
654
989
  };
655
990
 
991
+ var _excluded$5 = ["children"];
992
+ var SharedPropsContext = /*#__PURE__*/createContext(undefined);
993
+ var useSharedProps = function useSharedProps() {
994
+ var context = useContext(SharedPropsContext);
995
+ if (!context) {
996
+ throw new Error('useSharedProps deve ser usado dentro de um SharedPropsProvider');
997
+ }
998
+ return context.props;
999
+ };
1000
+ var SharedPropsProvider = function SharedPropsProvider(_ref) {
1001
+ var children = _ref.children,
1002
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$5);
1003
+ return React.createElement(SharedPropsContext.Provider, {
1004
+ value: {
1005
+ props: props
1006
+ }
1007
+ }, children);
1008
+ };
1009
+
1010
+ var url = process.env.REACT_APP_API_URL || 'http://localhost:5000/';
1011
+ axios.defaults.baseURL = url + "/";
1012
+ var api = /*#__PURE__*/axios.create();
1013
+
1014
+ var getFiles = /*#__PURE__*/function () {
1015
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
1016
+ var files;
1017
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1018
+ while (1) switch (_context.prev = _context.next) {
1019
+ case 0:
1020
+ _context.next = 2;
1021
+ return api.get("/files/" + id);
1022
+ case 2:
1023
+ files = _context.sent;
1024
+ return _context.abrupt("return", files);
1025
+ case 4:
1026
+ case "end":
1027
+ return _context.stop();
1028
+ }
1029
+ }, _callee);
1030
+ }));
1031
+ return function getFiles(_x) {
1032
+ return _ref.apply(this, arguments);
1033
+ };
1034
+ }();
1035
+
1036
+ function getFilesAction(id) {
1037
+ return {
1038
+ type: 'GET_FILES',
1039
+ payload: getFiles(id)
1040
+ };
1041
+ }
1042
+
656
1043
  var FileArea = function FileArea() {
657
1044
  var _useState = useState([]),
658
1045
  files = _useState[0],
@@ -663,42 +1050,25 @@ var FileArea = function FileArea() {
663
1050
  var _useState3 = useState(),
664
1051
  uploadFile = _useState3[0],
665
1052
  setUploadFile = _useState3[1];
666
- var _useLocation = useLocation(),
667
- pathname = _useLocation.pathname;
668
1053
  var _useState4 = useState(false),
669
1054
  modal = _useState4[0],
670
1055
  setModal = _useState4[1];
671
- var id = pathname.split('/')[4];
672
- var t = getLanguage('pt-br');
1056
+ var _useSharedProps = useSharedProps(),
1057
+ id = _useSharedProps.id,
1058
+ language = _useSharedProps.language;
1059
+ var t = getLanguage(language);
1060
+ var dispatch = useDispatch();
1061
+ var initFiles = useSelector(function (state) {
1062
+ return state.initFiles;
1063
+ });
673
1064
  var tags = ["pae", "boteria", "vr", "code7", "vidalink"];
674
1065
  useEffect(function () {
675
- setFiles([{
676
- "name": "Documentação conceitual Code7_v3",
677
- "tags": "boteria, code7"
678
- }, {
679
- "name": "PAE_Programa_Apoio_ao_Empregado",
680
- "tags": "pae, vr"
681
- }, {
682
- "name": "Vidalink",
683
- "tags": "vidalink, vr"
684
- }, {
685
- "name": "[GUIA PRÁTICO] Como criar o chatbot perfeito",
686
- "tags": "ebook, code7"
687
- }]);
688
- setInitialFiles([{
689
- "name": "Documentação conceitual Code7_v3",
690
- "tags": "boteria, code7"
691
- }, {
692
- "name": "PAE_Programa_Apoio_ao_Empregado",
693
- "tags": "pae, vr"
694
- }, {
695
- "name": "Vidalink",
696
- "tags": "vidalink, vr"
697
- }, {
698
- "name": "[GUIA PRÁTICO] Como criar o chatbot perfeito",
699
- "tags": "ebook, code7"
700
- }]);
1066
+ dispatch(getFilesAction(id));
701
1067
  }, []);
1068
+ useEffect(function () {
1069
+ setFiles(initFiles);
1070
+ setInitialFiles(initFiles);
1071
+ }, [initFiles]);
702
1072
  useEffect(function () {
703
1073
  console.log('files, id, t: ', files, id, t);
704
1074
  }, [files]);
@@ -901,6 +1271,23 @@ var TestArea = function TestArea() {
901
1271
  }, results.message)));
902
1272
  };
903
1273
 
1274
+ function FilesReducer (state, action) {
1275
+ if (state === void 0) {
1276
+ state = [];
1277
+ }
1278
+ switch (action.type) {
1279
+ case 'GET_FILES':
1280
+ return action.payload;
1281
+ default:
1282
+ return state;
1283
+ }
1284
+ }
1285
+
1286
+ var rootReducer = /*#__PURE__*/combineReducers({
1287
+ files: FilesReducer
1288
+ });
1289
+ var store = /*#__PURE__*/createStore(rootReducer, /*#__PURE__*/applyMiddleware(reduxPromise));
1290
+
904
1291
  var Leia = function Leia(props) {
905
1292
  var match = useRouteMatch();
906
1293
  var _useLocation = useLocation(),
@@ -910,7 +1297,9 @@ var Leia = function Leia(props) {
910
1297
  var activeTab = useMemo(function () {
911
1298
  return pathname.split('/')[5] || 'files';
912
1299
  }, [pathname]);
913
- return React.createElement(React.Fragment, null, React.createElement(Tabs, {
1300
+ return React.createElement(Provider, {
1301
+ store: store
1302
+ }, React.createElement(SharedPropsProvider, Object.assign({}, props), React.createElement(React.Fragment, null, React.createElement(Tabs, {
914
1303
  value: activeTab,
915
1304
  onChange: function onChange(value) {
916
1305
  return history.push(match.url + "/" + value);
@@ -931,7 +1320,7 @@ var Leia = function Leia(props) {
931
1320
  }), React.createElement(Route, {
932
1321
  path: match.path + "/test",
933
1322
  component: TestArea
934
- }))));
1323
+ }))))));
935
1324
  };
936
1325
 
937
1326
  function Code7(props) {