Skip to content

Commit

Permalink
feat: Update react v18
Browse files Browse the repository at this point in the history
Update backend to handle errors better
Add pre user prompt and answer for GPT-3.5 understanding
  • Loading branch information
Alfex4936 committed Jun 15, 2023
1 parent 8ef3119 commit da0314f
Show file tree
Hide file tree
Showing 17 changed files with 4,225 additions and 27,372 deletions.
5 changes: 5 additions & 0 deletions libra_api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ COPY . .
# Build the application
RUN cargo build --release

RUN chmod +x upx && \
./upx -9 /app/target/release/libra_api && \
rm upx

# Stage 2: Create the final image GLIB_2.29
FROM debian:bullseye-slim
WORKDIR /app

# Install necessary dependencies
RUN apt-get update && \
apt-get install -y libssl1.1 ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Copy the binary from the builder stage
Expand Down
1 change: 1 addition & 0 deletions libra_api/google-clone/craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
20,940 changes: 0 additions & 20,940 deletions libra_api/google-clone/package-lock.json

This file was deleted.

29 changes: 15 additions & 14 deletions libra_api/google-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"@craco/craco": "^7.1.0",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@material-ui/lab": "latest",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.12.1",
"react-scripts": "5.0.1",
"web-vitals": "^3.3.2"
},
"scripts": {
"start": "set NODE_OPTIONS=--openssl-legacy-provider & react-scripts start",
"build": "set NODE_OPTIONS=--openssl-legacy-provider & react-scripts build",
"test": "set NODE_OPTIONS=--openssl-legacy-provider & react-scripts test",
"eject": "set NODE_OPTIONS=--openssl-legacy-provider & react-scripts eject"
"start": "set NODE_OPTIONS=--openssl-legacy-provider & craco start",
"build": "set NODE_OPTIONS=--openssl-legacy-provider & craco build",
"test": "set NODE_OPTIONS=--openssl-legacy-provider & craco test",
"eject": "set NODE_OPTIONS=--openssl-legacy-provider & craco eject"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion libra_api/google-clone/src/App.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
}
25 changes: 9 additions & 16 deletions libra_api/google-clone/src/App.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

import Home from './pages/Home/Home';
import SearchResult from './pages/SearchResult/SearchResult';
import Home from "./pages/Home/Home";
import SearchResult from "./pages/SearchResult/SearchResult";

import './App.css';
import "./App.css";

function App() {
return (
<div className="app">

<Router>
<Switch>

<Routes>
{/* Home (the one with the search on) */}
<Route path="/" exact>
<Home />
</Route>
<Route path="/" element={<Home />} />

{/* SearchPage (The results page) */}
<Route path="/search">
<SearchResult />
</Route>

</Switch>
<Route path="search" element={<SearchResult />} />
</Routes>
</Router>
</div>
);
}

export default App;
export default App;
18 changes: 12 additions & 6 deletions libra_api/google-clone/src/StateContext.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import React, { createContext, useContext, useReducer } from 'react';
import React, { createContext, useContext, useReducer } from "react";

// Preparing the data layer
export const StateContext = createContext();

export const StateProvider = ({ reducer, initialState, children }) => (
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
)
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
);

// Hook which allows us to pull information from the data layer
export const useStateValue = () => useContext(StateContext);
export const useStateValue = () => {
const context = useContext(StateContext);
if (context === undefined) {
throw new Error("useStateValue must be used within a StateProvider");
}
return context;
};
29 changes: 29 additions & 0 deletions libra_api/google-clone/src/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { actionTypes } from "./reducer";

export const setSearchTerm = term => ({
type: actionTypes.SET_SEARCH_TERM,
term,
});

export const setNumResults = numResults => ({
type: actionTypes.SET_NUM_RESULTS,
numResults,
});
export const setOpenAIKey = openAIKey => ({
type: actionTypes.SET_OPENAI_KEY,
openAIKey,
});

export const setGptModel = model => ({
type: actionTypes.SET_GPT_MODEL,
model,
});

export const clearHistory = () => ({
type: actionTypes.CLEAR_HISTORY,
});

export const setError = error => ({
type: actionTypes.SET_ERROR,
error,
});
64 changes: 32 additions & 32 deletions libra_api/google-clone/src/components/Search/Search.css
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
.search__input {
display: flex;
align-items: center;
border: 1px solid lightgray;
height: 30px;
padding: 10px 20px;
border-radius: 50px;
width: 75vw;
max-width: 560px;
margin: 0 auto;
margin-top: 40px;
display: flex;
align-items: center;
border: 1px solid lightgray;
height: 30px;
padding: 10px 20px;
border-radius: 50px;
width: 75vw;
max-width: 560px;
margin: 0 auto;
margin-top: 40px;
}

.search__input > input {
flex: 1;
padding: 10px 20px;
font-size: medium;
border: none;
flex: 1;
padding: 10px 20px;
font-size: medium;
border: none;
}

.search__input > input:focus {
outline-width: 0;
outline-width: 0;
}

.search__inputIcon {
color: gray;
color: gray;
}

.search__buttons {
margin-top: 20px;
display: flex;
justify-content: center;
margin-top: 20px;
display: flex;
justify-content: center;
}

.search__buttons button {
margin: 5px;
padding: 7px 15px;
background-color: #f8f8f8;
border: 1px solid #FFF;
text-transform: inherit;
color: #5f6368;
margin: 5px;
padding: 7px 15px;
background-color: #f8f8f8;
border: 1px solid #fff;
text-transform: inherit;
color: #5f6368;
}

