Clean vuex

This commit is contained in:
Hubert Van De Walle 2020-07-05 14:57:09 +02:00
parent ccb046a08a
commit 8c6c40cd78
4 changed files with 11 additions and 11 deletions

View File

@ -7,11 +7,11 @@
:key="link.name" :key="link.name"
class="text-blue-200" class="text-blue-200"
> >
<router-link <nuxt-link
v-if="link.url" v-if="link.url"
:to="link.url" :to="link.url"
class="underline" class="underline"
>{{ link.name }}</router-link >{{ link.name }}</nuxt-link
> >
<button v-else class="underline" @click="link.action"> <button v-else class="underline" @click="link.action">
{{ link.name }} {{ link.name }}

View File

@ -9,7 +9,7 @@
</template> </template>
<script> <script>
import { mapState, mapActions } from 'vuex' import { mapState, mapActions, mapGetters } from 'vuex'
import renderMarkdown from '@/utils/markdown' import renderMarkdown from '@/utils/markdown'
export default { export default {
@ -20,6 +20,7 @@ export default {
}), }),
computed: { computed: {
...mapState('notes', ['notes', 'isInitialized']), ...mapState('notes', ['notes', 'isInitialized']),
...mapGetters('notes', ['find']),
uuid() { uuid() {
return this.$route.params.uuid return this.$route.params.uuid
}, },
@ -27,11 +28,11 @@ export default {
mounted() { mounted() {
if (!this.isInitialized) { if (!this.isInitialized) {
this.load().then(() => { this.load().then(() => {
this.note = this.notes.find((e) => e.uuid === this.uuid) this.note = this.find(this.uuid)
this.render() this.render()
}) })
} else { } else {
this.note = this.notes.find((e) => e.uuid === this.uuid) this.note = this.find(this.uuid)
this.render() this.render()
} }
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="container p-4 mx-auto bg-gray-700"> <div class="container p-4 mx-auto bg-gray-800">
<h1 class="text-center">My Notes</h1> <h1 class="text-center">My Notes</h1>
<input <input
id="search" id="search"
@ -10,9 +10,9 @@
/> />
<div v-for="note in notes" :key="note.uuid"> <div v-for="note in notes" :key="note.uuid">
<div class="flex justify-between items-center"> <div class="flex justify-between items-center">
<router-link :to="'/notes/' + note.uuid" class="text-lg">{{ <nuxt-link :to="'/notes/' + note.uuid" class="text-lg">{{
note.title note.title
}}</router-link> }}</nuxt-link>
<div class="py-2"> <div class="py-2">
<span <span
v-for="(tag, index) in note.tags" v-for="(tag, index) in note.tags"

View File

@ -48,7 +48,6 @@ export const actions = {
} }
export const getters = { export const getters = {
isEmpty(state) { isEmpty: (state) => state.isInitialized && state.notes.length === 0,
return state.isInitialized && state.notes.length === 0 find: (state) => (uuid) => state.notes.find((note) => note.uuid === uuid),
},
} }