stadtratmonitor-vue/src/components/Papers.vue

87 lines
2.2 KiB
Vue
Raw Normal View History

2023-06-14 18:12:42 +02:00
<script lang="ts">
2023-06-14 22:51:55 +02:00
export type Papers = {
2023-06-14 18:12:42 +02:00
body: string
content: string
name: string
resolution: string
originator: string
paper_type: string
published_at: string
reference: string
url: string
}
export default {
created() {
this.fetchData()
},
2023-06-14 22:51:55 +02:00
updated() {
this.$emit('papers', this.papers)
},
2023-06-14 18:12:42 +02:00
data() {
return {
apiUri: 'https://raw.githubusercontent.com/CodeforLeipzig/stadtratmonitor/master/input.json',
papers: [] as Papers[],
}
},
props: {
2023-06-16 15:23:23 +02:00
paperQuery: Object,
paperFilter: Object,
2023-06-14 18:12:42 +02:00
},
computed: {
filteredData() {
2023-06-16 15:23:23 +02:00
const paperQuery: String = this.paperQuery?.value
2023-06-14 22:51:55 +02:00
let filteredPapers: Papers[] = this.papers
2023-06-16 15:23:23 +02:00
if (paperQuery !== '') {
2023-06-14 22:51:55 +02:00
filteredPapers = this.papers.filter((paper) => {
2023-06-16 15:23:23 +02:00
return paper.name.toLowerCase().includes(paperQuery.toLowerCase())
2023-06-14 22:51:55 +02:00
})
}
if (this.paperFilter?.type !== '') {
filteredPapers = filteredPapers.filter((paper) => {
2023-06-16 15:29:25 +02:00
return paper.reference.includes(this.paperFilter?.type.key) && paper.paper_type.includes(this.paperFilter?.type.value)
2023-06-14 22:51:55 +02:00
})
}
2023-06-16 15:30:38 +02:00
if (this.paperFilter?.originator !== '') {
filteredPapers = filteredPapers.filter((paper) => {
return paper.originator.includes(this.paperFilter?.originator)
})
}
2023-06-14 18:12:42 +02:00
return filteredPapers
}
},
methods: {
async fetchData() {
this.papers = await (await fetch(this.apiUri)).json()
},
openPaper() {}
},
}
</script>
<template>
2023-06-16 15:30:38 +02:00
<ul
v-if="filteredData.length"
2023-06-16 21:03:41 +02:00
class="w-full grid grid-flow-row gap-2 my-2"
2023-06-16 15:30:38 +02:00
>
2023-06-14 18:12:42 +02:00
<li v-for="(paper, i) in filteredData" :key="i">
<article
2023-06-16 21:03:41 +02:00
class="p-4 rounded-lg bg-background-100 dark:bg-background-900"
2023-06-14 18:12:42 +02:00
@click.prevent="openPaper()"
>
<h4 class="text-xl">{{ paper.name }}</h4>
<p>{{ paper.published_at }}: {{ paper.paper_type}} von {{ paper.originator }}</p>
</article>
</li>
</ul>
<p
class="flex place-content-center my-60 text-lg"
v-else-if="papers.length"
>Für dieses Anfrage liegen uns keine Ergebnisse vor.
</p>
<p
class="flex place-content-center my-60 text-lg"
v-else
>Da scheint etwas schief gelaufen zu sein.
</p>
</template>