.search__buttons button:hover {
box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
background-image: -webkit-linear-gradient(top, #f8f8f8, #f1f1f1);
background-color: #f8f8f8;
border: 1px solid #c6c6c6;
color: #222;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
background-image: -webkit-linear-gradient(top, #f8f8f8, #f1f1f1);
background-color: #f8f8f8;
border: 1px solid #c6c6c6;
color: #222;
}

.search__buttonHidden {
display: none !important;
}
display: none !important;
}
6 changes: 3 additions & 3 deletions libra_api/google-clone/src/components/Search/Search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react"; // import useEffect
import { useHistory } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import { useStateValue } from "../../StateContext";
import { actionTypes } from "../../reducer";

Expand All @@ -14,7 +14,7 @@ function Search({ hideButtons = false, loading = false }) {

const [input, setInput] = useState(term || "");

const history = useHistory();
const navigate = useNavigate();

// update the input state when term changes
useEffect(() => {
Expand All @@ -38,7 +38,7 @@ function Search({ hideButtons = false, loading = false }) {
if (input.trim() !== "") {
// check if input isn't empty
if (!error) {
history.push("/search");
navigate("/search");
}
} else {
// Optional: Show an alert or some error message to user
Expand Down
17 changes: 9 additions & 8 deletions libra_api/google-clone/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import reducer, { initialState } from './reducer';
import { StateProvider } from './StateContext';
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import reducer, { initialState } from "./reducer";
import { StateProvider } from "./StateContext";

ReactDOM.render(
const rootNode = document.getElementById("root");

ReactDOM.createRoot(rootNode).render(
<React.StrictMode>
<StateProvider initialState={initialState} reducer={reducer}>
<App />
</StateProvider>
</React.StrictMode>,
document.getElementById('root')
</React.StrictMode>
);
31 changes: 22 additions & 9 deletions libra_api/google-clone/src/pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { Link } from "react-router-dom";

import Search from "../../components/Search/Search";
import History from "../../components/History/History";
import { actionTypes } from "../../reducer";
import { useStateValue } from "../../StateContext";

import SettingsIcon from "@material-ui/icons/Settings";
import HistoryIcon from "@material-ui/icons/History";
import { Slider } from "@material-ui/core";
import { actionTypes } from "../../reducer";
import { useStateValue } from "../../StateContext";
import IconButton from "@material-ui/core/IconButton";
import ClearAllIcon from "@material-ui/icons/ClearAll";

import Dialog from "@material-ui/core/Dialog";
import DialogTitle from "@material-ui/core/DialogTitle";
Expand All @@ -17,12 +18,8 @@ import DialogContentText from "@material-ui/core/DialogContentText";
import TextField from "@material-ui/core/TextField";
import DialogActions from "@material-ui/core/DialogActions";
import Button from "@material-ui/core/Button";

import InputLabel from "@material-ui/core/InputLabel";
import Input from "@material-ui/core/Input";
import MenuItem from "@material-ui/core/MenuItem";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
import { Slider } from "@material-ui/core";

import "./Home.css";

Expand Down Expand Up @@ -73,6 +70,17 @@ function Home() {
setOpen(false);
};

const handleClearHistory = () => {
// Clear the search history from the state
dispatch({ type: actionTypes.CLEAR_HISTORY });

// Remove the search history from local storage
localStorage.removeItem("searchHistory");

// Close the history dialog
handleCloseHistory();
};

const onNumResultsChange = (event, value) => {
dispatch({
type: actionTypes.SET_NUM_RESULTS,
Expand Down Expand Up @@ -200,7 +208,12 @@ function Home() {
onClose={handleCloseHistory}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">Search History</DialogTitle>
<DialogTitle id="form-dialog-title">
Search History
<IconButton style={{ float: "right" }} onClick={handleClearHistory}>
<ClearAllIcon />
</IconButton>
</DialogTitle>
<DialogContent style={{ maxHeight: "60vh", maxWidth: "80vw" }}>
<History searchHistory={history} />
</DialogContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown";

import useLibraSearch from "../../hooks/useLibraSearch/useLibraSearch";
import { useStateValue } from "../../StateContext";
import { actionTypes } from "../../reducer";

import Search from "../../components/Search/Search";
import SearchOption from "../../components/SearchOption/SearchOption";
Expand Down
6 changes: 6 additions & 0 deletions libra_api/google-clone/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const actionTypes = {
CLEAR_ERROR: "CLEAR_ERROR",
ADD_HISTORY: "ADD_HISTORY",
SET_GPT_MODEL: "SET_GPT_MODEL",
CLEAR_HISTORY: "CLEAR_HISTORY",
};

const reducer = (state, action) => {
Expand Down Expand Up @@ -46,6 +47,11 @@ const reducer = (state, action) => {
...state,
error: null, // reset error to null
};
case actionTypes.CLEAR_HISTORY:
return {
...state,
history: [],
};
case actionTypes.ADD_HISTORY:
// Add new history to the existing history array
const newHistory = [...state.history, action.history];
Expand Down
Loading

1 comment on commit da0314f

@vercel
Copy link

@vercel vercel bot commented on da0314f Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ajou-libra – ./

ajou-libra-alfex4936.vercel.app
ajou-libra.vercel.app
ajou-libra-git-main-alfex4936.vercel.app

Please sign in to comment.