Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
arpit2425 committed May 25, 2020
1 parent 2455d0b commit ed264ee
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 192 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.DS_Store
.env.local
.env.development.local
.env.development
.env.test.local
.env.production.local

Expand Down
338 changes: 330 additions & 8 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"contentful": "^7.14.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Contentful.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createClient } from "contentful";

export default createClient({
space: process.env.REACT_APP_API_SPACE,
accessToken: process.env.REACT_APP_ACCESS_TOKEN,
});
51 changes: 0 additions & 51 deletions src/components/RoomsFilter.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
// import React, { useContext } from "react";
// import { RoomContext } from "./../context";
// import Title from "./Title";
// function RoomsFilter({ rooms }) {
// const context = useContext(RoomContext);
// const getUnique = (items, value) => {
// return [...new Set(items.map((item) => item[value]))];
// };
// const {
// handleChange,
// type,
// pets,
// breakfast,
// capacity,
// price,
// minPrice,
// maxPrice,
// minSize,
// maxSize,
// } = context;
// let types = getUnique(rooms, "type");
// types = ["all", ...types];
// types = types.map((item, index) => {
// return (
// <option value={item} key={index}>
// {item}
// </option>
// );
// });
// return (
// <section className="filter-container">
// <Title title="Search Rooms" />
// <form className="filter-form">
// <div className="form-group">
// <label htmlFor="type">room type</label>
// <select
// name="type"
// id="type"
// value={type}
// className="form-control"
// onChange={handleChange}
// >
// {types}
// </select>
// </div>
// </form>
// </section>
// );
// }

// export default RoomsFilter;
import React from "react";
import { useContext } from "react";
import { RoomContext } from "../context";
Expand Down
171 changes: 40 additions & 131 deletions src/context.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,6 @@
// import React, { Component } from "react";
// import items from "./data";
// const RoomContext = React.createContext();

// class RoomProvider extends Component {
// state = {
// rooms: [],
// featuredRooms: [],
// sortedRooms: [],
// loading: true,
// type: "all",
// minPrice: 0,
// minSize: 0,
// maxPrice: 0,
// price: 0,
// maxSize: 0,
// capacity: 1,
// pets: false,
// breakfast: false,
// };
// handleChange = (event) => {
// const target = event.target;

// const value = event.type === "checkbox" ? target.checked : target.value;
// const name = event.target.name;
// this.setState(
// {
// [name]: value,
// },
// this.filterRooms
// );
// };
// filterRooms = () => {
// console.log("hello");
// // let {
// // rooms,
// // type,
// // pets,
// // breakfast,
// // capacity,
// // price,
// // minPrice,
// // maxPrice,
// // minSize,
// // maxSize,
// // } = this.state;
// // let tempRoom = [...rooms];
// // if (type !== "all") {
// // tempRoom = tempRoom.filter((item) => item.type === type);
// // }
// // this.setState({ sortedRooms: tempRoom });
// };
// componentDidMount() {
// let rooms = this.formatData(items);
// let featuredRooms = rooms.filter((room) => room.featured === true);
// let maxPrice = Math.max(...rooms.map((item) => item.price));
// let maxSize = Math.max(...rooms.map((item) => item.size));
// this.setState({
// rooms,
// featuredRooms,
// loading: false,
// sortedRooms: rooms,
// maxPrice,
// maxSize,
// });
// }
// getRoom = (slug) => {
// let tempRoom = [...this.state.rooms];
// let room = tempRoom.find((room) => room.slug === slug);
// return room;
// };
// formatData(items) {
// const tempItems = items.map((item) => {
// let id = item.sys.id;
// let images = item.fields.images.map((image) => image.fields.file.url);
// let room = { ...item.fields, images, id };
// return room;
// });
// return tempItems;
// }
// render() {
// return (
// <RoomContext.Provider value={{ ...this.state, getRoom: this.getRoom }}>
// {this.props.children}
// </RoomContext.Provider>
// );
// }
// }
// const RoomConsumer = RoomContext.Consumer;
// export { RoomContext, RoomConsumer, RoomProvider };

import React, { Component } from "react";
import items from "./data";
// import Client from "./Contentful";
// import items from "./data";
import Client from "./Contentful";

