Refactor some code
This commit is contained in:
parent
6f1b0dfefd
commit
2953ea4c8e
|
|
@ -168,7 +168,11 @@ const { mutate: duplicateContentBlock } = useMutation(DUPLICATE_CONTENT_BLOCK_MU
|
||||||
const variables = {
|
const variables = {
|
||||||
id,
|
id,
|
||||||
};
|
};
|
||||||
const { chapter }: any = store.readQuery({ query, variables });
|
|
||||||
|
const { chapter }: any = store.readQuery({
|
||||||
|
query,
|
||||||
|
variables,
|
||||||
|
});
|
||||||
const index = chapter.contentBlocks.findIndex(
|
const index = chapter.contentBlocks.findIndex(
|
||||||
(contentBlock: ExtendedContentBlockNode) => contentBlock.id === contentBlockId
|
(contentBlock: ExtendedContentBlockNode) => contentBlock.id === contentBlockId
|
||||||
);
|
);
|
||||||
|
|
@ -179,7 +183,12 @@ const { mutate: duplicateContentBlock } = useMutation(DUPLICATE_CONTENT_BLOCK_MU
|
||||||
contentBlocks,
|
contentBlocks,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
store.writeQuery({ query, variables, data });
|
|
||||||
|
store.writeQuery({
|
||||||
|
query,
|
||||||
|
variables,
|
||||||
|
data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
@ -200,35 +209,53 @@ const { mutate: doDeleteContentBlock } = useMutation(DELETE_CONTENT_BLOCK_MUTATI
|
||||||
) => {
|
) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
const query = CHAPTER_QUERY;
|
const query = CHAPTER_QUERY;
|
||||||
|
|
||||||
const variables = {
|
const variables = {
|
||||||
id: props.parent.id,
|
id: props.parent.id,
|
||||||
};
|
};
|
||||||
const { chapter }: any = store.readQuery({ query, variables });
|
|
||||||
|
const { chapter }: any = store.readQuery({
|
||||||
|
query,
|
||||||
|
variables,
|
||||||
|
});
|
||||||
const index = chapter.contentBlocks.findIndex(
|
const index = chapter.contentBlocks.findIndex(
|
||||||
(contentBlock: ExtendedContentBlockNode) => contentBlock.id === props.contentBlock.id
|
(contentBlock: ExtendedContentBlockNode) => contentBlock.id === props.contentBlock.id
|
||||||
);
|
);
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
throw Error('ContentBlock not found');
|
throw Error('ContentBlock not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentBlocks = removeAtIndex(chapter.contentBlocks, index);
|
const contentBlocks = removeAtIndex(chapter.contentBlocks, index);
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
chapter: {
|
chapter: {
|
||||||
...chapter,
|
...chapter,
|
||||||
contentBlocks,
|
contentBlocks,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
store.writeQuery({ query, variables, data });
|
|
||||||
|
store.writeQuery({
|
||||||
|
query,
|
||||||
|
variables,
|
||||||
|
data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const element = wrapper.value;
|
const element = wrapper.value;
|
||||||
|
|
||||||
if (element !== null) {
|
if (element !== null) {
|
||||||
if (route.hash === `#${props.contentBlock.id}`) {
|
if (route.hash === `#${props.contentBlock.id}`) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
window.scrollTo({ top: rect.y, behavior: 'smooth' });
|
|
||||||
|
window.scrollTo({
|
||||||
|
top: rect.y,
|
||||||
|
behavior: 'smooth',
|
||||||
|
});
|
||||||
}, PAGE_LOAD_TIMEOUT);
|
}, PAGE_LOAD_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,15 +304,10 @@ const deleteContentBlock = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// computed properties
|
// computed properties
|
||||||
const canEditModule = computed(() => {
|
const canEditModule = computed(() => !props.contentBlock.indent && props.editMode);
|
||||||
return !props.contentBlock.indent && props.editMode;
|
const specialClass = computed(() => `content-block--${props.contentBlock.type.toLowerCase()}`);
|
||||||
});
|
const isInstrumentBlock = computed(() => !!props.contentBlock.instrumentCategory);
|
||||||
const specialClass = computed(() => {
|
|
||||||
return `content-block--${props.contentBlock.type.toLowerCase()}`;
|
|
||||||
});
|
|
||||||
const isInstrumentBlock = computed(() => {
|
|
||||||
return !!props.contentBlock.instrumentCategory;
|
|
||||||
});
|
|
||||||
// todo: use dynamic css class with v-bind once we're on Vue 3: https://vuejs.org/api/sfc-css-features.html#v-bind-in-css
|
// todo: use dynamic css class with v-bind once we're on Vue 3: https://vuejs.org/api/sfc-css-features.html#v-bind-in-css
|
||||||
const instrumentStyle = computed(() => {
|
const instrumentStyle = computed(() => {
|
||||||
if (isInstrumentBlock.value) {
|
if (isInstrumentBlock.value) {
|
||||||
|
|
@ -313,11 +335,12 @@ const instrumentLabelStyle = computed(() => {
|
||||||
color: props.contentBlock.instrumentCategory.foreground,
|
color: props.contentBlock.instrumentCategory.foreground,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
const isMine = computed(() => {
|
|
||||||
return props.contentBlock.mine;
|
const isMine = computed(() => props.contentBlock.mine);
|
||||||
});
|
|
||||||
const contentBlocksWithContentLists = computed(() => {
|
const contentBlocksWithContentLists = computed(() => {
|
||||||
/*
|
/*
|
||||||
collects all content_list_items in content_lists:
|
collects all content_list_items in content_lists:
|
||||||
|
|
@ -359,19 +382,18 @@ const contentBlocksWithContentLists = computed(() => {
|
||||||
contents: newContent,
|
contents: newContent,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const isHidden = computed(() => {
|
|
||||||
return hidden({
|
const isHidden = computed(() =>
|
||||||
|
hidden({
|
||||||
block: props.contentBlock,
|
block: props.contentBlock,
|
||||||
schoolClass: schoolClass.value,
|
schoolClass: schoolClass.value,
|
||||||
type: CONTENT_TYPE,
|
type: CONTENT_TYPE,
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
const root = computed(() => {
|
|
||||||
// we need the root content block id, not the generated content block if inside a content list block
|
|
||||||
return props.contentBlock.root ? props.contentBlock.root : props.contentBlock.id;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
// we need the root content block id, not the generated content block if inside a content list block
|
||||||
|
const root = computed(() => (props.contentBlock.root ? props.contentBlock.root : props.contentBlock.id));
|
||||||
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
/* todo: re-add `scoped` after switch to vite or this bug is fixed: https://github.com/vuejs/vue-loader/issues/1915 */
|
/* todo: re-add `scoped` after switch to vite or this bug is fixed: https://github.com/vuejs/vue-loader/issues/1915 */
|
||||||
@import 'styles/helpers';
|
@import 'styles/helpers';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue