├── .eslintcache ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.test.tsx ├── App.tsx ├── components │ ├── Form │ │ ├── Form.css │ │ └── Form.tsx │ ├── Header │ │ ├── Header.css │ │ └── Header.tsx │ ├── Map │ │ ├── AddMarker.tsx │ │ ├── Map.css │ │ └── Map.tsx │ ├── Preview │ │ ├── Preview.css │ │ └── Preview.tsx │ └── Search │ │ ├── Search.css │ │ └── Search.tsx ├── data.ts ├── index.css ├── index.tsx ├── react-app-env.d.ts ├── reportWebVitals.ts ├── setupTests.ts └── store │ ├── actions │ ├── index.ts │ ├── places.ts │ └── search.ts │ ├── index.ts │ ├── models.ts │ └── reducers │ ├── index.ts │ ├── places.ts │ └── search.ts ├── tsconfig.json └── yarn.lock /.eslintcache: -------------------------------------------------------------------------------- 1 | [{"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/App.tsx":"1","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Header/Header.tsx":"2","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Map/Map.tsx":"3","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/index.tsx":"4","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/index.ts":"5","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/actions/index.ts":"6","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Search/Search.tsx":"7","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/reducers/index.ts":"8","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/reducers/search.ts":"9","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/reportWebVitals.ts":"10","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/actions/search.ts":"11","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Preview/Preview.tsx":"12","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/actions/places.ts":"13","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/reducers/places.ts":"14","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/data.ts":"15","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Map/AddMarker.tsx":"16","/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Form/Form.tsx":"17"},{"size":497,"mtime":1609257953719,"results":"18","hashOfConfig":"19"},{"size":990,"mtime":1610125021077,"results":"20","hashOfConfig":"19"},{"size":2527,"mtime":1610639761576,"results":"21","hashOfConfig":"19"},{"size":616,"mtime":1608650761388,"results":"22","hashOfConfig":"19"},{"size":225,"mtime":1608544784284,"results":"23","hashOfConfig":"19"},{"size":52,"mtime":1608731920417,"results":"24","hashOfConfig":"19"},{"size":1516,"mtime":1610125348791,"results":"25","hashOfConfig":"19"},{"size":156,"mtime":1608732094330,"results":"26","hashOfConfig":"19"},{"size":460,"mtime":1610640784321,"results":"27","hashOfConfig":"19"},{"size":425,"mtime":1608309974267,"results":"28","hashOfConfig":"19"},{"size":172,"mtime":1608546320207,"results":"29","hashOfConfig":"19"},{"size":1443,"mtime":1610637448612,"results":"30","hashOfConfig":"19"},{"size":1090,"mtime":1610124801949,"results":"31","hashOfConfig":"19"},{"size":1325,"mtime":1610124369868,"results":"32","hashOfConfig":"19"},{"size":5367,"mtime":1610640686967,"results":"33","hashOfConfig":"19"},{"size":1155,"mtime":1610463293272,"results":"34","hashOfConfig":"19"},{"size":3873,"mtime":1610124852692,"results":"35","hashOfConfig":"19"},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"ybxktz",{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"40"},{"filePath":"41","messages":"42","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"43","messages":"44","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"45"},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"62","messages":"63","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"68","messages":"69","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/App.tsx",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Header/Header.tsx",[],["72","73"],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Map/Map.tsx",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/index.tsx",[],["74","75"],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/index.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/actions/index.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Search/Search.tsx",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/reducers/index.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/reducers/search.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/reportWebVitals.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/actions/search.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Preview/Preview.tsx",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/actions/places.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/store/reducers/places.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/data.ts",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Map/AddMarker.tsx",[],"/Users/majuran.sivakumar/Documents/PERSO/PROJECTS/react-leaflet-example/src/components/Form/Form.tsx",[],{"ruleId":"76","replacedBy":"77"},{"ruleId":"78","replacedBy":"79"},{"ruleId":"76","replacedBy":"80"},{"ruleId":"78","replacedBy":"81"},"no-native-reassign",["82"],"no-negated-in-lhs",["83"],["82"],["83"],"no-global-assign","no-unsafe-negation"] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-leaflet-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "@types/jest": "^26.0.15", 10 | "@types/node": "^12.0.0", 11 | "@types/react": "^16.9.53", 12 | "@types/react-dom": "^16.9.8", 13 | "formik": "^2.2.6", 14 | "leaflet": "^1.7.1", 15 | "react": "^17.0.1", 16 | "react-dom": "^17.0.1", 17 | "react-icons": "^4.1.0", 18 | "react-leaflet": "^3.0.5", 19 | "react-redux": "^7.2.2", 20 | "react-scripts": "4.0.1", 21 | "redux": "^4.0.5", 22 | "typescript": "^4.0.3", 23 | "web-vitals": "^0.2.4" 24 | }, 25 | "scripts": { 26 | "start": "react-scripts start", 27 | "build": "react-scripts build", 28 | "test": "react-scripts test", 29 | "eject": "react-scripts eject" 30 | }, 31 | "eslintConfig": { 32 | "extends": [ 33 | "react-app", 34 | "react-app/jest" 35 | ] 36 | }, 37 | "browserslist": { 38 | "production": [ 39 | ">0.2%", 40 | "not dead", 41 | "not op_mini all" 42 | ], 43 | "development": [ 44 | "last 1 chrome version", 45 | "last 1 firefox version", 46 | "last 1 safari version" 47 | ] 48 | }, 49 | "devDependencies": { 50 | "@types/leaflet": "^1.5.19", 51 | "@types/react-redux": "^7.1.12", 52 | "eslint-config-prettier": "^7.1.0", 53 | "eslint-plugin-prettier": "^3.3.0", 54 | "prettier": "^2.2.1" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maj07/react-leaflet-example/c6c12f7604b6d118a5941d387d10be30b39d856d/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | 30 | React App 31 | 32 | 33 | 34 |
35 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maj07/react-leaflet-example/c6c12f7604b6d118a5941d387d10be30b39d856d/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maj07/react-leaflet-example/c6c12f7604b6d118a5941d387d10be30b39d856d/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | main { 2 | display: flex; 3 | position: fixed; 4 | } -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "./App.css"; 3 | 4 | import Header from "./components/Header/Header"; 5 | import Map from "./components/Map/Map"; 6 | import Search from "./components/Search/Search"; 7 | import Preview from "./components/Preview/Preview"; 8 | import Form from "./components/Form/Form"; 9 | 10 | function App() { 11 | return ( 12 | <> 13 | 16 |
17 | 18 | 19 | 20 |
21 |
22 | 23 | ); 24 | } 25 | 26 | export default App; 27 | -------------------------------------------------------------------------------- /src/components/Form/Form.css: -------------------------------------------------------------------------------- 1 | .form__container { 2 | z-index: 1000; 3 | position: fixed; 4 | width: 100%; 5 | height: 100vh; 6 | background-color: white; 7 | top: 0; 8 | right: -100%; 9 | transition: all 0.2s ease-in-out; 10 | } 11 | 12 | .form__container--active { 13 | right: 0; 14 | } 15 | 16 | .form__description__container { 17 | padding: 1rem; 18 | } 19 | 20 | .form__header { 21 | padding: 1rem 0.5rem; 22 | background-color: #3c8fce; 23 | text-align: center; 24 | position: relative; 25 | color: white; 26 | font-size: 1.2rem; 27 | font-weight: bold; 28 | } 29 | 30 | .form__header__close { 31 | position: absolute; 32 | right: 1rem; 33 | top: 1rem; 34 | font-size: 1.5rem; 35 | color: white; 36 | cursor: pointer; 37 | } 38 | 39 | .button__container { 40 | display: flex; 41 | } 42 | 43 | .form__button { 44 | text-decoration: none; 45 | font-weight: bold; 46 | background-color: #f9b29c; 47 | border-radius: 0.5rem; 48 | appearance: none; 49 | border: none; 50 | color: white; 51 | padding: 1rem; 52 | font-size: 1rem; 53 | margin: 1rem auto; 54 | cursor: pointer; 55 | } 56 | 57 | .formGroup { 58 | padding: 1rem; 59 | } 60 | 61 | .formGroupInput { 62 | display: flex; 63 | flex-direction: column; 64 | } 65 | 66 | label { 67 | font-size: 1.25rem; 68 | font-weight: bold; 69 | margin-bottom: 1rem; 70 | } 71 | 72 | input { 73 | height: 2rem; 74 | } 75 | 76 | .errors { 77 | margin-top: 1rem; 78 | color: #c41c1c; 79 | } 80 | 81 | @media only screen and (min-width: 768px) { 82 | .form__container { 83 | top: auto; 84 | width: 33%; 85 | } 86 | } -------------------------------------------------------------------------------- /src/components/Form/Form.tsx: -------------------------------------------------------------------------------- 1 | import { connect } from "react-redux"; 2 | import { addNewPlace as addNewPlaceAction, setPlaceFormVisibility } from "../../store/actions"; 3 | import { IState, Place } from "../../store/models"; 4 | import { AiFillCloseCircle } from "react-icons/ai"; 5 | import "./Form.css"; 6 | import { Field, Formik, Form as FormikForm } from "formik"; 7 | import { LatLng } from "leaflet"; 8 | 9 | const Form = ({ 10 | isVisible, 11 | position, 12 | closeForm, 13 | addNewPlace 14 | }: { 15 | isVisible: boolean; 16 | position: LatLng; 17 | closeForm: Function; 18 | addNewPlace: Function; 19 | }) => { 20 | 21 | const initialValues = { 22 | picture: "", 23 | title: "", 24 | description: "", 25 | seeMoreLink: "", 26 | }; 27 | 28 | const validator = (values: PlaceFormProps) => { 29 | const keys = Object.keys(values); 30 | 31 | return keys.reduce((prev, curr) => { 32 | if (!values[curr]) { 33 | return { ...prev, [curr]: "required" }; 34 | } 35 | return prev; 36 | }, {}); 37 | }; 38 | 39 | const handleOnSubmit = (values: PlaceFormProps) => { 40 | addNewPlace({ 41 | ...values, 42 | position: [position.lat, position.lng] 43 | }); 44 | closeForm() 45 | } 46 | 47 | return ( 48 |
51 |
52 | closeForm()} 56 | > 57 | 58 | 59 | Add new Place 60 |
61 | 66 | {({ errors, touched, isValidating }) => ( 67 | 68 |
69 |
70 | 71 | 72 |
73 | {errors.picture &&
Required
} 74 |
75 |
76 |
77 | 78 | 79 |
80 | {errors.title &&
Required
} 81 |
82 |
83 |
84 | 85 | 90 |
91 | {errors.description &&
Required
} 92 |
93 |
94 |
95 | 96 | 97 |
98 | {errors.seeMoreLink &&
Required
} 99 |
100 | 101 |
102 | 103 |
104 |
105 | )} 106 |
107 |
108 | ); 109 | }; 110 | 111 | const mapStateToProps = (state: IState) => { 112 | const { places } = state; 113 | return { 114 | isVisible: places.placeFormIsVisible, 115 | position: places.prePlacePosition as LatLng, 116 | }; 117 | }; 118 | 119 | const mapDispatchToProps = (dispatch: any) => { 120 | return { 121 | closeForm: () => 122 | dispatch(setPlaceFormVisibility(false)), 123 | addNewPlace: (place: Place) => { 124 | dispatch(addNewPlaceAction(place)) 125 | } 126 | }; 127 | }; 128 | 129 | export default connect(mapStateToProps, mapDispatchToProps)(Form); 130 | 131 | interface PlaceFormProps { 132 | [key: string]: string; 133 | picture: string; 134 | title: string; 135 | description: string; 136 | seeMoreLink: string; 137 | } 138 | -------------------------------------------------------------------------------- /src/components/Header/Header.css: -------------------------------------------------------------------------------- 1 | .header__container { 2 | background-color: #f9b29c; 3 | padding: 1rem 0; 4 | color: white; 5 | font-size: 2rem; 6 | text-align: center; 7 | font-weight: bold; 8 | } 9 | -------------------------------------------------------------------------------- /src/components/Header/Header.tsx: -------------------------------------------------------------------------------- 1 | import { connect } from "react-redux"; 2 | import { setSearchVisibility } from "../../store/actions"; 3 | import { IState } from "../../store/models"; 4 | import "./Header.css"; 5 | import { CgPlayListSearch } from "react-icons/cg"; 6 | 7 | const Header = ({ searchIsVisible, setSearchVisibility }: any) => { 8 | 9 | return ( 10 |
11 | setSearchVisibility(!searchIsVisible)} 20 | > 21 | Paris 22 |
23 | ); 24 | }; 25 | 26 | const mapStateToProps = (state: IState) => { 27 | const { search } = state; 28 | return search; 29 | }; 30 | 31 | const mapDispatchToProps = (dispatch: any) => { 32 | return { 33 | setSearchVisibility: (payload: boolean) => 34 | dispatch(setSearchVisibility(payload)), 35 | }; 36 | }; 37 | 38 | export default connect(mapStateToProps, mapDispatchToProps)(Header); 39 | -------------------------------------------------------------------------------- /src/components/Map/AddMarker.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { LatLng, LatLngExpression } from "leaflet"; 3 | import { Marker, useMapEvents } from "react-leaflet"; 4 | import { connect } from "react-redux"; 5 | import { 6 | setPlaceFormVisibility, 7 | setPrePlaceLocation, 8 | } from "../../store/actions"; 9 | import { IState } from "../../store/models"; 10 | 11 | const AddMarker = ({ formIsOpen, toggleForm, setLocation }: any) => { 12 | const [position, setPosition] = useState( 13 | (null as unknown) as LatLngExpression 14 | ); 15 | 16 | useMapEvents({ 17 | click: (e) => { 18 | setPosition(e.latlng); 19 | setLocation(e.latlng); 20 | toggleForm(true); 21 | }, 22 | }); 23 | 24 | return !formIsOpen || position === null ? null : ( 25 | 26 | ); 27 | }; 28 | 29 | const mapStateToProps = (state: IState) => { 30 | const { places } = state; 31 | 32 | return { 33 | formIsOpen: places.placeFormIsVisible, 34 | }; 35 | }; 36 | 37 | const mapDispatchToProps = (dispatch: any) => { 38 | return { 39 | toggleForm: (payload: boolean) => dispatch(setPlaceFormVisibility(payload)), 40 | setLocation: (payload: LatLng) => dispatch(setPrePlaceLocation(payload)), 41 | }; 42 | }; 43 | 44 | export default connect(mapStateToProps, mapDispatchToProps)(AddMarker); 45 | -------------------------------------------------------------------------------- /src/components/Map/Map.css: -------------------------------------------------------------------------------- 1 | 2 | .map__container { 3 | width: 100vw; 4 | } 5 | -------------------------------------------------------------------------------- /src/components/Map/Map.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { LatLngExpression } from "leaflet"; 3 | import { MapContainer, TileLayer, Marker, Tooltip, Polyline } from "react-leaflet"; 4 | import { connect } from "react-redux"; 5 | import { setPlacePreviewVisibility, setSelectedPlace } from "../../store/actions"; 6 | import { IState, Place } from "../../store/models"; 7 | import AddMarker from "./AddMarker"; 8 | 9 | import "./Map.css"; 10 | 11 | const Map = ({ 12 | isVisible, 13 | places, 14 | selectedPlace, 15 | togglePreview, 16 | setPlaceForPreview, 17 | }: any) => { 18 | const defaultPosition: LatLngExpression = [48.864716, 2.349]; // Paris position 19 | const [polyLineProps, setPolyLineProps] = useState([]); 20 | 21 | useEffect(() => { 22 | setPolyLineProps(places.reduce((prev: LatLngExpression[], curr: Place) => { 23 | prev.push(curr.position); 24 | return prev; 25 | }, [])) 26 | }, [places]); 27 | 28 | const showPreview = (place: Place) => { 29 | if (isVisible) { 30 | togglePreview(false); 31 | setPlaceForPreview(null); 32 | } 33 | 34 | if (selectedPlace?.title !== place.title) { 35 | setTimeout(() => { 36 | showPlace(place); 37 | }, 400); 38 | } 39 | }; 40 | 41 | const showPlace = (place: Place) => { 42 | setPlaceForPreview(place); 43 | togglePreview(true); 44 | }; 45 | 46 | return ( 47 |
48 | 55 | 59 | 60 | {places.map((place: Place) => ( 61 | showPreview(place) }} 65 | > 66 | {place.title} 67 | 68 | ))} 69 | 70 | 71 |
72 | ); 73 | }; 74 | 75 | const mapStateToProps = (state: IState) => { 76 | const { places } = state; 77 | return { 78 | isVisible: places.placePreviewsIsVisible, 79 | places: places.places, 80 | selectedPlace: places.selectedPlace, 81 | }; 82 | }; 83 | 84 | const mapDispatchToProps = (dispatch: any) => { 85 | return { 86 | togglePreview: (payload: boolean) => 87 | dispatch(setPlacePreviewVisibility(payload)), 88 | setPlaceForPreview: (payload: Place) => 89 | dispatch(setSelectedPlace(payload)), 90 | }; 91 | }; 92 | 93 | export default connect(mapStateToProps, mapDispatchToProps)(Map); 94 | -------------------------------------------------------------------------------- /src/components/Preview/Preview.css: -------------------------------------------------------------------------------- 1 | .preview__container { 2 | z-index: 1000; 3 | position: fixed; 4 | width: 100%; 5 | height: 100vh; 6 | overflow-y: scroll; 7 | background-color: white; 8 | top: 0; 9 | right: -100%; 10 | transition: all 0.2s ease-in-out; 11 | } 12 | 13 | .preview__container--active { 14 | right: 0; 15 | } 16 | 17 | .preview__description__container { 18 | padding: 1rem; 19 | } 20 | 21 | .preview__close { 22 | position: absolute; 23 | right: 1rem; 24 | top: 1rem; 25 | font-size: 2rem; 26 | color: white; 27 | cursor: pointer; 28 | } 29 | 30 | .preview__button { 31 | text-decoration: none; 32 | font-weight: bold; 33 | background-color: #f9b29c; 34 | border-radius: 0.5rem; 35 | appearance: none; 36 | border: none; 37 | color: white; 38 | padding: 1rem; 39 | font-size: 1rem; 40 | margin: 1rem auto; 41 | cursor: pointer; 42 | } 43 | 44 | .preview__title { 45 | font-weight: bold; 46 | font-size: 1.25rem; 47 | margin-bottom: 1rem; 48 | } 49 | 50 | .preview__description { 51 | line-height: 1.5rem; 52 | color: #484848; 53 | } 54 | 55 | .preview__picture { 56 | height: 40vh; 57 | background-repeat: no-repeat; 58 | background-size: cover; 59 | background-position: center; 60 | } 61 | 62 | 63 | @media only screen and (min-width: 768px) { 64 | .preview__container { 65 | top: auto; 66 | width: 33%; 67 | } 68 | } -------------------------------------------------------------------------------- /src/components/Preview/Preview.tsx: -------------------------------------------------------------------------------- 1 | import { connect } from "react-redux"; 2 | import { setPlacePreviewVisibility } from "../../store/actions"; 3 | import { IState } from "../../store/models"; 4 | import { AiFillCloseCircle } from "react-icons/ai"; 5 | import "./Preview.css"; 6 | 7 | const Preview = ({ isVisible, place, closePreview }: any) => { 8 | return ( 9 |
14 |
closePreview()}> 15 | 16 |
17 |
21 |
22 |
{place?.title}
23 |
{place?.description}
24 |
25 | See more 26 |
27 |
28 |
29 | ); 30 | }; 31 | 32 | const mapStateToProps = (state: IState) => { 33 | const { places } = state; 34 | return { isVisible: places.placePreviewsIsVisible, place: places.selectedPlace }; 35 | }; 36 | 37 | const mapDispatchToProps = (dispatch: any) => { 38 | return { 39 | closePreview: () => 40 | dispatch(setPlacePreviewVisibility(false)), 41 | }; 42 | }; 43 | 44 | export default connect(mapStateToProps, mapDispatchToProps)(Preview); 45 | -------------------------------------------------------------------------------- /src/components/Search/Search.css: -------------------------------------------------------------------------------- 1 | .search__container { 2 | z-index: 1000; 3 | position: fixed; 4 | width: 100%; 5 | height: 100vh; 6 | overflow-y: scroll; 7 | background-color: white; 8 | top: 0; 9 | left: -100%; 10 | transition: all 0.5s ease-in-out; 11 | } 12 | 13 | .search__container--active { 14 | left: 0; 15 | } 16 | 17 | .search__header { 18 | padding: 1rem 0.5rem; 19 | background-color: #abd2de; 20 | text-align: center; 21 | position: relative; 22 | color: white; 23 | font-size: 1.2rem; 24 | font-weight: bold; 25 | } 26 | 27 | .search__header__close { 28 | position: absolute; 29 | left: 1rem; 30 | } 31 | 32 | .search__list { 33 | overflow-y: scroll; 34 | height: 100vh; 35 | margin-bottom: 4rem; 36 | } 37 | 38 | .search__list__item { 39 | background-color: white; 40 | display: flex; 41 | padding: 1rem 0.25rem; 42 | margin: 1rem 0.5rem; 43 | border-radius: 0.5rem; 44 | height: 115px; 45 | background-size: cover; 46 | background-position: center; 47 | cursor: pointer; 48 | filter: grayscale(1); 49 | transition: all 0.25s ease-in-out; 50 | } 51 | 52 | .search__list__item:hover { 53 | filter: none; 54 | } 55 | 56 | 57 | @media only screen and (min-width: 768px) { 58 | .search__container { 59 | top: auto; 60 | width: 25%; 61 | } 62 | } -------------------------------------------------------------------------------- /src/components/Search/Search.tsx: -------------------------------------------------------------------------------- 1 | import { connect } from "react-redux"; 2 | import { setSelectedPlace, setPlacePreviewVisibility, setSearchVisibility } from "../../store/actions"; 3 | import { IState, Place } from "../../store/models"; 4 | import {BiArrowBack} from "react-icons/bi" 5 | import "./Search.css"; 6 | 7 | const Search = ({ searchIsVisible, places, closeSearch, setSelectedPlace }: any) => { 8 | 9 | return ( 10 |
15 |
16 | closeSearch()}> 17 | Search 18 |
19 |
20 | {places.map((place: Place) => ( 21 |
setSelectedPlace(place) }> 22 |
23 | ))} 24 |
25 |
26 | ); 27 | }; 28 | 29 | const mapStateToProps = (state: IState) => { 30 | const { search, places } = state; 31 | return {searchIsVisible: search.searchIsVisible, places: places.places}; 32 | }; 33 | 34 | const mapDispatchToProps = (dispatch: any) => { 35 | return { 36 | closeSearch: () => 37 | dispatch(setSearchVisibility(false)), 38 | 39 | setSelectedPlace: (payload: Place) => 40 | { 41 | dispatch(setSelectedPlace(payload)); 42 | dispatch(setPlacePreviewVisibility(true)) 43 | }, 44 | }; 45 | }; 46 | 47 | export default connect(mapStateToProps, mapDispatchToProps)(Search); 48 | -------------------------------------------------------------------------------- /src/data.ts: -------------------------------------------------------------------------------- 1 | import { Place } from "./store/models"; 2 | export const data: Place[] = [ 3 | { 4 | title: "Eiffel Tower", 5 | description: 6 | "The Eiffel Tower (/ˈaɪfəl/ EYE-fəl; French: tour Eiffel [tuʁ‿ɛfɛl]) is a wrought-iron lattice tower on the Champ de Mars in Paris, France. It is named after the engineer Gustave Eiffel, whose company designed and built the tower.", 7 | picture: 8 | "https://t2.gstatic.com/images?q=tbn:ANd9GcQ8iFga8aDttbI5iBkKgDmqOSV7LdcsVkfDHezlLYWrGDT7OajbZJh4qS1kiNbN1kkUHmz4SWPOS98AC5HubKYyKw", 9 | position: [48.858222, 2.2945], 10 | seeMoreLink: "https://en.wikipedia.org/wiki/Eiffel_Tower", 11 | }, 12 | 13 | { 14 | title: "Louvre Museum", 15 | description: 16 | "The Louvre (English: /ˈluːv(rə)/ LOOV(-rə)[3]), or the Louvre Museum (French: Musée du Louvre [myze dy luvʁ]), is the world's largest art museum and a historic monument in Paris, France. A central landmark of the city, it is located on the Right Bank of the Seine in the city's 1st arrondissement (district or ward). Approximately 38,000 objects from prehistory to the 21st century are exhibited over an area of 72,735 square meters (782,910 square feet). In 2019, the Louvre received 9.6 million visitors, making it the most visited museum in the world.", 17 | picture: 18 | "https://media-exp1.licdn.com/dms/image/C4D1BAQHRblI0BcMdMg/company-background_10000/0/1552905854220?e=2159024400&v=beta&t=l1ZJjkecqUDP1QjmmdY8TvCJHY5e2YM41UuTWCEKa7c", 19 | position: [48.861111, 2.336389], 20 | seeMoreLink: "https://en.wikipedia.org/wiki/Louvre", 21 | }, 22 | { 23 | title: "Notre-Dame de Paris", 24 | description: 25 | 'Notre-Dame de Paris (French: [nɔtʁə dam də paʁi]; meaning "Our Lady of Paris"), referred to simply as Notre-Dame,is a medieval Catholic cathedral on the Île de la Cité in the 4th arrondissement of Paris. The cathedral was consecrated to the Virgin Mary and considered to be one of the finest examples of French Gothic architecture. Its pioneering use of the rib vault and flying buttress, its enormous and colourful rose windows, as well as the naturalism and abundance of its sculptural decoration set it apart from the earlier Romanesque style. Major components that make Notre Dame stand out include its large historic organ and its immense church bells.', 26 | picture: 27 | "https://t1.gstatic.com/images?q=tbn:ANd9GcTP7Kev8E9D4tRQx70zbwJejhXbrWDSHe4YPnZRm2_iF3yXnB-J8_f6BbJov2HUz1IWVM2tpRLR2QEqkfyEkIsX1Q", 28 | position: [48.853, 2.3498], 29 | seeMoreLink: "https://en.wikipedia.org/wiki/Notre-Dame_de_Paris", 30 | }, 31 | { 32 | title: "Arc de Triomphe", 33 | description: 34 | "The Arc de Triomphe de l'Étoile, lit. 'Triumphal Arch of the Star') is one of the most famous monuments in Paris, France, standing at the western end of the Champs-Élysées at the centre of Place Charles de Gaulle, formerly named Place de l'Étoile—the étoile or \"star\" of the juncture formed by its twelve radiating avenues. The location of the arc and the plaza is shared between three arrondissements, 16th (south and west), 17th (north), and 8th (east). The Arc de Triomphe honours those who fought and died for France in the French Revolutionary and Napoleonic Wars, with the names of all French victories and generals inscribed on its inner and outer surfaces. Beneath its vault lies the Tomb of the Unknown Soldier from World War I.", 35 | picture: 36 | "https://t0.gstatic.com/images?q=tbn:ANd9GcQoZnddnNXMsy0UgYRljMrNsvL_HgNLqIJEfaeIqbfEVTiPKpm-ixUaV24h0dplYQRRE-HRH1kncMV2elUz70ensw", 37 | position: [48.8738, 2.295], 38 | seeMoreLink: "https://en.wikipedia.org/wiki/Arc_de_Triomphe", 39 | }, 40 | { 41 | title: "Basilica of the Sacred Heart of Jesus", 42 | description: 43 | "The Basilica of the Sacred Heart of Paris, commonly known as Sacré-Cœur Basilica and often simply Sacré-Cœur (French: Basilique du Sacré-Cœur, pronounced [sakʁe kœʁ]), is a Roman Catholic church and minor basilica, dedicated to the Sacred Heart of Jesus, in Paris, France.", 44 | picture: 45 | "https://i.f1g.fr/media/_uploaded/805x1000_crop/quiz-sacr%C3%A9-coeur/quiz-sacre-coeur.jpg", 46 | position: [48.886694, 2.343], 47 | seeMoreLink: "https://en.wikipedia.org/wiki/Sacré-Cœur,_Paris", 48 | }, 49 | { 50 | title: "Musée d'Orsay", 51 | description: 52 | "The Musée d'Orsay (UK: /ˌmjuːzeɪ dɔːrˈseɪ/ MEW-zay dor-SAY, US: /mjuːˈzeɪ -/ mew-ZAY -⁠, French: [myze dɔʁsɛ]) is a museum in Paris, France, on the Left Bank of the Seine. It is housed in the former Gare d'Orsay, a Beaux-Arts railway station built between 1898 and 1900. The museum holds mainly French art dating from 1848 to 1914, including paintings, sculptures, furniture, and photography. It houses the largest collection of Impressionist and post-Impressionist masterpieces in the world, by painters including Monet, Manet, Degas, Renoir, Cézanne, Seurat, Sisley, Gauguin, and Van Gogh. Many of these works were held at the Galerie nationale du Jeu de Paume prior to the museum's opening in 1986. It is one of the largest art museums in Europe. Musée d'Orsay had more than 3.6 million visitors in 2019.", 53 | picture: 54 | "https://aws-tiqets-cdn.imgix.net/images/content/2e18da2affe84093a455ee0349673772.jpg?auto=format&fit=crop&ixlib=python-3.2.1&q=25&s=63adb11bd0001a73e66aab61e54489cf&w=375&h=250&dpr=2.625", 55 | position: [48.86, 2.326389], 56 | seeMoreLink: "https://en.wikipedia.org/wiki/Musée_d'Orsay", 57 | }, 58 | ]; 59 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | import { Provider } from "react-redux"; 7 | import store from "./store"; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | 13 | 14 | , 15 | document.getElementById("root") 16 | ); 17 | 18 | // If you want to start measuring performance in your app, pass a function 19 | // to log results (for example: reportWebVitals(console.log)) 20 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 21 | reportWebVitals(); 22 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/store/actions/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./places"; 2 | export * from "./search"; 3 | -------------------------------------------------------------------------------- /src/store/actions/places.ts: -------------------------------------------------------------------------------- 1 | import { LatLngExpression } from "leaflet"; 2 | import { Place } from "../models"; 3 | 4 | export const SET_ALL_PLACES = "SET_ALL_PLACES"; 5 | export const SET_SELECTED_PLACE = "SET_SELECTED_PLACE"; 6 | export const SET_PLACE_PREVIEW_VISIBILITY = "SET_PLACE_PREVIEW_VISIBILITY"; 7 | export const SET_PLACE_FORM_VISIBILITY = "SET_PLACE_FORM_VISIBILITY"; 8 | export const SET_PRE_PLACE_LOCATION = "SET_PRE_PLACE_LOCATION"; 9 | export const ADD_NEW_PLACE = "ADD_NEW_PLACE"; 10 | 11 | export const setAllPlaces = (places: Place[]) => ({ 12 | type: SET_ALL_PLACES, 13 | payload: places, 14 | }); 15 | 16 | export const setSelectedPlace = (place: Place) => ({ 17 | type: SET_SELECTED_PLACE, 18 | payload: place, 19 | }); 20 | 21 | export const setPlacePreviewVisibility = (show: boolean) => ({ 22 | type: SET_PLACE_PREVIEW_VISIBILITY, 23 | payload: show, 24 | }); 25 | 26 | export const setPlaceFormVisibility = (show: boolean) => ({ 27 | type: SET_PLACE_FORM_VISIBILITY, 28 | payload: show, 29 | }); 30 | 31 | export const setPrePlaceLocation = (payload: LatLngExpression) => ({ 32 | type: SET_PRE_PLACE_LOCATION, 33 | payload, 34 | }); 35 | 36 | export const addNewPlace = (payload: Place) => ({ 37 | type: ADD_NEW_PLACE, 38 | payload, 39 | }); 40 | -------------------------------------------------------------------------------- /src/store/actions/search.ts: -------------------------------------------------------------------------------- 1 | export const SET_SEARCH_VISIBILITY = "SET_SEARCH_VISIBILITY"; 2 | 3 | export const setSearchVisibility = (show: boolean) => ({ 4 | type: SET_SEARCH_VISIBILITY, 5 | payload: show, 6 | }); 7 | -------------------------------------------------------------------------------- /src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { createStore } from "redux"; 2 | import rootReducer from "./reducers"; 3 | 4 | export default createStore( 5 | rootReducer, 6 | (window as any)?.__REDUX_DEVTOOLS_EXTENSION__ && 7 | (window as any)?.__REDUX_DEVTOOLS_EXTENSION__() 8 | ); 9 | -------------------------------------------------------------------------------- /src/store/models.ts: -------------------------------------------------------------------------------- 1 | import { LatLngExpression } from "leaflet"; 2 | 3 | export interface SearchState { 4 | searchIsVisible: boolean; 5 | } 6 | 7 | export interface PlaceState { 8 | places: Place[]; 9 | selectedPlace: Place | null; 10 | placePreviewsIsVisible: boolean; 11 | placeFormIsVisible: boolean; 12 | prePlacePosition: LatLngExpression; 13 | } 14 | 15 | export interface IState { 16 | search: SearchState; 17 | places: PlaceState; 18 | } 19 | 20 | export interface Place { 21 | picture: string; 22 | title: string; 23 | description: string; 24 | seeMoreLink: string; 25 | position: LatLngExpression; 26 | } 27 | -------------------------------------------------------------------------------- /src/store/reducers/index.ts: -------------------------------------------------------------------------------- 1 | import { combineReducers } from "redux"; 2 | import places from "./places"; 3 | import search from "./search"; 4 | 5 | export default combineReducers({ places, search }); 6 | -------------------------------------------------------------------------------- /src/store/reducers/places.ts: -------------------------------------------------------------------------------- 1 | import { 2 | SET_ALL_PLACES, 3 | SET_SELECTED_PLACE, 4 | SET_PLACE_PREVIEW_VISIBILITY, 5 | SET_PLACE_FORM_VISIBILITY, 6 | SET_PRE_PLACE_LOCATION, 7 | ADD_NEW_PLACE, 8 | } from "../actions"; 9 | import { PlaceState } from "../models"; 10 | import { data } from "../../data"; 11 | import { LatLngExpression } from "leaflet"; 12 | 13 | const initialState: PlaceState = { 14 | places: data, 15 | selectedPlace: null, 16 | placePreviewsIsVisible: false, 17 | placeFormIsVisible: false, 18 | prePlacePosition: (null as unknown) as LatLngExpression, 19 | }; 20 | 21 | const productsReducer = ( 22 | state: PlaceState = initialState, 23 | action: { type: string; payload: any } 24 | ): PlaceState => { 25 | switch (action.type) { 26 | case SET_ALL_PLACES: { 27 | return { ...state, places: action.payload }; 28 | } 29 | case SET_SELECTED_PLACE: { 30 | return { ...state, selectedPlace: action.payload }; 31 | } 32 | case SET_PLACE_PREVIEW_VISIBILITY: { 33 | return { ...state, placePreviewsIsVisible: action.payload }; 34 | } 35 | case SET_PLACE_FORM_VISIBILITY: { 36 | return { ...state, placeFormIsVisible: action.payload }; 37 | } 38 | case SET_PRE_PLACE_LOCATION: { 39 | return { ...state, prePlacePosition: action.payload }; 40 | } 41 | case ADD_NEW_PLACE: { 42 | return { ...state, places: [...state.places, action.payload] }; 43 | } 44 | default: { 45 | return state; 46 | } 47 | } 48 | }; 49 | 50 | export default productsReducer; 51 | -------------------------------------------------------------------------------- /src/store/reducers/search.ts: -------------------------------------------------------------------------------- 1 | import { SET_SEARCH_VISIBILITY } from "../actions"; 2 | import { SearchState } from "../models"; 3 | 4 | const initialState: SearchState = { 5 | searchIsVisible: false, 6 | }; 7 | 8 | const searchReducer = ( 9 | state = initialState, 10 | action: { type: string; payload: any } 11 | ) => { 12 | switch (action.type) { 13 | case SET_SEARCH_VISIBILITY: { 14 | return { ...state, searchIsVisible: action.payload }; 15 | } 16 | default: { 17 | return state; 18 | } 19 | } 20 | }; 21 | 22 | export default searchReducer; 23 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | --------------------------------------------------------------------------------