🚧 Register a Widget to display stories from HN

This commit is contained in:
Josua Blejeru
2023-05-22 21:57:09 +02:00
parent 2ec404121a
commit 1a42a41a53
3 changed files with 62 additions and 10 deletions

View File

@@ -0,0 +1,54 @@
<template>
<div class="hackernews-wrapper">
<h3>Hackernews Trending</h3>
<!-- Hackernews Trending Posts-->
<div class="posts-wrapper">
</div>
</div>
</template>
<script>
// import axios from 'axios';
import WidgetMixin from '@/mixins/WidgetMixin';
import { widgetApiEndpoints } from '@/utils/defaults';
export default {
mixins: [WidgetMixin],
data() {
return {
trendingPosts: null,
};
},
filters: {
debug() { console.debug('Not implemented'); },
},
computed: {
storyType() {
// This can be `beststories`, `topstories` or newstories
return this.options.stories || 'beststories';
},
limit() {
return this.options.limit || 10;
},
endpoint() {
return `${widgetApiEndpoints.hackernewsTrending}/${this.storyType}.json`
},
},
methods: {
fetchData() {
console.log("Let's fetch some Data");
this.makeRequest(this.endpoint).then(this.fetchPostDetails)
},
async fetchPostDetails(data) {
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))
},
},
};
</script>

View File

@@ -78,6 +78,7 @@ const COMPAT = {
'gl-system-load': 'GlSystemLoad',
'gl-cpu-temp': 'GlCpuTemp',
'health-checks': 'HealthChecks',
'hackernews-trending': 'HackernewsTrending',
'gluetun-status': 'GluetunStatus',
iframe: 'IframeWidget',
image: 'ImageWidget',