fix: misc changes

This commit is contained in:
Jannat Patel
2024-06-13 15:34:57 +05:30
parent 81feee887c
commit a99c41a07b
6 changed files with 87 additions and 34 deletions

View File

@@ -145,8 +145,9 @@
/>
</div>
<div class="mt-20">
{{ allowDiscussions }}
<Discussions
v-if="allowDiscussions()"
v-if="allowDiscussions"
:title="'Questions'"
:doctype="'Course Lesson'"
:docname="lesson.data.name"
@@ -185,7 +186,7 @@
</template>
<script setup>
import { createResource, Breadcrumbs, Button } from 'frappe-ui'
import { computed, watch, ref, inject, createApp } from 'vue'
import { computed, watch, inject, ref } from 'vue'
import CourseOutline from '@/components/CourseOutline.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import { useRoute } from 'vue-router'
@@ -198,7 +199,9 @@ import CourseInstructors from '@/components/CourseInstructors.vue'
const user = inject('$user')
const route = useRoute()
let editor, instructorEditor
const allowDiscussions = ref(false)
const editor = ref(null)
const instructorEditor = ref(null)
const props = defineProps({
courseName: {
@@ -228,13 +231,24 @@ const lesson = createResource({
auto: true,
onSuccess(data) {
markProgress(data)
if (data.content) editor = renderEditor('editor', data.content)
console.log('success')
if (data.content) editor.value = renderEditor('editor', data.content)
if (data.instructor_content?.blocks?.length)
instructorEditor = renderEditor(
instructorEditor.value = renderEditor(
'instructor-content',
data.instructor_content
)
editor.value?.isReady.then(() => {
checkIfDiscussionsAllowed()
})
console.log(editor.value)
console.log(data.body)
if (!editor.value && data.body) {
const quizRegex = /\{\{ Quiz\(".*"\) \}\}/
const hasQuiz = quizRegex.test(data.body)
console.log(hasQuiz)
if (!hasQuiz) allowDiscussions.value = true
}
},
})
@@ -292,6 +306,8 @@ watch(
[oldChapterNumber, oldLessonNumber]
) => {
if (newChapterNumber || newLessonNumber) {
editor.value = null
instructorEditor.value = null
lesson.submit({
chapter: newChapterNumber,
lesson: newLessonNumber,
@@ -300,12 +316,21 @@ watch(
}
)
const allowDiscussions = () => {
return (
lesson.data?.membership ||
user.data?.is_moderator ||
user.data?.is_instructor
const checkIfDiscussionsAllowed = () => {
let quizPresent = false
console.log(lesson.data?.content)
JSON.parse(lesson.data?.content)?.blocks?.forEach((block) => {
if (block.type === 'quiz') quizPresent = true
})
if (
!quizPresent &&
(lesson.data?.membership ||
user.data?.is_moderator ||
user.data?.is_instructor)
)
allowDiscussions.value = true
else allowDiscussions.value = false
}
const allowEdit = () => {