feat: description script setup (#1927)
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/1927 Reviewed-by: konrad <k@knt.li> Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
parent
b4aa65018c
commit
c7f8ae256b
1 changed files with 51 additions and 54 deletions
|
@ -29,65 +29,62 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import {defineComponent} from 'vue'
|
import {ref,computed, watch} from 'vue'
|
||||||
|
import {useStore} from 'vuex'
|
||||||
|
|
||||||
import AsyncEditor from '@/components/input/AsyncEditor'
|
import Editor from '@/components/input/AsyncEditor'
|
||||||
|
|
||||||
import {LOADING} from '@/store/mutation-types'
|
import TaskModel from '@/models/task'
|
||||||
import {mapState} from 'vuex'
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'description',
|
|
||||||
components: {
|
|
||||||
Editor: AsyncEditor,
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
task: {description: ''},
|
|
||||||
saved: false,
|
|
||||||
saving: false, // Since loading is global state, this variable ensures we're only showing the saving icon when saving the description.
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: mapState({
|
|
||||||
loading: LOADING,
|
|
||||||
}),
|
|
||||||
props: {
|
|
||||||
modelValue: {
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
attachmentUpload: {
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
canWrite: {
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
emits: ['update:modelValue'],
|
|
||||||
watch: {
|
|
||||||
modelValue: {
|
|
||||||
handler(value) {
|
|
||||||
this.task = value
|
|
||||||
},
|
|
||||||
immediate: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async save() {
|
|
||||||
this.saving = true
|
|
||||||
|
|
||||||
try {
|
const props = defineProps({
|
||||||
this.task = await this.$store.dispatch('tasks/update', this.task)
|
modelValue: {
|
||||||
this.$emit('update:modelValue', this.task)
|
type: TaskModel,
|
||||||
this.saved = true
|
required: true,
|
||||||
setTimeout(() => {
|
},
|
||||||
this.saved = false
|
attachmentUpload: {
|
||||||
}, 2000)
|
required: true,
|
||||||
} finally {
|
},
|
||||||
this.saving = false
|
canWrite: {
|
||||||
}
|
required: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
|
const task = ref<TaskModel>({description: ''})
|
||||||
|
const saved = ref(false)
|
||||||
|
|
||||||
|
// Since loading is global state, this variable ensures we're only showing the saving icon when saving the description.
|
||||||
|
const saving = ref(false)
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
const loading = computed(() => store.state.loading)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(value) => {
|
||||||
|
task.value = value
|
||||||
|
},
|
||||||
|
{immediate: true},
|
||||||
|
)
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
saving.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
// FIXME: don't update state from internal.
|
||||||
|
task.value = await store.dispatch('tasks/update', task.value)
|
||||||
|
emit('update:modelValue', task.value)
|
||||||
|
|
||||||
|
saved.value = true
|
||||||
|
setTimeout(() => {
|
||||||
|
saved.value = false
|
||||||
|
}, 2000)
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue