Skip to content

Commit

Permalink
simplify response handling and improve api constant name
Browse files Browse the repository at this point in the history
  • Loading branch information
chukarave committed Feb 23, 2024
1 parent 91437ee commit 8cc8b6f
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions resources/js/Components/LanguageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import languageData from "@wikimedia/language-data";
const searchInput: Ref<string> = ref('');
const highlightedIndex: Ref<number> = ref(-1);
const closeUrl = ref(closeUrlSvg);
const apiSearchInput = ref(['']);
const apiLanguageCodes = ref(['']);
const input = ref<InstanceType<typeof LanguageSelectorInput> | null>(null);
Expand All @@ -64,11 +64,11 @@ const languages = computed<Language[]>(() => {
});
const shownLanguages = computed<Language[]>(() => {
return languages.value.filter((language) =>
language.code.startsWith(
searchInput.value.toLowerCase() ) ||
language.autonym.toLowerCase().includes(
searchInput.value.toLowerCase()) || apiSearchInput.value.includes(language.code))
return languages.value.filter((language) =>
language.code.startsWith(searchInput.value.toLowerCase()) ||
language.autonym.toLowerCase().includes(searchInput.value.toLowerCase()) ||
apiLanguageCodes.value.includes(language.code)
)
});
function onInput(searchedLanguage: string): void {
Expand All @@ -83,14 +83,11 @@ async function getApiLanguageCodes(inputValue: string) {
{
params: {
search: inputValue,
origin:'*' // avoid CORS console errors
origin: '*' // avoid CORS console errors
}
}).then((response) => {
const languageCodes = Object.keys(response.data.languagesearch);
languageCodes.forEach(languageCode => {
apiSearchInput.value.push(languageCode);
});
}) ;
apiLanguageCodes.value = Object.keys(response.data.languagesearch);
});
}
function onSelect(languageCode: string): void {
Expand Down

0 comments on commit 8cc8b6f

Please sign in to comment.