api-client/components/app/Header.vue

182 lines
5.1 KiB
Vue
Raw Normal View History

2020-03-04 01:17:02 +00:00
<template>
2021-07-07 23:28:42 +00:00
<header class="flex items-center justify-between p-2 flex-1">
<div class="inline-flex space-x-2 items-center font-bold flex-shrink-0">
<AppLogo class="h-6 mx-4" /> Hoppscotch
2021-07-01 16:39:11 +00:00
</div>
2021-07-03 13:14:58 +00:00
<div class="inline-flex space-x-2 items-center flex-shrink-0">
<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"
label="Get Started"
@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="
(currentUser.displayName ||
'<label><i>Name not found</i></label>') +
'<br>' +
(currentUser.email || '<label><i>Email not found</i></label>')
"
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="/profile"
icon="person"
:label="$t('profile')"
@click.native="$refs.user.tippy().hide()"
/>
<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>
<span tabindex="-1">
<tippy
ref="options"
2021-07-08 07:30:41 +00:00
interactive
2021-07-03 13:14:58 +00:00
tabindex="-1"
trigger="click"
theme="popover"
arrow
2021-07-02 16:30:08 +00:00
>
2021-07-03 13:14:58 +00:00
<template #trigger>
<TabPrimary
v-tippy="{ theme: 'tooltip' }"
:title="$t('more')"
icon="drag_indicator"
2021-07-02 16:30:08 +00:00
/>
2021-07-03 13:14:58 +00:00
</template>
<SmartItem
icon="extension"
:label="$t('extensions')"
@click.native="
showExtensions = true
$refs.options.tippy().hide()
"
/>
<SmartItem
icon="keyboard"
:label="$t('shortcuts')"
@click.native="
showShortcuts = true
$refs.options.tippy().hide()
"
/>
<SmartItem
v-if="navigatorShare"
icon="share"
:label="$t('share')"
@click.native="
nativeShare()
$refs.options.tippy().hide()
"
/>
</tippy>
</span>
2020-03-04 01:17:02 +00:00
</div>
<FirebaseLogin :show="showLogin" @hide-modal="showLogin = false" />
2021-05-18 06:26:59 +00:00
<AppExtensions
:show="showExtensions"
@hide-modal="showExtensions = false"
/>
<AppShortcuts :show="showShortcuts" @hide-modal="showShortcuts = 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"
// import { hasExtensionInstalled } from "~/helpers/strategies/ExtensionStrategy"
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,
2020-03-04 01:17:02 +00:00
showExtensions: false,
showShortcuts: false,
navigatorShare: navigator.share,
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
},
methods: {
nativeShare() {
if (navigator.share) {
navigator
.share({
2020-08-13 11:20:02 +00:00
title: "Hoppscotch",
2021-05-15 12:43:31 +00:00
text: "Hoppscotch • Open source API development ecosystem - Helps you create requests faster, saving precious time on development.",
2020-08-25 07:57:59 +00:00
url: "https://hoppscotch.io",
2020-03-04 01:17:02 +00:00
})
.then(() => {})
.catch(console.error)
} else {
// fallback
}
},
},
}
</script>