Skip to content

Commit

Permalink
pinia using storeToRefs
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlumbcgov committed Jul 18, 2023
1 parent 8c017c4 commit f9d65ab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
14 changes: 3 additions & 11 deletions frontend/src/components/DistrictSelect.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useAppStore } from '@/stores/app'
import { mapState } from 'pinia'
import { storeToRefs } from 'pinia'
import router from '@/router'
const appStore = useAppStore()
//const districts = appStore.getDistricts
const districts = computed({
get() {
return appStore.getDistricts
},
set(newValue) {
console.log(newValue) //TODO set districts in store? what am I doing here
}
})
const { districts } = storeToRefs(appStore)
const selectedDistrict = ref({}) // placeholder
function goToDistrict() {
Expand All @@ -30,7 +22,7 @@ function goToDistrict() {

<template>
<div>
{{ selectedDistrict }}
<!-- {{ districts }} -->
<!-- <v-autocomplete
v-model="selectedDistrict"
label="Select a District"
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/stores/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineStore } from 'pinia';
import { storeToRefs, defineStore } from 'pinia';

interface District {
districtId: string;
Expand Down Expand Up @@ -42,11 +42,11 @@ export const useAppStore = defineStore('app', {
}
},
getters: {
getDistricts(): District[] {
return this.districts;
getDistricts: (state) => {
return () => state.districts
},
getSchools(): School[] {
return this.schools;
getSchools: (state) => {
return () => state.schools
}
}
});
4 changes: 2 additions & 2 deletions frontend/src/views/ListDistricts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</template>
<script>
import { useAppStore } from '@/stores/app'
import { toRefs, watchEffect } from 'vue';
import { storeToRefs } from 'pinia'
export default {
setup() {
const appStore = useAppStore()
const { districts } = toRefs(appStore);
const { districts } = storeToRefs(appStore);
return { districts }
}
}
Expand Down

0 comments on commit f9d65ab

Please sign in to comment.