api-client/components/app/Header.vue

116 lines
3 KiB
Vue
Raw Normal View History

2020-03-04 01:17:02 +00:00
<template>
<header class="flex flex-1 py-2 px-4 items-center justify-between">
<div
2021-07-26 07:10:02 +00:00
class="
font-extrabold
space-x-2
flex-shrink-0
text-sm
inline-flex
items-center
"
>
<AppLogo />
2021-07-01 16:39:11 +00:00
</div>
2021-07-17 17:40:28 +00:00
<div class="space-x-2 flex-shrink-0 inline-flex items-center">
<AppGitHubStarButton class="mt-1 mr-2" />
2021-07-03 13:14:58 +00:00
<TabPrimary
2021-07-01 16:39:11 +00:00
id="installPWA"
2021-07-02 16:30:08 +00:00
v-tippy="{ theme: 'tooltip' }"
:title="$t('install_pwa')"
2021-07-03 13:14:58 +00:00
icon="offline_bolt"
@click.native="showInstallPrompt()"
/>
<span tabindex="-1">
<ButtonPrimary
v-if="currentUser === null"
2021-07-21 03:32:37 +00:00
label="Login"
@click.native="showLogin = true"
/>
2021-07-05 16:52:15 +00:00
<tippy
v-else
ref="user"
2021-07-08 07:30:41 +00:00
interactive
2021-07-05 16:52:15 +00:00
tabindex="-1"
trigger="click"
theme="popover"
arrow
>
2021-07-03 13:14:58 +00:00
<template #trigger>
<ProfilePicture
2021-07-02 16:30:08 +00:00
v-if="currentUser.photoURL"
2021-07-03 13:14:58 +00:00
v-tippy="{ theme: 'tooltip' }"
:url="currentUser.photoURL"
2021-07-05 16:52:15 +00:00
:alt="currentUser.displayName"
2021-07-03 13:14:58 +00:00
:title="
2021-07-24 05:53:10 +00:00
`${currentUser.displayName || 'Name not found'}` +
2021-07-03 13:14:58 +00:00
'<br>' +
2021-07-24 05:53:10 +00:00
`<sub>${currentUser.email || 'Email not found'}</sub>`
2021-07-03 13:14:58 +00:00
"
2021-07-02 16:30:08 +00:00
/>
2021-07-03 13:14:58 +00:00
<TabPrimary
v-else
v-tippy="{ theme: 'tooltip' }"
:title="$t('account')"
icon="account_circle"
/>
</template>
2021-07-05 16:52:15 +00:00
<SmartItem
to="/settings"
icon="settings"
:label="$t('settings')"
@click.native="$refs.user.tippy().hide()"
/>
<FirebaseLogout @confirm-logout="$refs.user.tippy().hide()" />
2021-07-03 13:14:58 +00:00
</tippy>
</span>
2020-03-04 01:17:02 +00:00
</div>
<FirebaseLogin :show="showLogin" @hide-modal="showLogin = false" />
2020-03-04 01:17:02 +00:00
</header>
</template>
<script>
import intializePwa from "~/helpers/pwa"
2021-06-14 04:07:30 +00:00
import { currentUser$ } from "~/helpers/fb/auth"
2021-06-21 04:27:45 +00:00
import { getLocalConfig, setLocalConfig } from "~/newstore/localpersistence"
2020-03-04 01:17:02 +00:00
export default {
data() {
return {
// Once the PWA code is initialized, this holds a method
// that can be called to show the user the installation
// prompt.
showInstallPrompt: null,
2021-07-03 13:14:58 +00:00
showLogin: false,
2021-06-14 04:07:30 +00:00
}
},
subscriptions() {
return {
currentUser: currentUser$,
2020-03-04 01:17:02 +00:00
}
},
2020-12-11 10:29:03 +00:00
async mounted() {
2020-03-04 01:17:02 +00:00
// Initializes the PWA code - checks if the app is installed,
// etc.
2020-12-11 10:29:03 +00:00
this.showInstallPrompt = await intializePwa()
2021-06-21 04:27:45 +00:00
const cookiesAllowed = getLocalConfig("cookiesAllowed") === "yes"
2020-12-11 10:29:03 +00:00
if (!cookiesAllowed) {
this.$toast.show(this.$t("we_use_cookies"), {
icon: "info",
duration: 5000,
theme: "toasted-primary",
action: [
{
text: this.$t("dismiss"),
2021-05-18 06:26:59 +00:00
onClick: (_, toastObject) => {
2021-06-21 04:27:45 +00:00
setLocalConfig("cookiesAllowed", "yes")
2020-12-11 10:29:03 +00:00
toastObject.goAway(0)
2020-03-04 01:17:02 +00:00
},
2020-12-11 10:29:03 +00:00
},
],
})
}
2020-03-04 01:17:02 +00:00
},
}
</script>