이승윤

Merge branch 'feat/elasticsearch' into 'develop'

Feat/elasticsearch



See merge request !12
...@@ -22,4 +22,6 @@ npm-debug.log* ...@@ -22,4 +22,6 @@ npm-debug.log*
22 yarn-debug.log* 22 yarn-debug.log*
23 yarn-error.log* 23 yarn-error.log*
24 24
25 -.vscode
...\ No newline at end of file ...\ No newline at end of file
25 +.vscode
26 +
27 +.env
...\ No newline at end of file ...\ No newline at end of file
......
1 +REACT_APP_API_ENDPOINT={API_ENDPOINT}
2 +REACT_APP_SEARCH_KEY={SEARCH_KEY}
3 +REACT_APP_ENGINE_NAME={ENGINE_NAME}
...\ No newline at end of file ...\ No newline at end of file
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
13 }], 13 }],
14 "arrow-body-style": 1, 14 "arrow-body-style": 1,
15 "react/jsx-fragments": 0, 15 "react/jsx-fragments": 0,
16 - "react/prop-types": 0 16 + "react/prop-types": 0,
17 + "import/prefer-default-export": 0,
18 + "no-param-reassign": 0
17 }, 19 },
18 "settings": { 20 "settings": {
19 "react": { 21 "react": {
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
5 "dependencies": { 5 "dependencies": {
6 "@mantine/core": "^1.0.6", 6 "@mantine/core": "^1.0.6",
7 "@mantine/hooks": "^1.0.6", 7 "@mantine/hooks": "^1.0.6",
8 + "@reduxjs/toolkit": "^1.6.0",
8 "@testing-library/jest-dom": "^5.11.4", 9 "@testing-library/jest-dom": "^5.11.4",
9 "@testing-library/react": "^11.1.0", 10 "@testing-library/react": "^11.1.0",
10 "@testing-library/user-event": "^12.1.10", 11 "@testing-library/user-event": "^12.1.10",
11 "axios": "^0.21.1", 12 "axios": "^0.21.1",
13 + "dotenv": "^10.0.0",
12 "react": "^17.0.2", 14 "react": "^17.0.2",
13 "react-dom": "^17.0.2", 15 "react-dom": "^17.0.2",
14 "react-icons": "^4.2.0", 16 "react-icons": "^4.2.0",
......
1 import React from 'react'; 1 import React from 'react';
2 import { createGlobalStyle } from 'styled-components'; 2 import { createGlobalStyle } from 'styled-components';
3 import { BrowserRouter, Route, Switch } from 'react-router-dom'; 3 import { BrowserRouter, Route, Switch } from 'react-router-dom';
4 +import dotenv from 'dotenv';
4 import HomePage from './pages/HomePage'; 5 import HomePage from './pages/HomePage';
5 import LoginPage from './pages/LoginPage'; 6 import LoginPage from './pages/LoginPage';
6 import SearchPage from './pages/SearchPage'; 7 import SearchPage from './pages/SearchPage';
7 8
9 +dotenv.config();
10 +
8 const GlobalStyle = createGlobalStyle` 11 const GlobalStyle = createGlobalStyle`
9 html, 12 html,
10 body, 13 body,
......
...@@ -130,9 +130,7 @@ const Header = () => { ...@@ -130,9 +130,7 @@ const Header = () => {
130 /> 130 />
131 </DropDownWrap> 131 </DropDownWrap>
132 </DropDownContainer> 132 </DropDownContainer>
133 - <InputBlock color="blue" fontsize="20px" width="70%" display> 133 + <InputBlock color="blue" fontsize="20px" width="70%" display />
134 - <input />
135 - </InputBlock>
136 </SearchContainer> 134 </SearchContainer>
137 <MenuContainer> 135 <MenuContainer>
138 <ul> 136 <ul>
......
...@@ -2,8 +2,11 @@ import React, { useState, useEffect } from 'react'; ...@@ -2,8 +2,11 @@ import React, { useState, useEffect } from 'react';
2 import { TextInput } from '@mantine/core'; 2 import { TextInput } from '@mantine/core';
3 import styled from 'styled-components'; 3 import styled from 'styled-components';
4 import { useHistory, useLocation } from 'react-router-dom'; 4 import { useHistory, useLocation } from 'react-router-dom';
5 +import { useDispatch } from 'react-redux';
5 import SearchBox from './SearchBox'; 6 import SearchBox from './SearchBox';
6 import { inputColorMap } from '../../lib/styles/palette'; 7 import { inputColorMap } from '../../lib/styles/palette';
8 +import { esApi } from '../../lib/api/elasticsearch';
9 +import { setParsedDocuments } from '../../features/parsedDocumentsSlice';
7 10
8 const InputBlock = styled.div` 11 const InputBlock = styled.div`
9 width: ${props => props.width}; 12 width: ${props => props.width};
...@@ -42,10 +45,16 @@ const MyInput = ({ ...@@ -42,10 +45,16 @@ const MyInput = ({
42 const history = useHistory(); 45 const history = useHistory();
43 const search = useLocation(); 46 const search = useLocation();
44 const name = search.search.substring(7); 47 const name = search.search.substring(7);
48 + const dispatch = useDispatch();
49 +
45 useEffect(() => { 50 useEffect(() => {
51 + const setSearchDatas = async () => {
52 + const { results } = await esApi.search(name);
53 + dispatch(setParsedDocuments(results));
54 + };
46 setQuery(name); 55 setQuery(name);
47 - }, []); 56 + setSearchDatas();
48 - 57 + }, [name]);
49 return ( 58 return (
50 <InputBlock 59 <InputBlock
51 color={color} 60 color={color}
......
1 +import { createSlice } from '@reduxjs/toolkit';
2 +
3 +const parsedDocumentsSlice = createSlice({
4 + name: 'parsedDocuments',
5 + initialState: {
6 + documents: [],
7 + },
8 + reducers: {
9 + setParsedDocuments: (state, action) => {
10 + state.documents = action.payload;
11 + },
12 + },
13 +});
14 +
15 +export const { setParsedDocuments } = parsedDocumentsSlice.actions;
16 +
17 +export default parsedDocumentsSlice.reducer;
1 import React from 'react'; 1 import React from 'react';
2 import ReactDOM from 'react-dom'; 2 import ReactDOM from 'react-dom';
3 +import { configureStore } from '@reduxjs/toolkit';
4 +import { Provider } from 'react-redux';
3 import App from './App'; 5 import App from './App';
6 +import rootReducer from './reducers';
7 +
8 +const store = configureStore({
9 + reducer: rootReducer,
10 +});
4 11
5 ReactDOM.render( 12 ReactDOM.render(
6 <React.StrictMode> 13 <React.StrictMode>
7 - <App /> 14 + <Provider store={store}>
15 + <App />
16 + </Provider>
8 </React.StrictMode>, 17 </React.StrictMode>,
9 document.getElementById('root') 18 document.getElementById('root')
10 ); 19 );
......
1 +import axios from 'axios';
2 +
3 +const esInstance = axios.create({
4 + baseURL: process.env.REACT_APP_API_ENDPOINT,
5 + headers: {
6 + 'Content-Type': 'application/json',
7 + Authorization: `Bearer ${process.env.REACT_APP_SEARCH_KEY}`,
8 + },
9 +});
10 +
11 +export const esApi = {
12 + search: async searchWord => {
13 + const res = await esInstance.post(
14 + `/api/as/v1/engines/${process.env.REACT_APP_ENGINE_NAME}/search`,
15 + {
16 + query: searchWord,
17 + }
18 + );
19 +
20 + return res.data;
21 + },
22 +};
1 import React from 'react'; 1 import React from 'react';
2 +import { useSelector } from 'react-redux';
2 import Header from '../components/Header'; 3 import Header from '../components/Header';
3 -import Main from '../components/document/index'; 4 +import Main from '../components/document';
4 5
5 const SearchPage = () => { 6 const SearchPage = () => {
7 + const parsedDocuments = useSelector(state => state.parsedDocuments);
8 +
9 + if (parsedDocuments.length === 0) {
10 + return (
11 + <>
12 + <Header />
13 + <div>검색 결과가 없습니다.</div>
14 + </>
15 + );
16 + }
6 return ( 17 return (
7 <> 18 <>
8 <Header /> 19 <Header />
......
1 +import { combineReducers } from 'redux';
2 +import parsedDocumentsReducer from '../features/parsedDocumentsSlice';
3 +
4 +export default combineReducers({
5 + parsedDocuments: parsedDocumentsReducer,
6 +});
...@@ -1512,6 +1512,16 @@ ...@@ -1512,6 +1512,16 @@
1512 schema-utils "^2.6.5" 1512 schema-utils "^2.6.5"
1513 source-map "^0.7.3" 1513 source-map "^0.7.3"
1514 1514
1515 +"@reduxjs/toolkit@^1.6.0":
1516 + version "1.6.0"
1517 + resolved "https://registry.yarnpkg.com/@reduxjs/toolkit/-/toolkit-1.6.0.tgz#0a17c6941c57341f8b31e982352b495ab69d5add"
1518 + integrity sha512-eGL50G+Vj5AG5uD0lineb6rRtbs96M8+hxbcwkHpZ8LQcmt0Bm33WyBSnj5AweLkjQ7ZP+KFRDHiLMznljRQ3A==
1519 + dependencies:
1520 + immer "^9.0.1"
1521 + redux "^4.1.0"
1522 + redux-thunk "^2.3.0"
1523 + reselect "^4.0.0"
1524 +
1515 "@rollup/plugin-node-resolve@^7.1.1": 1525 "@rollup/plugin-node-resolve@^7.1.1":
1516 version "7.1.3" 1526 version "7.1.3"
1517 resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz#80de384edfbd7bfc9101164910f86078151a3eca" 1527 resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz#80de384edfbd7bfc9101164910f86078151a3eca"
...@@ -4359,6 +4369,11 @@ dotenv@8.2.0: ...@@ -4359,6 +4369,11 @@ dotenv@8.2.0:
4359 resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" 4369 resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
4360 integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== 4370 integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
4361 4371
4372 +dotenv@^10.0.0:
4373 + version "10.0.0"
4374 + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
4375 + integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
4376 +
4362 duplexer@^0.1.1: 4377 duplexer@^0.1.1:
4363 version "0.1.2" 4378 version "0.1.2"
4364 resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6" 4379 resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"
...@@ -5902,6 +5917,11 @@ immer@8.0.1: ...@@ -5902,6 +5917,11 @@ immer@8.0.1:
5902 resolved "https://registry.yarnpkg.com/immer/-/immer-8.0.1.tgz#9c73db683e2b3975c424fb0572af5889877ae656" 5917 resolved "https://registry.yarnpkg.com/immer/-/immer-8.0.1.tgz#9c73db683e2b3975c424fb0572af5889877ae656"
5903 integrity sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA== 5918 integrity sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA==
5904 5919
5920 +immer@^9.0.1:
5921 + version "9.0.3"
5922 + resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.3.tgz#146e2ba8b84d4b1b15378143c2345559915097f4"
5923 + integrity sha512-mONgeNSMuyjIe0lkQPa9YhdmTv8P19IeHV0biYhcXhbd5dhdB9HSK93zBpyKjp6wersSUgT5QyU0skmejUVP2A==
5924 +
5905 import-cwd@^2.0.0: 5925 import-cwd@^2.0.0:
5906 version "2.1.0" 5926 version "2.1.0"
5907 resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9" 5927 resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9"
...@@ -9716,6 +9736,11 @@ redent@^3.0.0: ...@@ -9716,6 +9736,11 @@ redent@^3.0.0:
9716 indent-string "^4.0.0" 9736 indent-string "^4.0.0"
9717 strip-indent "^3.0.0" 9737 strip-indent "^3.0.0"
9718 9738
9739 +redux-thunk@^2.3.0:
9740 + version "2.3.0"
9741 + resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
9742 + integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
9743 +
9719 redux@^4.0.0, redux@^4.0.5: 9744 redux@^4.0.0, redux@^4.0.5:
9720 version "4.0.5" 9745 version "4.0.5"
9721 resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f" 9746 resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
...@@ -9724,6 +9749,13 @@ redux@^4.0.0, redux@^4.0.5: ...@@ -9724,6 +9749,13 @@ redux@^4.0.0, redux@^4.0.5:
9724 loose-envify "^1.4.0" 9749 loose-envify "^1.4.0"
9725 symbol-observable "^1.2.0" 9750 symbol-observable "^1.2.0"
9726 9751
9752 +redux@^4.1.0:
9753 + version "4.1.0"
9754 + resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.0.tgz#eb049679f2f523c379f1aff345c8612f294c88d4"
9755 + integrity sha512-uI2dQN43zqLWCt6B/BMGRMY6db7TTY4qeHHfGeKb3EOhmOKjU3KdWvNLJyqaHRksv/ErdNH7cFZWg9jXtewy4g==
9756 + dependencies:
9757 + "@babel/runtime" "^7.9.2"
9758 +
9727 regenerate-unicode-properties@^8.2.0: 9759 regenerate-unicode-properties@^8.2.0:
9728 version "8.2.0" 9760 version "8.2.0"
9729 resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz#e5de7111d655e7ba60c057dbe9ff37c87e65cdec" 9761 resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz#e5de7111d655e7ba60c057dbe9ff37c87e65cdec"
...@@ -9896,6 +9928,11 @@ requires-port@^1.0.0: ...@@ -9896,6 +9928,11 @@ requires-port@^1.0.0:
9896 resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" 9928 resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
9897 integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= 9929 integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
9898 9930
9931 +reselect@^4.0.0:
9932 + version "4.0.0"
9933 + resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7"
9934 + integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA==
9935 +
9899 resolve-cwd@^2.0.0: 9936 resolve-cwd@^2.0.0:
9900 version "2.0.0" 9937 version "2.0.0"
9901 resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a" 9938 resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
......