-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create app-menu component + use custom fetch for user login #10
- Loading branch information
Showing
2 changed files
with
73 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<script setup lang="ts"> | ||
import type { User } from '~/libs/apiTypes' | ||
const back = ref(true) | ||
const user = useState<User>('user') | ||
const { locale, locales, setLocale } = useI18n() | ||
const availableLocales = computed(() => { | ||
return locales.value.filter((i) => i.code !== locale.value) | ||
}) | ||
// Function from https://dev.to/jorik/country-code-to-flag-emoji-a21 | ||
function getFlagEmoji(countryCode: string) { | ||
const codePoints = countryCode | ||
.toUpperCase() | ||
.split('') | ||
.map((char) => 127397 + char.charCodeAt(0)) | ||
return String.fromCodePoint(...codePoints) | ||
} | ||
</script> | ||
|
||
<template> | ||
<el-menu mode="horizontal" :ellipsis="false"> | ||
<el-menu-item v-if="back" index="0"> | ||
<nuxt-link to="/" :title="$t('app.back')"> | ||
<img src="/favicon.svg" style="width: 6em" /> | ||
</nuxt-link> | ||
</el-menu-item> | ||
<el-menu-item v-else index="0"> | ||
<img src="/favicon.svg" style="width: 6em" /> | ||
</el-menu-item> | ||
<div class="flex-grow" /> | ||
<el-menu-item index="1"> | ||
<slot name="header" /> | ||
</el-menu-item> | ||
<div class="flex-grow" /> | ||
<el-menu-item index="2"> | ||
<el-select | ||
v-model="locale" | ||
class="m-2" | ||
placeholder="Language" | ||
size="small" | ||
@change="setLocale" | ||
> | ||
<el-option | ||
v-for="l in availableLocales" | ||
:key="l.code" | ||
:label="`${getFlagEmoji(l.flag)} ${l.name}`" | ||
:value="l.code" | ||
:fit-input-width="true" | ||
/> | ||
</el-select> | ||
</el-menu-item> | ||
<el-menu-item index="3"> | ||
<User :user="user" /> | ||
</el-menu-item> | ||
</el-menu> | ||
</template> | ||
|
||
<style scoped> | ||
.flex-grow { | ||
flex-grow: 1; | ||
} | ||
</style> |