diff --git a/kolibri/plugins/learn/assets/src/composables/useLanguages.js b/kolibri/plugins/learn/assets/src/composables/useLanguages.js deleted file mode 100644 index 2f05fff81c9..00000000000 --- a/kolibri/plugins/learn/assets/src/composables/useLanguages.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * A composable function containing logic related to languages - */ - -import sortBy from 'lodash/sortBy'; -import { computed, ref } from 'kolibri.lib.vueCompositionApi'; -import { get } from '@vueuse/core'; -import plugin_data from 'plugin_data'; - -const langArray = plugin_data.languages ? plugin_data.languages : []; -const langMap = {}; - -export function setLanguages(langs) { - for (const lang of langs) { - langMap[lang.id] = lang; - } -} - -setLanguages(langArray); - -// The refs are defined in the outer scope so they can be used as a shared store -const languagesMap = ref(langMap); - -export default function useLanguages() { - const languages = computed(() => sortBy(Object.values(get(languagesMap)), 'id')); - return { - languages, - languagesMap, - }; -} diff --git a/kolibri/plugins/learn/assets/src/views/SearchChips.vue b/packages/kolibri-common/components/SearchChips.vue similarity index 86% rename from kolibri/plugins/learn/assets/src/views/SearchChips.vue rename to packages/kolibri-common/components/SearchChips.vue index d2b2e7c780f..b49326eddde 100644 --- a/kolibri/plugins/learn/assets/src/views/SearchChips.vue +++ b/packages/kolibri-common/components/SearchChips.vue @@ -33,16 +33,23 @@ import flatMap from 'lodash/flatMap'; import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings'; import { NoCategories } from 'kolibri.coreVue.vuex.constants'; - import useChannels from '../composables/useChannels'; - import useLanguages from '../composables/useLanguages'; + import useChannels from 'kolibri-common/composables/useChannels'; + import { injectBaseSearch } from 'kolibri-common/composables/useBaseSearch'; export default { name: 'SearchChips', mixins: [commonCoreStrings], setup() { - const { languagesMap } = useLanguages(); + const { availableLanguages } = injectBaseSearch(); + const languagesMap = availableLanguages.value.reduce((map, lang) => { + map[lang.id] = map; + return map; + }, {}); const { channelsMap } = useChannels(); - return { channelsMap, languagesMap }; + return { + channelsMap, + languagesMap, + }; }, props: { searchTerms: { diff --git a/packages/kolibri-common/composables/useBaseSearch.js b/packages/kolibri-common/composables/useBaseSearch.js index 5b7e17f1ad2..76e75ddd193 100644 --- a/packages/kolibri-common/composables/useBaseSearch.js +++ b/packages/kolibri-common/composables/useBaseSearch.js @@ -23,7 +23,6 @@ import { import useUser from 'kolibri.coreVue.composables.useUser'; import { deduplicateResources } from '../utils/contentNode'; -import { setLanguages } from './useLanguages'; export const logging = logger.getLogger(__filename); @@ -384,7 +383,6 @@ export default function useBaseSearch({ languagesList: labels.languages || [], channelsList: labels.channels || [], }); - setLanguages(labels.languages || []); }) .catch(err => logging.error('Failed to fetch search labels from remote', err)) .then(() => { diff --git a/packages/kolibri-common/composables/useLanguages.js b/packages/kolibri-common/composables/useLanguages.js deleted file mode 100644 index 2f05fff81c9..00000000000 --- a/packages/kolibri-common/composables/useLanguages.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * A composable function containing logic related to languages - */ - -import sortBy from 'lodash/sortBy'; -import { computed, ref } from 'kolibri.lib.vueCompositionApi'; -import { get } from '@vueuse/core'; -import plugin_data from 'plugin_data'; - -const langArray = plugin_data.languages ? plugin_data.languages : []; -const langMap = {}; - -export function setLanguages(langs) { - for (const lang of langs) { - langMap[lang.id] = lang; - } -} - -setLanguages(langArray); - -// The refs are defined in the outer scope so they can be used as a shared store -const languagesMap = ref(langMap); - -export default function useLanguages() { - const languages = computed(() => sortBy(Object.values(get(languagesMap)), 'id')); - return { - languages, - languagesMap, - }; -}