diff --git a/src/components/Widgets/HackernewsTrending.vue b/src/components/Widgets/HackernewsTrending.vue index 348d5783..a61ac64c 100644 --- a/src/components/Widgets/HackernewsTrending.vue +++ b/src/components/Widgets/HackernewsTrending.vue @@ -1,10 +1,20 @@ @@ -21,34 +31,126 @@ export default { trendingPosts: null, }; }, - filters: { - debug() { console.debug('Not implemented'); }, - }, computed: { storyType() { // This can be `beststories`, `topstories` or newstories - return this.options.stories || 'beststories'; + // TODO: display error message if another string not matching the keywords was insert + return this.options.stories || 'topstories'; }, limit() { return this.options.limit || 10; }, endpoint() { - return `${widgetApiEndpoints.hackernewsTrending}/${this.storyType}.json` + return `${widgetApiEndpoints.hackernewsTrending}/${this.storyType}.json`; }, }, methods: { fetchData() { - console.log("Let's fetch some Data"); - this.makeRequest(this.endpoint).then(this.fetchPostDetails) + this.makeRequest(this.endpoint).then(this.fetchPostDetails); }, async fetchPostDetails(data) { - const topPosts = data.slice(0, this.limit) + const topPosts = data.slice(0, this.limit); const allData = topPosts.map((post) => { const url = `${widgetApiEndpoints.hackernewsTrending}/item/${post}.json`; return this.makeRequest(url); }) - Promise.all(allData).then((values) => console.log(values)) + Promise.all(allData).then((resolvedPostValues) => { + this.trendingPosts = resolvedPostValues.map((element, index) => { + element.originURL = `https://news.ycombinator.com/item?id=${topPosts.at(index)}` + return element + }); + console.log(this.trendingPosts) + }); }, + formatDate(unixTime) { + const date = new Date(unixTime * 1000); + // Then specify how you want your dates to be formatted + return new Intl.DateTimeFormat('default', {dateStyle: 'long'}).format(date); + } }, }; + +