23
loading...
This website collects cookies to deliver better user experience
export enum TaskStatus {
InProgress = "In Progress",
Completed = "Completed",
Deleted = "Deleted",
Rescheduled = "Rescheduled",
}
export default interface Task {
id?: string;
title: string;
status: TaskStatus;
dueDate: string;
rescheduledFrom: string;
rescheduledTo: string;
}
rescheduledFrom
and rescheduledFrom
which will be utilized when a task is, you guessed it, rescheduled. I am also using an enum to make sure all of the tasks will have consistent status
values.export const store = createStore<State>({
state: {
goalList: [
{
id: "fdde9397-337c-4a75-9641-968c37374a32",
title: "Hello world",
dueDate: "31/12/2021",
},
],
weeklyTasks: [
{
goalId: "fdde9397-337c-4a75-9641-968c37374a32",
tasks: [
{
id: "fdde9397-667c-4a75-9641-9685jg373ff3",
title: "In progress weekly Task 1",
status: TaskStatus.InProgress,
dueDate: moment().format("DD/MM/YYYY").toString(),
rescheduledFrom: "",
rescheduledTo: "",
},
],
},
],
},
});
weeklyTask
array and then retrieve it. This might cause duplication of code, but more importantly, there is no guarantee that the data will be consistent.computed: {
doneTodosCount () {
return this.$store.state.todos.filter(todo => todo.done).length
}
}
state
as a 1st argument and getters
as a 2nd argument. Based on the requirements, I would like to filter a weeklyTask
array based on the goalId
. In order to do so, a Method-Style Access must be used, which means passing arguments to getters by returning a functionexport const store = createStore<State>({
// ..state
getters: {
getWeeklyTasksByGoalId(state: State) {
return (goalId: string) =>
state.weeklyTasks.filter((week) => week.goalId == goalId)[0];
},
},
// ... mutations
});
goalId
so I can safely return data from the first index of a filtered array.<script lang="ts">
// imports
export default defineComponent({
setup() {
const route = useRoute();
const store = useStore();
const isPast = ref(false);
const goalWeeklyTasks = computed(() => store.getters.getWeeklyTasksByGoalId(
route.params.goalId
));
const weeklyTasksByDueDate = computed(() =>
goalWeeklyTasks.tasks.filter(
(task: Task) =>
task.dueDate === moment().format("DD/MM/YYYY").toString()
)
);
return {
weeklyTasksByDueDate,
isPast,
};
},
});
</script>
AppTaskListItem.vue
component, where it will recieve a task object as a prop.<template>
<li class="p-10 border border-gray-200 rounded-md text-left">
<div
v-if="state === 'active' || state === 'underReview'"
class="flex items-center justify-end mb-5"
>
<!-- rest of the component -->
<p class="text-lg font-light">
{{ task.title }}
</p>
</div>
</li>
</template>
<script lang="ts">
import Task from "@/types/Task.interface";
import { defineComponent, PropType } from "vue";
export default defineComponent({
props: {
task: {
type: Object as PropType<Task>,
required: true,
},
},
});
</script>
WeeklyPlan.vue
template and pass a task data via newly added props.<template>
<BaseLayout>
<!-- rest of the component -->
<ul class="mt-5 space-y-8">
<AppTaskListItem
v-for="task in weeklyTasksByDueDate"
:key="task.id"
:task="task"
/>
</ul>
<!-- rest of the component -->
</BaseLayout>
</template>