2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<section class="container section" v-if="todoList">
|
2022-01-10 15:19:16 +01:00
|
|
|
<breadcrumbs-nav
|
|
|
|
:links="[
|
|
|
|
{
|
|
|
|
name: RouteName.GROUP,
|
|
|
|
params: { preferredUsername: usernameWithDomain(todoList.actor) },
|
|
|
|
text: displayName(group),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: RouteName.TODO_LISTS,
|
|
|
|
params: { preferredUsername: usernameWithDomain(todoList.actor) },
|
|
|
|
text: $t('Task lists'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: RouteName.TODO_LIST,
|
|
|
|
params: { id: todoList.id },
|
|
|
|
text: todoList.title,
|
|
|
|
},
|
|
|
|
]"
|
|
|
|
/>
|
2020-02-18 08:57:00 +01:00
|
|
|
<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";
|
2022-01-10 15:19:16 +01:00
|
|
|
import { displayName, IActor, usernameWithDomain } 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";
|
2021-05-12 18:10:07 +02:00
|
|
|
import { ApolloCache, FetchResult, InMemoryCache } from "@apollo/client/core";
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@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,
|
|
|
|
},
|
2021-10-10 16:24:12 +02:00
|
|
|
metaInfo() {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
const { todoList } = this;
|
|
|
|
return {
|
|
|
|
title: todoList.title,
|
|
|
|
};
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
})
|
|
|
|
export default class TodoList extends Vue {
|
|
|
|
@Prop({ type: String, required: true }) id!: string;
|
|
|
|
|
|
|
|
todoList!: ITodoList;
|
|
|
|
|
|
|
|
currentActor!: IActor;
|
|
|
|
|
|
|
|
newTodo: ITodo = { title: "", status: false };
|
|
|
|
|
|
|
|
RouteName = RouteName;
|
|
|
|
|
2022-01-10 15:19:16 +01:00
|
|
|
displayName = displayName;
|
|
|
|
|
|
|
|
usernameWithDomain = usernameWithDomain;
|
|
|
|
|
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,
|
|
|
|
},
|
2021-05-12 18:10:07 +02:00
|
|
|
update: (store: ApolloCache<InMemoryCache>, { data }: FetchResult) => {
|
2020-02-18 08:57:00 +01:00
|
|
|
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>
|