const RoomContext = React.createContext();
// <RoomContext.Provider value={'hello'}
Expand All @@ -112,47 +21,47 @@ class RoomProvider extends Component {
pets: false,
};
// getData
// getData = async () => {
// try {
// let response = await Client.getEntries({
// content_type: "beachResortRoom",
// // order: "sys.createdAt"
// order: "-fields.price"
// });
// let rooms = this.formatData(response.items);
// let featuredRooms = rooms.filter(room => room.featured === true);
// let maxPrice = Math.max(...rooms.map(item => item.price));
// let maxSize = Math.max(...rooms.map(item => item.size));
getData = async () => {
try {
let response = await Client.getEntries({
content_type: "beachResort",
// order: "sys.createdAt"
order: "-fields.price",
});
let rooms = this.formatData(response.items);
let featuredRooms = rooms.filter((room) => room.featured === true);
let maxPrice = Math.max(...rooms.map((item) => item.price));
let maxSize = Math.max(...rooms.map((item) => item.size));

// this.setState({
// rooms,
// featuredRooms,
// sortedRooms: rooms,
// loading: false,
// price: maxPrice,
// maxPrice,
// maxSize
// });
// } catch (error) {
// console.log(error);
// }
// };
this.setState({
rooms,
featuredRooms,
sortedRooms: rooms,
loading: false,
price: maxPrice,
maxPrice,
maxSize,
});
} catch (error) {
console.log(error);
}
};

componentDidMount() {
// this.getData();
let rooms = this.formatData(items);
let featuredRooms = rooms.filter((room) => room.featured === true);
let maxPrice = Math.max(...rooms.map((item) => item.price));
let maxSize = Math.max(...rooms.map((item) => item.size));
this.setState({
rooms,
featuredRooms,
sortedRooms: rooms,
loading: false,
price: maxPrice,
maxPrice,
maxSize,
});
this.getData();
// let rooms = this.formatData(items);
// let featuredRooms = rooms.filter((room) => room.featured === true);
// let maxPrice = Math.max(...rooms.map((item) => item.price));
// let maxSize = Math.max(...rooms.map((item) => item.size));
// this.setState({
// rooms,
// featuredRooms,
// sortedRooms: rooms,
// loading: false,
// price: maxPrice,
// maxPrice,
// maxSize,
// });
}

formatData(items) {
Expand Down
56 changes: 54 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,13 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.1.tgz#7e33d8f7d449b3f673cd72deb9abdc552dbe528e"
integrity sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==

axios@^0.19.1:
version "0.19.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
dependencies:
follow-redirects "1.5.10"

axobject-query@^2.0.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.1.2.tgz#2bdffc0371e643e5f03ba99065d5179b9ca79799"
Expand Down Expand Up @@ -3401,6 +3408,32 @@ content-type@~1.0.4:
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==

contentful-resolve-response@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/contentful-resolve-response/-/contentful-resolve-response-1.1.4.tgz#9eb656876eecb2cd00444f0adf26bd91a5ec1992"
integrity sha512-oFq6n6zjbiwD9/7mBa8YHPwvPM0B0D4uOgg1n/rVzpQPhCrzeIixNj6fbJAbDiJt05rZqxiY3K1Db7pPRhRaZw==
dependencies:
lodash "^4.17.4"

contentful-sdk-core@^6.4.5:
version "6.4.5"
resolved "https://registry.yarnpkg.com/contentful-sdk-core/-/contentful-sdk-core-6.4.5.tgz#e73f4c5426f354608543fc73e46c17c6730180e9"
integrity sha512-rygNuiwbG6UKrJg6EDlaKewayTeLWrjA2wJwVmq7rV/DYo0cic6t28y0EMhRQ4pgJDV5HyUQFoFeBm2lwLfG2Q==
dependencies:
lodash "^4.17.10"
qs "^6.5.2"

contentful@^7.14.4:
version "7.14.4"
resolved "https://registry.yarnpkg.com/contentful/-/contentful-7.14.4.tgz#882c2785cab953c0729453f60dbb8acd556f5f6a"
integrity sha512-BY5mEr8DkPxVPot4aMurtuOqf9HxkXW6T9KRDUtJcxua/sAITjYu3YOeZG8PeNGYI40R5yqIvpJ6vMI+/lg4Fg==
dependencies:
axios "^0.19.1"
contentful-resolve-response "^1.1.4"
contentful-sdk-core "^6.4.5"
json-stringify-safe "^5.0.1"
lodash "^4.17.11"

[email protected], convert-source-map@^1.4.0, convert-source-map@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442"
Expand Down Expand Up @@ -3835,6 +3868,13 @@ [email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
dependencies:
ms "2.0.0"

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

debug@^3.0.0, debug@^3.1.1, debug@^3.2.5:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
Expand Down Expand Up @@ -4887,6 +4927,13 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"

[email protected]:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"

follow-redirects@^1.0.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.10.0.tgz#01f5263aee921c6a54fb91667f08f4155ce169eb"
Expand Down Expand Up @@ -6569,7 +6616,7 @@ json-stable-stringify@^1.0.1:
dependencies:
jsonify "~0.0.0"

json-stringify-safe@~5.0.1:
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=
Expand Down Expand Up @@ -6835,7 +6882,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.5:
"lodash@>=3.5 <5", lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.17.5:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down Expand Up @@ -8822,6 +8869,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==

qs@^6.5.2:
version "6.9.4"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==

qs@~6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
Expand Down

0 comments on commit ed264ee

Please sign in to comment.