|
| 1 | +<template> |
| 2 | + <form @submit.prevent="addTodo"> |
| 3 | + Name:<br/> |
| 4 | + <input class="todo-input" id="name" type="text" placeholder="Enter task name" v-model="task" required/><br/> |
| 5 | + Due date:<br/> |
| 6 | + <input class="todo-input" id="dueDate" type="date" placeholder="Enter due date" v-model="dueDate" required/><br/> |
| 7 | + Priority:<br/> |
| 8 | + <select class="todo-input" id="priority" v-model="priority" required> |
| 9 | + <option value="1">Low</option><option value="2">Medium</option><option value="3">High</option></select><br/> |
| 10 | + Difficulty:<br/> |
| 11 | + <select class="todo-input" id="difficulty" v-model="difficulty" required> |
| 12 | + <option value="1">Easy</option><option value="2">Medium</option><option value="3">Hard</option></select><br/> |
| 13 | + Repeat often:<br/> |
| 14 | + <input class="todo-input" id="repeat-often" type="number" placeholder="Enter number of days/weeks/months/years to repeat" v-model="repeatOften" required min="1"/><br/> |
| 15 | + Repeat frequency:<br/> |
| 16 | + <select class="todo-input" id="repeat-frequency" v-model="repeatFrequency" required> |
| 17 | + <option value="1">Daily</option><option value="2">Weekly</option><option value="3">Monthly</option><option value="4">Yearly</option><option value="5">Once</option></select><br/> |
| 18 | + <button type="submit">Add Todo</button> |
| 19 | + </form> |
| 20 | +</template> |
| 21 | + |
| 22 | +<script lang="ts"> |
| 23 | +import store from '@/store'; |
| 24 | +import { difficulty, priority, repeatFrequency } from './TodoList.vue'; |
| 25 | +import { defineComponent } from 'vue'; |
| 26 | +
|
| 27 | +export interface todoTask { |
| 28 | + task: string; |
| 29 | + dueDate: Date; |
| 30 | + priority: number; |
| 31 | + difficulty: number; |
| 32 | + repeatOften: number; |
| 33 | + repeatFrequency: number; |
| 34 | + newId: number; |
| 35 | + completed: boolean; |
| 36 | +} |
| 37 | +const currentUtcDate: Date = new Date(); |
| 38 | +const currentLocalDate: Date = new Date(currentUtcDate.setMinutes(currentUtcDate.getMinutes() - currentUtcDate.getTimezoneOffset())); |
| 39 | +
|
| 40 | +export default defineComponent ({ |
| 41 | + data() { |
| 42 | + return { |
| 43 | + task: "", |
| 44 | + dueDate: currentLocalDate.toISOString().split('T')[0], |
| 45 | + priority: priority.Low, |
| 46 | + difficulty: difficulty.Easy, |
| 47 | + repeatOften: 1, |
| 48 | + repeatFrequency: repeatFrequency.Once, |
| 49 | + newId: 0, |
| 50 | + completed: false |
| 51 | + }; |
| 52 | + }, |
| 53 | + mounted() { |
| 54 | + const dueDateInput = document.getElementById('dueDate') as HTMLInputElement; |
| 55 | + dueDateInput.min = currentLocalDate.toISOString().split('T')[0]; |
| 56 | + }, |
| 57 | + methods: { |
| 58 | + addTodo: function(): void | todoTask[] { |
| 59 | + store.dispatch("createTodo", this); |
| 60 | + this.newId++; |
| 61 | + this.task = ""; |
| 62 | + this.dueDate = currentLocalDate.toISOString().split('T')[0]; |
| 63 | + this.priority = priority.Low; |
| 64 | + this.difficulty = difficulty.Easy; |
| 65 | + this.repeatOften = 1; |
| 66 | + this.repeatFrequency = repeatFrequency.Once; |
| 67 | + this.completed = false; |
| 68 | + } |
| 69 | + } |
| 70 | +}); |
| 71 | +</script> |
| 72 | + |
| 73 | +<style lang="scss"> |
| 74 | +
|
| 75 | +</style> |
0 commit comments