fix: course cache issue
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
<Tabs
|
<Tabs
|
||||||
v-model="tabIndex"
|
v-model="tabIndex"
|
||||||
tablistClass="overflow-x-visible flex-wrap !gap-3 md:flex-nowrap"
|
tablistClass="overflow-x-visible flex-wrap !gap-3 md:flex-nowrap"
|
||||||
:tabs="tabs"
|
:tabs="makeTabs"
|
||||||
>
|
>
|
||||||
<template #tab="{ tab, selected }">
|
<template #tab="{ tab, selected }">
|
||||||
<div>
|
<div>
|
||||||
@@ -124,61 +124,53 @@ const user = inject('$user')
|
|||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
|
|
||||||
const courses = createResource({
|
const courses = createResource({
|
||||||
debounce: 300,
|
|
||||||
makeParams(values) {
|
|
||||||
return {
|
|
||||||
search_query: searchQuery.value,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
url: 'lms.lms.utils.get_courses',
|
url: 'lms.lms.utils.get_courses',
|
||||||
|
cache: ['courses', user.data?.email],
|
||||||
auto: true,
|
auto: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const tabIndex = ref(0)
|
const tabIndex = ref(0)
|
||||||
const tabs = [
|
let tabs
|
||||||
{
|
|
||||||
label: 'Live',
|
|
||||||
courses: computed(() => courses.data?.live || []),
|
|
||||||
count: computed(() => courses.data?.live?.length),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'New',
|
|
||||||
courses: computed(() => courses.data?.new),
|
|
||||||
count: computed(() => courses.data?.new?.length),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Upcoming',
|
|
||||||
courses: computed(() => courses.data?.upcoming),
|
|
||||||
count: computed(() => courses.data?.upcoming?.length),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
if (user.data) {
|
const makeTabs = computed(() => {
|
||||||
tabs.push({
|
tabs = []
|
||||||
label: 'Enrolled',
|
addToTabs('Live', getCourses('live'))
|
||||||
courses: computed(() => courses.data?.enrolled),
|
addToTabs('New', getCourses('new'))
|
||||||
count: computed(() => courses.data?.enrolled?.length),
|
addToTabs('Upcoming', getCourses('upcoming'))
|
||||||
})
|
|
||||||
|
if (user.data) {
|
||||||
|
addToTabs('Enrolled', getCourses('enrolled'))
|
||||||
|
|
||||||
if (
|
if (
|
||||||
user.data.is_moderator ||
|
user.data.is_moderator ||
|
||||||
user.data.is_instructor ||
|
user.data.is_instructor ||
|
||||||
courses.data?.created?.length
|
courses.data?.created?.length
|
||||||
) {
|
) {
|
||||||
tabs.push({
|
addToTabs('Created', getCourses('created'))
|
||||||
label: 'Created',
|
|
||||||
courses: computed(() => courses.data?.created),
|
|
||||||
count: computed(() => courses.data?.created?.length),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.data.is_moderator) {
|
if (user.data.is_moderator) {
|
||||||
tabs.push({
|
addToTabs('Under Review', getCourses('under_review'))
|
||||||
label: 'Under Review',
|
|
||||||
courses: computed(() => courses.data?.under_review),
|
|
||||||
count: computed(() => courses.data?.under_review?.length),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return tabs
|
||||||
|
})
|
||||||
|
|
||||||
|
const addToTabs = (label, courses) => {
|
||||||
|
tabs.push({
|
||||||
|
label,
|
||||||
|
courses: computed(() => courses),
|
||||||
|
count: computed(() => courses.length),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCourses = (type) => {
|
||||||
|
if (searchQuery.value) {
|
||||||
|
return courses.data[type].filter((course) =>
|
||||||
|
course.title.toLowerCase().includes(searchQuery.value.toLowerCase())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return courses.data[type]
|
||||||
}
|
}
|
||||||
|
|
||||||
const pageMeta = computed(() => {
|
const pageMeta = computed(() => {
|
||||||
|
|||||||
@@ -1251,12 +1251,10 @@ def change_currency(amount, currency, country=None):
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_courses(search_query=""):
|
def get_courses():
|
||||||
"""Returns the list of courses."""
|
"""Returns the list of courses."""
|
||||||
courses = []
|
courses = []
|
||||||
course_list = frappe.get_all(
|
course_list = frappe.get_all("LMS Course", pluck="name")
|
||||||
"LMS Course", {"title": ["like", f"%{search_query}%"]}, pluck="name"
|
|
||||||
)
|
|
||||||
for course in course_list:
|
for course in course_list:
|
||||||
courses.append(get_course_details(course))
|
courses.append(get_course_details(course))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user