code7-leia 0.1.49 → 0.1.52

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,11 +1,8 @@
1
1
  import React, { useEffect, useState} from 'react';
2
+ import { useDispatch, useSelector } from 'react-redux';
2
3
 
3
4
  import { FaUpload, FaList, FaPlus } from 'react-icons/fa';
4
5
 
5
- // import { formatAxios } from '../../utils/formatAxios'
6
-
7
- import { useLocation } from 'react-router-dom';
8
-
9
6
  import type { FileData } from '../../interface/FileData'
10
7
 
11
8
  import { getLanguage } from '../../utils/getLanguage'
@@ -19,15 +16,18 @@ import ModalContent from './components/Modal/ModalContent'
19
16
  import EmptyState from '../EmptyState';
20
17
  import Select from '../Select'
21
18
  import AreaUpload from './components/AreaUpload';
19
+ import { useSharedProps } from '../../contexts/SharedPropsProvider';
20
+ import { getFilesAction } from '../../store/Files/Files.actions';
22
21
 
23
22
  export const FileArea = () => {
24
23
  const [files, setFiles] = useState<FileData[]>([]);
25
24
  const [initialFiles, setInitialFiles] = useState<FileData[]>([]);
26
25
  const [uploadFile, setUploadFile] = useState<{ content: ArrayBuffer | string; properties: File }>();
27
- const { pathname } = useLocation();
28
26
  const [modal, setModal] = useState(false)
29
- const id = pathname.split('/')[4]
30
- const t = getLanguage('pt-br')
27
+ const { id, language } = useSharedProps();
28
+ const t = getLanguage(language)
29
+ const dispatch = useDispatch();
30
+ const initFiles = useSelector((state: any) => state.initFiles);
31
31
  const tags = [
32
32
  "pae",
33
33
  "boteria",
@@ -37,45 +37,16 @@ export const FileArea = () => {
37
37
  ]
38
38
 
39
39
  useEffect(() => {
40
- setFiles([
41
- {
42
- "name": "Documentação conceitual Code7_v3",
43
- "tags": "boteria, code7"
44
- },
45
- {
46
- "name": "PAE_Programa_Apoio_ao_Empregado",
47
- "tags": "pae, vr"
48
- },
49
- {
50
- "name": "Vidalink",
51
- "tags": "vidalink, vr"
52
- },
53
- {
54
- "name": "[GUIA PRÁTICO] Como criar o chatbot perfeito",
55
- "tags": "ebook, code7"
56
- }
57
- ])
58
-
59
- setInitialFiles([
60
- {
61
- "name": "Documentação conceitual Code7_v3",
62
- "tags": "boteria, code7"
63
- },
64
- {
65
- "name": "PAE_Programa_Apoio_ao_Empregado",
66
- "tags": "pae, vr"
67
- },
68
- {
69
- "name": "Vidalink",
70
- "tags": "vidalink, vr"
71
- },
72
- {
73
- "name": "[GUIA PRÁTICO] Como criar o chatbot perfeito",
74
- "tags": "ebook, code7"
75
- }
76
- ])
40
+ dispatch(getFilesAction(id))
77
41
  }, [])
78
42
 
43
+ useEffect(() => {
44
+ setFiles(initFiles)
45
+ setInitialFiles(initFiles)
46
+ }, [initFiles])
47
+
48
+
49
+
79
50
  useEffect(() => {
80
51
  console.log('files, id, t: ', files, id, t)
81
52
  }, [files])
@@ -0,0 +1,29 @@
1
+ import React, { createContext, useContext } from 'react';
2
+
3
+ interface Props {
4
+ id: string;
5
+ language: "en" | "pt-br" | "es";
6
+ children?: React.ReactNode;
7
+ }
8
+
9
+ interface SharedPropsContextType {
10
+ props: Props;
11
+ }
12
+
13
+ const SharedPropsContext = createContext<SharedPropsContextType | undefined>(undefined);
14
+
15
+ export const useSharedProps = () => {
16
+ const context = useContext(SharedPropsContext);
17
+ if (!context) {
18
+ throw new Error('useSharedProps deve ser usado dentro de um SharedPropsProvider');
19
+ }
20
+ return context.props;
21
+ };
22
+
23
+ export const SharedPropsProvider: React.FC<Props> = ({ children, ...props }) => {
24
+ return (
25
+ <SharedPropsContext.Provider value={{ props }}>
26
+ {children}
27
+ </SharedPropsContext.Provider>
28
+ );
29
+ };
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+
3
+ export const API_TOKEN = 'API_TOKEN';
4
+
5
+ const url = process.env.REACT_APP_API_URL || 'http://localhost:5000/';
6
+
7
+ axios.defaults.baseURL = `${url}/`;
8
+
9
+ export default axios.create();
@@ -0,0 +1,8 @@
1
+ import api from '../Api'
2
+ import { FileData } from '../../interface/FileData'
3
+
4
+ export const getFiles = async (id: string) => {
5
+ const files:[FileData] = await api.get(`/files/${id}`)
6
+
7
+ return files
8
+ }
@@ -0,0 +1,8 @@
1
+ import { getFiles } from '../../service/Files/Files';
2
+
3
+ export function getFilesAction (id: string) {
4
+ return {
5
+ type: 'GET_FILES',
6
+ payload: getFiles(id)
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ export default function (state = [], action: any) {
2
+ switch (action.type) {
3
+ case 'GET_FILES':
4
+ return action.payload;
5
+ default:
6
+ return state;
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ import { createStore, combineReducers, applyMiddleware } from 'redux';
2
+ import reduxPromise from 'redux-promise';
3
+ import FilesReducer from './Files/Files.reducer';
4
+ import { FileData } from '../interface/FileData'
5
+
6
+ const rootReducer = combineReducers({
7
+ files: FilesReducer as unknown as [FileData],
8
+ });
9
+
10
+ const store = createStore(rootReducer, applyMiddleware(reduxPromise));
11
+
12
+ export default store;