{{ post.text }}
{{ comment.text }}
let fs = window.fs || {}; fs.data = { posts: [], posts_details: [], users_details: [], }; fs.next_posts_page = null; fs.fetch_next_posts_page = function() { if (fs.next_posts_page === null || fs.next_posts_page === undefined) { return new Promise(function(resolve, reject) { reject(null); }); } return fetch(fs.next_posts_page).then(function(response) { if (response.status !== 200) { console.log('Error getting posts page:', response.status); return; } return response.json().then(function(data) { for (let i=data.posts.length-1; i>=0; i--) { fs.data.posts.push(data.posts[i]); } fs.next_posts_page = data.previous_page; return data; }); }); }; fetch('/data/posts.json').then(function(response) { if (response.status !== 200) { console.log('Error getting main posts page:', response.status); return; } return response.json().then(function(data) { fs.next_posts_page = data.last_page; return fs.fetch_next_posts_page().then(function() { return fs.fetch_next_posts_page().catch(function() {}); }); }); }); fs._fetch_details = function(location, id, variable_store) { var url = location + id + '.json'; return fetch(url) .then(function(response) { if (response.status !== 200) { console.log('Error getting details:', response.status); return; } return response.json().then(function(data) { variable_store[id] = data; return data; }); }); }; fs.get_post_details = function(post_id) { if (fs.data.posts_details[post_id] !== undefined) { return new Promise(function(resolve, reject) { resolve(fs.data.posts_details[post_id]) }); } else { return fs._fetch_details('/data/posts/', post_id, fs.data.posts_details); } }; fs.get_user_details = function(user_id) { if (fs.data.users_details[user_id] !== undefined) { return new Promise(function(resolve, reject) { resolve(fs.data.users_details[user_id]) }); } else { return fs._fetch_details('/data/users/', user_id, fs.data.users_details); } }; window.onscroll = function onScroll() { if (window.innerHeight + window.pageYOffset >= document.body.offsetHeight) { window.onscroll = null; fs.fetch_next_posts_page().then(function() { window.onscroll = onScroll; }).catch(function() {}); } }; const Post = { props: ['post', 'is_route'], data: function() { return { post_details: null, }; }, template: `
`, created: function() { this.fetchData(); }, methods: { fetchData: function() { if (this.is_route === true) { let self = this; fs.get_post_details(this.post.id).then(function(post_details) { self.post_details = post_details; }); } }, }, }; const PostRoute = { data: function() { return { post: null, } }, template: `