diff --git a/src/App.js b/src/App.js index 70672e3..b7b3c3e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,12 @@ import React from "react"; -import logo from "./public/logo_mint.svg"; import "./App.scss"; import TopBar from "./components/TopBar"; +import LogoMain from "./components/logoMain"; import Footer from "./components/Footer"; import SearchPanel from "./components/SearchPanel"; +import SearchResults from "./components/SearchResults"; import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles"; +import { useSelector } from "react-redux"; const theme = createMuiTheme({ palette: { @@ -15,16 +17,21 @@ const theme = createMuiTheme({ }); function App() { + const appMode = useSelector((store) => store.appMode); + return (
- Menui logo + -

- Sprawdź co serwuje Twoja ulubiona restauracja. -

+ {appMode === "init" && ( +

+ Sprawdź co serwuje Twoja ulubiona restauracja. +

+ )} +
diff --git a/src/App.scss b/src/App.scss index 1fb5149..2792432 100644 --- a/src/App.scss +++ b/src/App.scss @@ -2,6 +2,7 @@ @import "./styles/TopBar.scss"; @import "./styles/SearchPanel.scss"; @import "./styles/Footer.scss"; +@import "./styles/SearchResults.scss"; .App { padding: 0; @@ -38,4 +39,5 @@ p { flex-direction: column; justify-content: center; text-align: center; + align-items: center; } diff --git a/src/actions/index.js b/src/actions/index.js index 3c50ac4..3243b44 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -16,7 +16,9 @@ export const clearAutocomplete = () => { export const fetchAutocomplete = (input) => { return function (dispatch) { axios - .get("http://localhost:4000/search/autocomplete?string=" + input) + .get( + "http://localhost:4000/search/autocomplete?string=" + encodeURI(input) + ) .then((response) => { const cities = Array.from(response.data.cities); const restaurants = Array.from(response.data.restaurants); @@ -30,6 +32,37 @@ export const fetchAutocomplete = (input) => { }; }; +export const fetchSearch = (input) => { + return function (dispatch) { + axios + .get("http://localhost:4000/search?string=" + encodeURI(input)) + .then((response) => { + const data = response.data; + if (Object.keys(data).length > 0) { + dispatch(setSearchResults(data)); + dispatch(setAppMode("APP_SEARCH_RESULTS")); + } + }) + .catch((err) => { + console.log(err); + }); + }; +}; + +const setSearchResults = (input) => { + return { + type: "SEARCH_RESULTS", + payload: input, + }; +}; + +export const setSearchQuery = (input) => { + return { + type: "SEARCH_QUERY_SET", + payload: input, + }; +}; + export const setAppMode = (mode) => { return { type: mode, diff --git a/src/components/ButtonSecondary.js b/src/components/ButtonSecondary.js index fae2076..427f906 100644 --- a/src/components/ButtonSecondary.js +++ b/src/components/ButtonSecondary.js @@ -19,5 +19,5 @@ const StylizedButton = withStyles({ })(Button); export default function ButtonSecondary(props) { - return {props.text}; + return {props.text}; } diff --git a/src/components/CardRestaurant.js b/src/components/CardRestaurant.js new file mode 100644 index 0000000..9ff9346 --- /dev/null +++ b/src/components/CardRestaurant.js @@ -0,0 +1,18 @@ +import React from "react"; + +export default function CardRestaurant(props) { + return ( +
+
+
+

{props.name}

+
+

Miasto: {props.city}

+

Godziny otwarcia: {props.hours}

+

+ Jakiś krótki opis restauracji. Coś tam że jest przytulnie i elegancko. +

+
+
+ ); +} diff --git a/src/components/SearchPanel.js b/src/components/SearchPanel.js index d912c04..3836fbd 100644 --- a/src/components/SearchPanel.js +++ b/src/components/SearchPanel.js @@ -3,10 +3,11 @@ import ButtonSecondary from "./ButtonSecondary"; import TextField from "@material-ui/core/TextField"; import Autocomplete from "@material-ui/lab/Autocomplete"; import { useSelector, useDispatch } from "react-redux"; -import { fetchAutocomplete } from "../actions"; +import { fetchAutocomplete, setSearchQuery, fetchSearch } from "../actions"; export default function SearchPanel() { let options = useSelector((store) => store.autocomplete); + let searchQuery = useSelector((store) => store.searchQuery); const dispatch = useDispatch(); return ( @@ -15,18 +16,23 @@ export default function SearchPanel() { options={options} style={{ width: 300 }} noOptionsText="Brak podpowiedzi" + onChange={(event) => dispatch(setSearchQuery(event.target.textContent))} renderInput={(params) => ( dispatch(setSearchQuery(event.target.value))} onInput={(event) => dispatch(fetchAutocomplete(event.target.value))} /> )} />
- + dispatch(fetchSearch(searchQuery))} + text="Szukaj" + />
); diff --git a/src/components/SearchResults.js b/src/components/SearchResults.js new file mode 100644 index 0000000..2d67d9b --- /dev/null +++ b/src/components/SearchResults.js @@ -0,0 +1,28 @@ +import React from "react"; +import CardRestaurant from "./CardRestaurant"; +import { useSelector } from "react-redux"; + +export default function SearchResults() { + var results = useSelector((store) => store.searchResults); + + return ( +
+ + + + +
+ ); +} diff --git a/src/components/logoMain.js b/src/components/logoMain.js new file mode 100644 index 0000000..a2ec52f --- /dev/null +++ b/src/components/logoMain.js @@ -0,0 +1,13 @@ +import logo from "../public/logo_mint.svg"; +import React from "react"; +import { useSelector } from "react-redux"; + +export default function LogoMain() { + let appMode = useSelector((store) => store.appMode); + + if (appMode === "init") { + return Menui logo; + } else { + return ""; + } +} diff --git a/src/index.js b/src/index.js index 70eb46e..405b735 100644 --- a/src/index.js +++ b/src/index.js @@ -6,9 +6,15 @@ import App from "./App"; import * as serviceWorker from "./serviceWorker"; import rootReducer from "./reducers"; import thunk from "redux-thunk"; -import { createStore, applyMiddleware } from "redux"; +import { createStore, applyMiddleware, compose } from "redux"; -const store = createStore(rootReducer, applyMiddleware(thunk)); +const store = createStore( + rootReducer, + compose( + applyMiddleware(thunk), + window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() + ) +); ReactDOM.render( diff --git a/src/public/cat.jpg b/src/public/cat.jpg new file mode 100644 index 0000000..34f49a5 Binary files /dev/null and b/src/public/cat.jpg differ diff --git a/src/reducers/appMode.js b/src/reducers/appMode.js index a8e04dc..b7bb239 100644 --- a/src/reducers/appMode.js +++ b/src/reducers/appMode.js @@ -1,4 +1,4 @@ -const appModeReducer = (state = "init", action) => { +const appModeReducer = (state = "search results", action) => { switch (action.type) { case "APP_INIT": return (state = "init"); diff --git a/src/reducers/index.js b/src/reducers/index.js index ad1a00c..c0d1fca 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -2,11 +2,13 @@ import { combineReducers } from "redux"; import autoCompleteReducer from "./autoComplete"; import searchResults from "./searchResults"; import appMode from "./appMode"; +import searchQuery from "./searchQuery"; const rootReducer = combineReducers({ autocomplete: autoCompleteReducer, appMode: appMode, searchResults: searchResults, + searchQuery: searchQuery, }); export default rootReducer; diff --git a/src/reducers/searchQuery.js b/src/reducers/searchQuery.js new file mode 100644 index 0000000..75dab81 --- /dev/null +++ b/src/reducers/searchQuery.js @@ -0,0 +1,12 @@ +const searchQuery = (state = {}, action) => { + switch (action.type) { + case "SEARCH_QUERY_SET": + return (state = action.payload); + case "SEARCH_QUERY_CLEAR": + return (state = ""); + default: + return state; + } +}; + +export default searchQuery; diff --git a/src/styles/SearchResults.scss b/src/styles/SearchResults.scss new file mode 100644 index 0000000..ffe1e89 --- /dev/null +++ b/src/styles/SearchResults.scss @@ -0,0 +1,49 @@ +@import "./Design.scss"; + +.search-results { +} + +.card-restaurant { + background-color: #f7f7f7; + margin: 14px; + color: $secondary-color; + border-radius: 10px; + min-width: 70vw; + min-height: 200px; + display: flex; + cursor: pointer; + :hover { + background-color: #ebebeb; + } +} + +.card-img { + width: 180px; + height: 180px; + margin: 10px; + border-radius: 8px; + background-image: url("../public/cat.jpg"); + background-size: cover; +} + +.card-info { + text-align: start; + flex-grow: 6; + + h1 { + color: $main-color; + font-size: 1.6rem; + font-weight: 300; + margin-bottom: 4px; + } + h3 { + font-weight: 400; + margin-top: 2px; + margin-bottom: 2px; + font-size: 0.8rem; + } + hr { + color: $main-color; + border: solid 1px; + } +}