2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<section class="container section" v-if="todoList">
|
|
|
|
<nav class="breadcrumb" aria-label="breadcrumbs">
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<router-link
|
|
|
|
:to="{
|
|
|
|
name: RouteName.GROUP,
|
|
|
|
params: { preferredUsername: todoList.actor.preferredUsername },
|
|
|
|
}"
|
2020-09-29 09:53:48 +02:00
|
|
|
>{{ todoList.actor.name }}</router-link
|
2020-02-18 08:57:00 +01:00
|
|
|
>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<router-link
|
|
|
|
:to="{
|
|
|
|
name: RouteName.TODO_LISTS,
|
|
|
|
params: { preferredUsername: todoList.actor.preferredUsername },
|
|
|
|
}"
|
|
|
|
>{{ $t("Task lists") }}</router-link
|
|
|
|
>
|
|
|
|
</li>
|
|
|
|
<li class="is-active">
|
2020-11-30 10:24:11 +01:00
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.TODO_LIST, params: { id: todoList.id } }"
|
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
{{ todoList.title }}
|
|
|
|
</router-link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
<h2 class="title">{{ todoList.title }}</h2>
|
|
|
|
<div v-for="todo in todoList.todos.elements" :key="todo.id">
|
|
|
|
<compact-todo :todo="todo" />
|
|
|
|
</div>
|
|
|
|
<form class="form box" @submit.prevent="createNewTodo">
|
|
|
|
<b-field>
|
|
|
|
<b-checkbox v-model="newTodo.status" />
|
|
|
|
<b-input expanded v-model="newTodo.title" />
|
|
|
|
</b-field>
|
|
|
|
<b-button native-type="submit">{{ $t("Add a todo") }}</b-button>
|
|
|
|
</form>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ITodo } from "@/types/todos";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { CREATE_TODO, FETCH_TODO_LIST } from "@/graphql/todos";
|
|
|
|
import CompactTodo from "@/components/Todo/CompactTodo.vue";
|
|
|
|
import { CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
|
|
|
import { IActor } from "@/types/actor";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ITodoList } from "@/types/todolist";
|
2020-02-18 08:57:00 +01:00
|
|
|
import RouteName from "../../router/name";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
CompactTodo,
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
todoList: {
|
|
|
|
query: FETCH_TODO_LIST,
|
2020-08-27 11:53:24 +02:00
|
|
|
fetchPolicy: "cache-and-network",
|
2020-02-18 08:57:00 +01:00
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
id: this.$route.params.id,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class TodoList extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) id!: string;
|
|
|
|
|
|
|
|
todoList!: ITodoList;
|
|
|
|
|
|
|
|
currentActor!: IActor;
|
|
|
|
|
|
|
|
newTodo: ITodo = { title: "", status: false };
|
|
|
|
|
|
|
|
RouteName = RouteName;
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
async createNewTodo(): Promise<void> {
|
2020-02-18 08:57:00 +01:00
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: CREATE_TODO,
|
|
|
|
variables: {
|
|
|
|
title: this.newTodo.title,
|
|
|
|
status: this.newTodo.status,
|
|
|
|
todoListId: this.id,
|
|
|
|
},
|
|
|
|
update: (store, { data }) => {
|
|
|
|
if (data == null) return;
|
|
|
|
const cachedData = store.readQuery<{ todoList: ITodoList }>({
|
|
|
|
query: FETCH_TODO_LIST,
|
|
|
|
variables: { id: this.todoList.id },
|
|
|
|
});
|
|
|
|
if (cachedData == null) return;
|
|
|
|
const { todoList } = cachedData;
|
|
|
|
if (todoList === null) {
|
2020-11-30 10:24:11 +01:00
|
|
|
console.error(
|
|
|
|
"Cannot update event notes cache, because of null value."
|
|
|
|
);
|
2020-02-18 08:57:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const newTodo: ITodo = data.createTodo;
|
|
|
|
newTodo.creator = this.currentActor;
|
|
|
|
|
|
|
|
todoList.todos.elements = todoList.todos.elements.concat([newTodo]);
|
|
|
|
|
|
|
|
store.writeQuery({
|
|
|
|
query: FETCH_TODO_LIST,
|
|
|
|
variables: { id: this.todoList.id },
|
|
|
|
data: { todoList },
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.newTodo = { title: "", status: false };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|