Add validation for list ID and disable if not valid.

Add component to Home with undefined list id.
This commit is contained in:
Sytone 2021-06-02 12:23:48 -07:00
parent 9f9c942c73
commit 52b0a4c6ac
2 changed files with 15 additions and 15 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="field is-grouped"> <div class="field is-grouped" v-if="validListIdAvailable">
<p <p
:class="{ 'is-loading': taskService.loading }" :class="{ 'is-loading': taskService.loading }"
class="control has-icons-left is-expanded" class="control has-icons-left is-expanded"
@ -52,6 +52,8 @@ export default {
taskService: TaskService, taskService: TaskService,
labelService: LabelService, labelService: LabelService,
labelTaskService: LabelTaskService, labelTaskService: LabelTaskService,
listIdForNewTask: undefined,
validListIdAvailable: false,
}; };
}, },
components: {}, components: {},
@ -67,6 +69,13 @@ export default {
this.labelService = new LabelService(); this.labelService = new LabelService();
this.labelTaskService = new LabelTaskService(); this.labelTaskService = new LabelTaskService();
}, },
beforeMount() {
console.log(this.listId);
if (this.listId !== undefined) {
this.listIdForNewTask = this.listId;
this.validListIdAvailable = true;
}
},
methods: { methods: {
addTask() { addTask() {
if (this.newTaskText === '') { if (this.newTaskText === '') {
@ -77,13 +86,9 @@ export default {
const task = new TaskModel({ const task = new TaskModel({
title: this.newTaskText, title: this.newTaskText,
listId: this.listId, listId: this.listIdForNewTask,
}); });
if (this.listId === undefined) {
// TODO: Have a default list in settings as a option, waiting on API PR.
task.listId = 1;
}
this.taskService this.taskService
.create(task) .create(task)
.then(task => { .then(task => {
@ -190,10 +195,6 @@ export default {
Promise.all(labelAddsToWaitFor).then(() => { Promise.all(labelAddsToWaitFor).then(() => {
this.taskService this.taskService
.update(task) .update(task)
// .then(updatedTask => {
// this.updateTasks(updatedTask);
// this.$store.commit(HAS_TASKS, true);
// })
.then(() => { .then(() => {
this.$store.commit(HAS_TASKS, true); this.$store.commit(HAS_TASKS, true);
}) })

View File

@ -3,8 +3,9 @@
<h2> <h2>
Hi {{ userInfo.name !== '' ? userInfo.name : userInfo.username }}! Hi {{ userInfo.name !== '' ? userInfo.name : userInfo.username }}!
</h2> </h2>
<div>{{ defaultListId }}</div>
<add-task <add-task
:list="defaultList" :listId="defaultListId"
@taskAdded="updateTaskList" @taskAdded="updateTaskList"
class="is-max-width-desktop" class="is-max-width-desktop"
/> />
@ -37,7 +38,6 @@
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import ShowTasks from './tasks/ShowTasks'; import ShowTasks from './tasks/ShowTasks';
import AddTask from '../components/tasks/add-task'; import AddTask from '../components/tasks/add-task';
import ListModel from '../models/list';
export default { export default {
name: 'Home', name: 'Home',
@ -50,13 +50,12 @@ export default {
loading: false, loading: false,
currentDate: new Date(), currentDate: new Date(),
tasks: [], tasks: [],
defaultList: ListModel, defaultListId: undefined,
showTasksKey: 0, showTasksKey: 0,
}; };
}, },
created() { created() {
this.defaultList = new ListModel(); //TODO: Load the value from user settings. Until then it will not render the add task component.
this.defaultList.id = 1;
}, },
computed: mapState({ computed: mapState({
migratorsEnabled: state => migratorsEnabled: state =>