Skip to content

Commit

Permalink
Refactor LanguageSwitcher component to use DropdownLink; comment out …
Browse files Browse the repository at this point in the history
…Composer install step in deploy workflow
  • Loading branch information
abdessamadbettal committed Dec 6, 2024
1 parent 3ae9652 commit e57d738
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
php-version: '8.2'
tools: 'composer'

- name: Composer install
run: composer install
# - name: Composer install
# run: composer install

- name: NPM install
run: npm install && npm run build
Expand Down
15 changes: 11 additions & 4 deletions resources/js/Components/LanguageSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
</template>

<template #content>
<button
<DropdownLink
v-for="lang in languages"
:key="lang.code"
:href="getURL(lang)"
class="px-4 py-2 hover:bg-gray-100 cursor-pointer flex"
@click="changeLanguage(lang)"
@click.prevent="changeLanguage(lang)"
>
<img :src="lang.flag" alt="" class="w-4 h-4 me-2">
{{ lang.name }}
</button>
</DropdownLink>
</template>
</Dropdown>
</div>
Expand All @@ -39,7 +40,8 @@
import { computed } from 'vue';
import { router as inertiaRouter } from '@inertiajs/vue3';
import Dropdown from '@/Components/Forms/Dropdown.vue';
import { setLocale } from '@/i18n';
import DropdownLink from '@/Components/DropdownLink.vue';
import i18n, { setLocale } from '@/i18n';
const props = defineProps(['currentLocale']);
Expand All @@ -54,6 +56,11 @@ const currentLanguage = computed(() => {
return languages.find(lang => lang.code === props.currentLocale);
});
const getURL = (lang) => {
const currentUrl = new URL(window.location.href);
return currentUrl.pathname.replace(`/${props.currentLocale}`, `/${lang.code}`);
};
async function changeLanguage(lang) {
const currentUrl = new URL(window.location.href);
Expand Down

0 comments on commit e57d738

Please sign in to comment.