/* In today’s project, we’re going to build an app that lets you find interesting things to do near where you live. I have a simple API setup with some data from the quirkiest state in the United States: Rhode Island. */
var app = new Reef('#app', { data: {}, template: function (props) { if (props.posts && props.posts.length) { let html = '<div class="container">' + props.posts.map(function (post) { return`<div class="post-container"><div class="miniature-container"><img class="minature" src="${post.img}" /></div><div class="info-container"><h2 class="title">${post.place}</h2><p>${post.description}</p><p><em>${post.location}</em></p><a href=${post.url} target="_blank">Read more</a></div></div>`; }).join('') + '</div>'; return html; } let html = '<p>Unable to find any places right now.</p>' return html; } }); const getPosts = function () { fetch('https://vanillajsacademy.com/api/places.json').then(function (response) { if (response.ok) { return response.json(); } returnPromise.reject(response); }).then(function (data) { app.data.posts = data; }).catch(function (error) { console.warn(error); app.data.posts = null; }) } getPosts();