Update bookmark in module

This commit is contained in:
Ramon Wenger 2022-01-30 00:14:45 +01:00
parent bf89fba212
commit 12f16c3971
9 changed files with 114 additions and 35 deletions

View File

@ -82,7 +82,7 @@ export default {
}),
ModuleNode: () => ({
title: 'Module Title',
slug: 'some slug',
slug: 'some-slug',
metaTitle: 'Meta Title',
heroImage: '',
teaser: '',
@ -90,6 +90,7 @@ export default {
assignments: [],
objectiveGroups: [],
id: getModuleId(),
bookmark: null
}),
TopicNode: () => ({
modules: [],

View File

@ -15,6 +15,7 @@ describe('Bookmarks', () => {
ModuleDetailsQuery: {
module: {
...minimalModule,
slug: 'my-module-slug',
chapters: [
{
title: 'My super Chapter',
@ -41,6 +42,11 @@ describe('Bookmarks', () => {
success: true
}
},
UpdateModuleBookmark: {
updateModuleBookmark: {
success: true
}
},
UpdateChapterBookmark: {
updateChapterBookmark: {
success: true
@ -65,7 +71,29 @@ describe('Bookmarks', () => {
});
it('should bookmark module', () => {
cy.visit();
cy.visit('/module/lohn-und-budget/');
cy.getByDataCy('module-bookmark-actions').as('moduleBookmark');
cy.get('@moduleBookmark').within(() => {
cy.getByDataCy('bookmark-action').click();
cy.getByDataCy('add-note-action').click();
});
cy.get('[data-cy=bookmark-note]').within(() => {
cy.get('.skillbox-input').type('Hallo Velo');
});
cy.get('[data-cy=modal-save-button]').click();
cy.get('@moduleBookmark').within(() => {
cy.getByDataCy('edit-note-action').click();
});
cy.get('[data-cy=bookmark-note]').within(() => {
cy.get('.skillbox-input').clear().type('Hello Bike');
});
cy.get('[data-cy=modal-save-button]').click();
});
it('should bookmark chapter', () => {

View File

@ -27,6 +27,7 @@
:bookmarked="module.bookmark"
:note="note"
class="module__bookmark-actions"
data-cy="module-bookmark-actions"
@add-note="$emit('addNote')"
@edit-note="$emit('editNote')"
@bookmark="$emit('bookmark', !module.bookmark)"

View File

@ -52,8 +52,7 @@
</script>
<style scoped lang="scss">
@import "@/styles/_variables.scss";
@import "@/styles/_mixins.scss";
@import "~styles/helpers";
.bookmark-actions {
height: 100%;

View File

@ -40,7 +40,6 @@
content,
block,
text,
type
};
} else {
note = {
@ -48,6 +47,9 @@
text
};
}
if(type){
note.type = type;
}
this.$apollo
.mutate(constructNoteMutation(note))

View File

@ -3,8 +3,9 @@ import CONTENT_BLOCK_QUERY from '@/graphql/gql/queries/contentBlockQuery.gql';
import CHAPTER_QUERY from '@/graphql/gql/queries/chapterQuery.gql';
import MODULE_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
import INSTRUMENT_FRAGMENT from '@/graphql/gql/fragments/instrumentParts.gql';
import gql from 'graphql-tag';
import MODULE_FRAGMENT from '@/graphql/gql/fragments/moduleParts.gql';
const getBlockType = id => atob(id).split(':')[0];
const compareUuid = note => element => element.uuid === note.content;
export const constructNoteMutation = (n) => {
@ -80,32 +81,64 @@ export const constructNoteMutation = (n) => {
};
} else { // it's a chapter bookmark or a module bookmark
update = (store, {data: {addNote: {note}}}) => {
const type = getBlockType(n.parent) === 'ChapterNode' ? 'chapter' : 'module';
const query = type === 'chapter' ? CHAPTER_QUERY : MODULE_QUERY;
const variables = {id: n.parent};
const fromStore = store.readQuery({
query,
variables
});
const type = n.type === 'module' ? 'module' : 'chapter';
const isChapter = type === 'chapter';
let query;
let variables;
let fromStore;
if(isChapter) {
variables = {id: n.parent};
query = CHAPTER_QUERY;
fromStore = store.readQuery({
query,
variables
});
const entity = fromStore[type];
console.log('fromStore', fromStore);
const entity = fromStore[type];
let bookmark = {
...entity.bookmark,
note
};
const data = {
[type]: {
...entity,
bookmark
}
};
store.writeQuery({
data,
query,
variables
});
} else {
let fragment = MODULE_FRAGMENT;
let id = store.identify({
__typename: 'ModuleNode',
slug: n.parent
});
const module = store.readFragment({
fragment,
id
});
let bookmark = {
...entity.bookmark,
...module.bookmark,
note
};
const data = {
[type]: {
...entity,
bookmark
}
let data = {
...module,
bookmark
};
store.writeQuery({
data,
query,
variables
store.writeFragment({
fragment,
id,
data
});
}
};
}

View File

@ -137,21 +137,32 @@
},
update: (store) => {
const fragment = MODULE_FRAGMENT;
const id = `ModuleNode:${slug}`;
const data = store.readFragment({
const id = store.identify({
__typename: 'ModuleNode',
slug: slug
});
const module = store.readFragment({
fragment,
id,
});
let bookmark;
if (bookmarked) {
data.bookmark = {
bookmark = {
__typename: 'ModuleBookmarkNode',
note: null,
};
} else {
data.bookmark = null;
bookmark = null;
}
const data = {
...module,
bookmark
};
store.writeFragment({
data,
fragment,
@ -170,7 +181,8 @@
addNote(id) {
this.$store.dispatch('addNote', {
content: id,
parent: this.module.id,
parent: this.module.slug,
type: 'module'
});
},
editNote() {

View File

@ -140,11 +140,13 @@ export default new Vuex.Store({
addNote({commit, dispatch}, payload) {
if (payload.block) {
commit('setCurrentNoteBlock', payload.block);
commit('setNoteType', payload.type);
commit('setCurrentContent', payload.content);
} else {
commit('setCurrentNoteParent', payload.parent);
}
if(payload.type) {
commit('setNoteType', payload.type);
}
dispatch('showModal', 'new-note-wizard');
},
editNote({commit, dispatch}, payload) {

View File

@ -87,13 +87,14 @@ class AddNote(relay.ClientIDMutation):
user=user
)
else:
type, id = from_global_id(parent)
if type == 'ModuleNode':
type = note.get('type', 'chapter')
if type == 'module':
bookmark = ModuleBookmark.objects.get(
module__id=id,
module__slug=parent,
user=user
)
else:
_, id = from_global_id(parent)
bookmark = ChapterBookmark.objects.get(
chapter__id=id,
user=user