Make note read-only after saving

Resolves MS-880 #Complete
This commit is contained in:
Ramon Wenger 2024-02-13 16:04:58 +01:00
parent 4c42a152fb
commit f0018e2e56
5 changed files with 76 additions and 2 deletions

View File

@ -201,4 +201,28 @@ describe('Highlights', () => {
markText(); markText();
}); });
it('visits a module and highlights some text, then adds a note', () => {
cy.mockGraphqlOps({
operations: {
...operations,
ModuleDetailsQuery: {
module: getModule(defaultContents),
},
},
});
cy.visit('/module/my-module');
markText();
cy.getByDataCy('highlight-note').click();
cy.wait('@AddHighlight');
const note = 'Some noteworthy stuff';
cy.getByDataCy('highlight-note-input').should('have.value', '').type(note);
cy.getByDataCy('highlight-note-save').click();
cy.wait('@UpdateHighlight');
cy.getByDataCy('highlight-note-save').should('not.exist');
cy.getByDataCy('highlight-note-text').should('have.text', note);
});
}); });

View File

@ -118,4 +118,7 @@ export default {
id: getInstrumentId(), id: getInstrumentId(),
bookmarks: null, bookmarks: null,
}), }),
HighlightNode: () => ({
note: null,
}),
}; };

View File

@ -22,19 +22,39 @@
</div> </div>
<div class="highlight-sidebar__section highlight-sidebar__note"> <div class="highlight-sidebar__section highlight-sidebar__note">
<h2 class="heading-4">Meine Notiz</h2> <h2 class="heading-4">Meine Notiz</h2>
<div class="form-with-border highlight-sidebar__note-form"> <div
class="form-with-border highlight-sidebar__note-form"
v-if="inEditMode"
>
<textarea <textarea
class="borderless-textarea" class="borderless-textarea"
placeholder="Notiz erfassen..." placeholder="Notiz erfassen..."
data-cy="highlight-note-input"
v-model="note" v-model="note"
v-auto-grow v-auto-grow
></textarea> ></textarea>
<a <a
class="button button--primary" class="button button--primary"
@click="$emit('update-text', note)" data-cy="highlight-note-save"
@click.stop="save"
>Speichern</a >Speichern</a
> >
</div> </div>
<div v-else>
<!-- .stop to prevent the click handler to close the sidebar (as the element won't be a child of the
sidebar anymore once the event handler checks) -->
<p
data-cy="highlight-note-text"
class="highlight-sidebar__note"
>
{{ note }}
</p>
<a
class="inline-title highlight-sidebar__edit-note"
@click.stop="enableEditMode"
>Notiz bearbeiten</a
>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -58,10 +78,22 @@ const props = defineProps<Props>();
const highlightMark = ref<HTMLElement | null>(null); const highlightMark = ref<HTMLElement | null>(null);
const Cross = defineAsyncComponent(() => import('@/components/icons/CrossIcon.vue')); const Cross = defineAsyncComponent(() => import('@/components/icons/CrossIcon.vue'));
const inEditMode = ref(false);
onMounted(() => { onMounted(() => {
note.value = props.highlight.note?.text || ''; note.value = props.highlight.note?.text || '';
// enable edit mode if note does not yet exist from a previous save
inEditMode.value = note.value == '';
}); });
const enableEditMode = () => {
inEditMode.value = true;
};
const save = () => {
emits('update-text', note.value);
inEditMode.value = false;
};
</script> </script>
<style scoped lang="postcss"> <style scoped lang="postcss">
@ -122,5 +154,14 @@ onMounted(() => {
&__note-form { &__note-form {
min-height: 100px; min-height: 100px;
} }
&__note {
white-space: pre-line; /* display newlines as linebreaks */
margin-bottom: var(--medium-spacing);
}
&__edit-note {
cursor: pointer;
}
} }
</style> </style>

View File

@ -42,3 +42,8 @@
font-weight: var(--regular-font-weight); font-weight: var(--regular-font-weight);
line-height: var(--paragraph-line-height); line-height: var(--paragraph-line-height);
} }
.inline-title {
@reuse .regular-text;
color: var(--color-silver-dark);
}

View File

@ -13,6 +13,7 @@
--color-white: #ffffff; --color-white: #ffffff;
--color-silver: #d0d0d0; --color-silver: #d0d0d0;
--color-silver-dark: #aaaaaa;
--color-charcoal-dark: #333333; --color-charcoal-dark: #333333;
--sans-serif-font-family: 'Montserrat', Arial, sans-serif; --sans-serif-font-family: 'Montserrat', Arial, sans-serif;