Skip to content

Commit

Permalink
Move code to composable - refs BT#22255
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Dec 27, 2024
1 parent 8bed158 commit 00dc554
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
22 changes: 22 additions & 0 deletions assets/vue/composables/language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export function useLanguage() {
const defaultLanguage = { originalName: "English", isocode: "en" }

/**
* @type {{originalName: string, isocode: string}[]}
*/
const languageList = window.languages || [defaultLanguage]

/**
* @param {string} isoCode
* @returns {{originalName: string, isocode: string}|undefined}
*/
function findByIsoCode(isoCode) {
return languageList.find((language) => isoCode === language.isocode)
}

return {
defaultLanguage,
languageList,
findByIsoCode,
}
}
14 changes: 3 additions & 11 deletions assets/vue/views/course/CatalogueCourses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ import courseService from "../../services/courseService"
import * as trackCourseRanking from "../../services/trackCourseRankingService"
import { useNotification } from "../../composables/notification"
import { useLanguage } from "../../composables/language"
const { showErrorNotification } = useNotification()
const { findByIsoCode: findLanguageByIsoCode } = useLanguage()
const securityStore = useSecurityStore()
const status = ref(false)
Expand All @@ -227,7 +229,7 @@ async function load() {
courses.value = items.map((course) => ({
...course,
courseLanguage: getOriginalLanguageName(course.courseLanguage),
courseLanguage: findLanguageByIsoCode(course.courseLanguage)?.originalName,
}))
} catch (error) {
showErrorNotification(error)
Expand Down Expand Up @@ -294,16 +296,6 @@ const initFilters = function () {
}
}
const getOriginalLanguageName = function (courseLanguage) {
const languages = window.languages
let language = languages.find((element) => element.isocode === courseLanguage)
if (language) {
return language.originalName
} else {
return ""
}
}
const onRatingChange = function (event, trackCourseRanking, courseId) {
let { value } = event
if (value > 0) {
Expand Down

0 comments on commit 00dc554

Please sign in to comment.