This commit is contained in:
Hubert Van De Walle 2020-06-25 15:41:03 +02:00
parent 071ce40ac6
commit 67915246ba
7 changed files with 60 additions and 34 deletions

View File

@ -0,0 +1,16 @@
package be.vandewalleh.validation
import am.ik.yavi.builder.ValidatorBuilder
import am.ik.yavi.builder.konstraint
import am.ik.yavi.core.Validator
import be.vandewalleh.entities.Note
import be.vandewalleh.entities.User
val noteValidator: Validator<Note> = ValidatorBuilder.of<Note>()
.konstraint(Note::title) {
notNull().notBlank().lessThanOrEqual(50)
}
.konstraint(Note::tags) {
this.lessThanOrEqual(10)
}
.build()

View File

@ -1,6 +1,11 @@
<template> <template>
<div class="tags"> <div class="tags">
<v-chip v-for="tag in tags" :key="tag" active color="secondary"> <v-chip
v-for="(tag, index) in tags"
:key="index"
active
color="secondary"
>
{{ tag }} {{ tag }}
</v-chip> </v-chip>
</div> </div>

View File

@ -72,19 +72,7 @@ export default {
** Axios module configuration ** Axios module configuration
** See https://axios.nuxtjs.org/options ** See https://axios.nuxtjs.org/options
*/ */
axios: { axios: {},
headers: {
common: {
Accept: 'application/json',
},
delete: {},
get: {},
head: {},
post: {},
put: {},
patch: {},
},
},
env: { env: {
API_HOST: env.API_HOST, API_HOST: env.API_HOST,

View File

@ -21,6 +21,8 @@
auto-grow auto-grow
></v-textarea> ></v-textarea>
<client-only v-else> <client-only v-else>
<!-- html is sanitized -->
<!-- eslint-disable-next-line -->
<div class="html" v-html="html" /> <div class="html" v-html="html" />
</client-only> </client-only>
</v-card-text> </v-card-text>
@ -51,12 +53,7 @@ export default {
}, },
}, },
mounted() { mounted() {
this.$axios this.$axios.get('/tags').then((e) => (this.possibleTags = e.data))
.get('/tags')
.then((e) => (this.possibleTags = e.data))
.catch((e) => {
console.log(e)
})
}, },
methods: { methods: {
createNote() { createNote() {
@ -71,8 +68,6 @@ export default {
.catch((e) => { .catch((e) => {
if (e.response && e.response.status === 409) { if (e.response && e.response.status === 409) {
this.conflict = true this.conflict = true
} else {
console.log('??')
} }
}) })
}, },

View File

@ -6,6 +6,8 @@
<TagsGroup :tags="note.tags" /> <TagsGroup :tags="note.tags" />
</v-card-title> </v-card-title>
<v-card-text> <v-card-text>
<!-- html is sanitized -->
<!-- eslint-disable-next-line -->
<div v-html="renderedMarkdown"></div> <div v-html="renderedMarkdown"></div>
</v-card-text> </v-card-text>
</v-card> </v-card>
@ -23,8 +25,9 @@ export default {
}), }),
computed: { computed: {
renderedMarkdown() { renderedMarkdown() {
if (!this.note.chapters) return '' return !this.note.content
return renderMarkdown(this.note.chapters[0].content).contents ? ''
: renderMarkdown(this.note.content).contents
}, },
}, },
mounted() { mounted() {

View File

@ -1,13 +1,16 @@
<template> <template>
<div> <div>
<v-progress-circular <v-progress-circular
v-if="loading && notes.length === 0" v-if="!isInitialized"
:size="100" :size="100"
:width="7" :width="7"
color="purple" color="purple"
indeterminate indeterminate
></v-progress-circular> ></v-progress-circular>
<v-row> <v-card v-if="isEmpty">
<v-card-text>No notes yet :/</v-card-text>
</v-card>
<v-row v-else>
<v-col <v-col
v-for="note in notes" v-for="note in notes"
:key="note.uuid" :key="note.uuid"
@ -28,7 +31,7 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapGetters, mapActions } from 'vuex'
export default { export default {
name: 'Notes', name: 'Notes',
@ -36,10 +39,14 @@ export default {
loading: true, loading: true,
}), }),
computed: { computed: {
...mapState('notes', { notes: (state) => state.notes }), ...mapState('notes', ['notes', 'isInitialized']),
...mapGetters('notes', ['isEmpty']),
}, },
mounted() { mounted() {
this.$store.dispatch('notes/load').then(() => (this.loading = false)) if (!this.initialized) this.load()
},
methods: {
...mapActions('notes', ['load']),
}, },
head: () => ({ head: () => ({
title: 'My notes', title: 'My notes',

View File

@ -1,8 +1,12 @@
export const state = () => ({ export const state = () => ({
notes: [], notes: [],
isInitialized: false,
}) })
export const mutations = { export const mutations = {
setInitialized(state) {
state.isInitialized = true
},
set(state, notes) { set(state, notes) {
state.notes = notes state.notes = notes
}, },
@ -15,21 +19,25 @@ export const mutations = {
// used when logging out // used when logging out
clear(state) { clear(state) {
state.notes = [] state.notes = []
state.initialized = false
}, },
} }
export const actions = { export const actions = {
async load({ commit }) { async load({ commit }) {
await new Promise((resolve) => setTimeout(resolve, 600)) await new Promise((resolve) => setTimeout(resolve, 600))
this.$axios.get('/notes').then(({ data }) => commit('set', data)) this.$axios.get('/notes').then(({ data }) => {
commit('set', data)
commit('setInitialized')
})
}, },
// FIXME: make the api send the new date back
create({ commit }, note) { create({ commit }, note) {
this.$axios.post('/notes', note).then(({ data }) => this.$axios.post('/notes', note).then(({ data }) =>
commit('add', { commit('add', {
updatedAt: new Date().toISOString(),
uuid: data.uuid, uuid: data.uuid,
...note, title: data.title,
updatedAt: data.updatedAt,
tags: data.tags,
}) })
) )
}, },
@ -40,4 +48,8 @@ export const actions = {
}, },
} }
export const getters = {} export const getters = {
isEmpty(state) {
return state.isInitialized && state.notes.length === 0
},
}