Add bookmark action to chapter

This commit is contained in:
Ramon Wenger 2019-12-03 14:03:30 +01:00
parent 7c534cbe5c
commit a06f32bcb0
3 changed files with 53 additions and 10 deletions

View File

@ -2,8 +2,10 @@
<div class="chapter"> <div class="chapter">
<h3 :id="'chapter-' + index">{{chapter.title}}</h3> <h3 :id="'chapter-' + index">{{chapter.title}}</h3>
<h1>Bookmark: {{chapter.bookmark}} <a @click="bookmark">Click</a></h1> <bookmark-actions
:bookmarked="chapter.bookmark"
@bookmark="bookmark(!chapter.bookmark)"
></bookmark-actions>
<p class="chapter__description"> <p class="chapter__description">
{{chapter.description}} {{chapter.description}}
</p> </p>
@ -20,17 +22,20 @@
<script> <script>
import ContentBlock from '@/components/ContentBlock'; import ContentBlock from '@/components/ContentBlock';
import AddContentButton from '@/components/AddContentButton'; import AddContentButton from '@/components/AddContentButton';
import BookmarkActions from '@/components/notes/BookmarkActions';
import {mapGetters} from 'vuex'; import {mapGetters} from 'vuex';
import {isHidden} from '@/helpers/content-block'; import {isHidden} from '@/helpers/content-block';
import {meQuery} from '@/graphql/queries'; import {meQuery} from '@/graphql/queries';
import UPDATE_CHAPTER_BOOKMARK_MUTATION from '@/graphql/gql/mutations/updateChapterBookmark.gql'; import UPDATE_CHAPTER_BOOKMARK_MUTATION from '@/graphql/gql/mutations/updateChapterBookmark.gql';
import CHAPTER_QUERY from '@/graphql/gql/chapterQuery.gql';
export default { export default {
props: ['chapter', 'index'], props: ['chapter', 'index'],
components: { components: {
BookmarkActions,
ContentBlock, ContentBlock,
AddContentButton AddContentButton
}, },
@ -58,14 +63,48 @@
}, },
methods: { methods: {
bookmark() { bookmark(bookmarked) {
console.log('bookmark'); const id = this.chapter.id;
this.$apollo.mutate({ this.$apollo.mutate({
mutation: UPDATE_CHAPTER_BOOKMARK_MUTATION, mutation: UPDATE_CHAPTER_BOOKMARK_MUTATION,
variables: { variables: {
input: { input: {
chapter: this.chapter.id, chapter: id,
bookmarked: true bookmarked
}
},
update: (store, response) => {
const query = CHAPTER_QUERY;
const variables = {id};
const data = store.readQuery({
query,
variables
});
const chapter = data.chapter;
if (bookmarked) {
chapter.bookmark = {
__typename: 'ChapterBookmarkNode',
note: null
}
} else {
chapter.bookmark = null;
}
data.chapter = chapter;
store.writeQuery({
data,
query,
variables
});
},
optimisticResponse: {
__typename: 'Mutation',
updateChapterBookmark: {
__typename: 'UpdateChapterBookmarkPayload',
success: true
} }
} }
}); });
@ -82,6 +121,8 @@
@import "@/styles/_mixins.scss"; @import "@/styles/_mixins.scss";
.chapter { .chapter {
position: relative;
&__description { &__description {
@include lead-paragraph; @include lead-paragraph;

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="content-component" :class="{'content-component--bookmarked': bookmarked}"> <div class="content-component" :class="{'content-component--bookmarked': bookmarked}">
<bookmark-actions <bookmark-actions
v-if="showBookmarkActions()" v-if="showBookmarkActions"
@add-note="addNote(component.id)" @add-note="addNote(component.id)"
@edit-note="editNote" @edit-note="editNote"
@bookmark="bookmarkContent(component.id, !bookmarked)" @bookmark="bookmarkContent(component.id, !bookmarked)"
@ -72,6 +72,9 @@
note() { note() {
const bookmark = this.bookmarks && this.bookmarks.find(bookmark => bookmark.uuid === this.component.id); const bookmark = this.bookmarks && this.bookmarks.find(bookmark => bookmark.uuid === this.component.id);
return bookmark && bookmark.note; return bookmark && bookmark.note;
},
showBookmarkActions() {
return this.component.type !== 'content_list' && this.component.type !== 'basic_knowledge' && !this.editModule;
} }
}, },
@ -136,9 +139,6 @@
} }
} }
}); });
},
showBookmarkActions() {
return this.component.type !== 'content_list' && this.component.type !== 'basic_knowledge' && !this.editModule;
} }
} }
}; };

View File

@ -47,6 +47,7 @@ objective_groups_1 = [
module_1_chapter_1 = { module_1_chapter_1 = {
'title': '1.1 Lehrbeginn', 'title': '1.1 Lehrbeginn',
'description': 'Hello World',
'content_blocks': [ 'content_blocks': [
{ {
'type': 'task', 'type': 'task',
@ -186,6 +187,7 @@ module_1_chapter_1 = {
} }
module_1_chapter_2 = { module_1_chapter_2 = {
'title': '1.2 Die drei Lernorte', 'title': '1.2 Die drei Lernorte',
'description': 'Hello World',
'content_blocks': [ 'content_blocks': [
{ {
'type': 'base_society', 'type': 'base_society',