fix global state (still massively wip)

This commit is contained in:
Vri 🌈 2023-06-27 12:38:14 +02:00
parent 71dc064ab6
commit dc98b0bf37
Signed by: vrifox
GPG key ID: D40098E5B60B2197
2 changed files with 22 additions and 32 deletions

View file

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Paper, Search, Filter } from '@/types' import type { Paper, Search, Filter } from '@/types'
import { papers, topics, papersfetch } from '@/store' import { state, papersFetch } from '@/store'
import MainMenu from '@/components/MainMenu.vue' import MainMenu from '@/components/MainMenu.vue'
import SearchBar from '@/components/SearchBar.vue' import SearchBar from '@/components/SearchBar.vue'
import FilterView from './components/papers/FilterView.vue' import FilterView from './components/papers/FilterView.vue'
@ -20,8 +20,7 @@ let filter: Filter = {
}, },
originator: '', originator: '',
} }
onMounted (() => papersfetch() ) onMounted (() => papersFetch() )
/* onMounted(() => topics.process() ) */
</script> </script>
<template> <template>
@ -42,7 +41,7 @@ onMounted (() => papersfetch() )
</header> </header>
<main class="flex flex-row max-w-5xl m-auto"> <main class="flex flex-row max-w-5xl m-auto">
{{ papers }} {{ state.topics }}
<RouterView <RouterView
:search="search" :search="search"
:filter="filter" :filter="filter"

View file

@ -1,34 +1,25 @@
import { reactive, ref } from 'vue' import { reactive } from 'vue'
import type { Paper, Topic } from '@/types' import type { Paper, Topic } from '@/types'
const apiUrl: URL = new URL('https://raw.githubusercontent.com/CodeforLeipzig/stadtratmonitor/master/input.json') const apiUrl: URL = new URL(
'https://raw.githubusercontent.com/CodeforLeipzig/stadtratmonitor/master/input.json'
)
export let papers: Array<Paper> = reactive([]) interface State {
export let topics: Array<Topic> = reactive([]) papers: Paper[]
topics: Topic[]
}
export async function papersfetch() { export const state: State = reactive({ papers: [], topics: [] })
papers = await (await fetch(apiUrl)).json()
/* const topicReferences = await [...new Set(papers?.map((paper: Paper) => paper.reference))] export async function papersFetch() {
topics = await topicReferences.map( (reference: string) => { const papersData: Paper[] = await (await fetch(apiUrl)).json()
const topicReferences = await [...new Set(papersData?.map((paper) => paper.reference))]
state.papers = papersData
state.topics = await topicReferences.map((reference) => {
return { return {
'reference': reference, reference: reference,
'papers': papers?.filter( (paper: Paper) => paper.reference === reference), papers: papersData?.filter((paper: Paper) => paper.reference === reference)
} }
}) */ })
} }
/* export function paperprocess() */
/* export const test = reactive({
testi: papers.papers,
funk() {
return [...new Set(papers.papers?.map((paper: Paper) => paper.reference))]
}
}) */
/* export const = reactive({
topics: Array<Topic>,
topicReferences: Set<String>,
async process() {
},
}) */