Skip to content

Commit

Permalink
finished project with local data
Browse files Browse the repository at this point in the history
  • Loading branch information
john-smilga committed Aug 1, 2019
1 parent 2ce3c3d commit 9c06f54
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions src/context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from "react";
// import items from "./data";
import items from "./data";
import Client from "./Contentful";

const RoomContext = React.createContext();
Expand All @@ -22,49 +22,49 @@ export default class RoomProvider extends Component {
pets: false
};

getData = async () => {
try {
let response = await Client.getEntries({
content_type: "beachResortRoom"
});
let rooms = this.formatData(response.items);
// getData = async () => {
// try {
// let response = await Client.getEntries({
// content_type: "beachResortRoom"
// });
// 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);
}
};
// 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);
// }
// };

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

0 comments on commit 9c06f54

Please sign in to comment.