api-client/packages/hoppscotch-common/src/components/app/Header.vue

207 lines
7.2 KiB
Vue
Raw Normal View History

2020-03-04 01:17:02 +00:00
<template>
<div>
<header
2022-12-01 12:17:39 +00:00
class="flex items-center justify-between flex-1 flex-shrink-0 px-2 py-2 space-x-2 overflow-x-auto overflow-y-hidden"
>
<div
class="inline-flex items-center space-x-2"
:style="{
paddingTop: platform.ui?.appHeader?.paddingTop?.value,
paddingLeft: platform.ui?.appHeader?.paddingLeft?.value,
}"
>
<HoppButtonSecondary
2022-02-01 07:50:40 +00:00
class="tracking-wide !font-bold !text-secondaryDark hover:bg-primaryDark focus-visible:bg-primaryDark uppercase"
2022-01-31 14:14:40 +00:00
:label="t('app.name')"
to="/"
/>
2021-12-31 14:35:39 +00:00
<AppGitHubStarButton class="mt-1.5 transition <sm:hidden" />
</div>
2022-01-31 14:14:40 +00:00
<div class="inline-flex items-center space-x-2">
<HoppButtonSecondary
v-if="showInstallButton"
v-tippy="{ theme: 'tooltip' }"
:title="t('header.install_pwa')"
:icon="IconDownload"
2021-12-04 13:29:26 +00:00
class="rounded hover:bg-primaryDark focus-visible:bg-primaryDark"
@click="installPWA()"
/>
<HoppButtonSecondary
v-tippy="{ theme: 'tooltip', allowHTML: true }"
2022-10-01 13:49:43 +00:00
:title="`${t('app.search')} <kbd>/</kbd>`"
:icon="IconSearch"
2021-12-04 13:29:26 +00:00
class="rounded hover:bg-primaryDark focus-visible:bg-primaryDark"
@click="invokeAction('modals.search.toggle')"
2021-08-28 17:53:16 +00:00
/>
<HoppButtonSecondary
v-tippy="{ theme: 'tooltip', allowHTML: true }"
:title="`${
mdAndLarger ? t('support.title') : t('app.options')
2022-10-01 13:49:43 +00:00
} <kbd>?</kbd>`"
:icon="IconLifeBuoy"
2021-12-04 13:29:26 +00:00
class="rounded hover:bg-primaryDark focus-visible:bg-primaryDark"
@click="invokeAction('modals.support.toggle')"
2021-08-28 15:18:13 +00:00
/>
<HoppButtonSecondary
v-if="currentUser === null"
:icon="IconUploadCloud"
:label="t('header.save_workspace')"
filled
2021-12-01 17:29:01 +00:00
class="hidden md:flex"
2022-12-14 13:59:04 +00:00
@click="invokeAction('modals.login.toggle')"
/>
<HoppButtonPrimary
v-if="currentUser === null"
:label="t('header.login')"
2022-12-14 13:59:04 +00:00
@click="invokeAction('modals.login.toggle')"
/>
2022-01-31 14:14:40 +00:00
<div v-else class="inline-flex items-center space-x-2">
<HoppButtonPrimary
2021-10-03 12:44:52 +00:00
v-tippy="{ theme: 'tooltip' }"
:title="t('team.invite_tooltip')"
:label="t('team.invite')"
:icon="IconUserPlus"
2021-12-01 17:29:01 +00:00
class="!bg-green-500 !bg-opacity-15 !text-green-500 !hover:bg-opacity-10 !hover:bg-green-400 !hover:text-green-600"
@click="showTeamsModal = true"
2021-10-03 12:44:52 +00:00
/>
<span class="px-2">
<tippy
interactive
trigger="click"
theme="popover"
:on-shown="() => tippyActions.focus()"
>
<ProfilePicture
v-if="currentUser.photoURL"
v-tippy="{
theme: 'tooltip',
}"
:url="currentUser.photoURL"
:alt="
currentUser.displayName ||
t('profile.default_hopp_displayname')
"
:title="
currentUser.displayName ||
currentUser.email ||
t('profile.default_hopp_displayname')
"
indicator
:indicator-styles="
network.isOnline ? 'bg-green-500' : 'bg-red-500'
"
/>
<ProfilePicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="
currentUser.displayName ||
currentUser.email ||
t('profile.default_hopp_displayname')
"
:initial="currentUser.displayName || currentUser.email"
indicator
:indicator-styles="
network.isOnline ? 'bg-green-500' : 'bg-red-500'
"
/>
<template #content="{ hide }">
<div
ref="tippyActions"
class="flex flex-col focus:outline-none"
tabindex="0"
2022-11-02 09:35:57 +00:00
@keyup.p="profile.$el.click()"
@keyup.s="settings.$el.click()"
@keyup.l="logout.$el.click()"
@keyup.escape="hide()"
>
<div class="flex flex-col px-2 text-tiny">
<span class="inline-flex font-semibold truncate">
{{
currentUser.displayName ||
t("profile.default_hopp_displayname")
}}
</span>
<span class="inline-flex truncate text-secondaryLight">
{{ currentUser.email }}
</span>
</div>
<hr />
<HoppSmartItem
ref="profile"
to="/profile"
:icon="IconUser"
:label="t('navigation.profile')"
2022-11-02 09:35:57 +00:00
:shortcut="['P']"
@click="hide()"
/>
<HoppSmartItem
ref="settings"
to="/settings"
:icon="IconSettings"
:label="t('navigation.settings')"
:shortcut="['S']"
@click="hide()"
/>
<FirebaseLogout
ref="logout"
:shortcut="['L']"
@confirm-logout="hide()"
/>
</div>
2021-10-03 12:44:52 +00:00
</template>
</tippy>
</span>
</div>
</div>
</header>
<AppAnnouncement v-if="!network.isOnline" />
2021-10-03 12:44:52 +00:00
<TeamsModal :show="showTeamsModal" @hide-modal="showTeamsModal = false" />
</div>
2020-03-04 01:17:02 +00:00
</template>
<script setup lang="ts">
2022-10-05 15:54:15 +00:00
import { computed, reactive, ref } from "vue"
import IconUser from "~icons/lucide/user"
import IconSettings from "~icons/lucide/settings"
import IconDownload from "~icons/lucide/download"
import IconSearch from "~icons/lucide/search"
import IconLifeBuoy from "~icons/lucide/life-buoy"
import IconUploadCloud from "~icons/lucide/upload-cloud"
import IconUserPlus from "~icons/lucide/user-plus"
import { breakpointsTailwind, useBreakpoints, useNetwork } from "@vueuse/core"
import { pwaDefferedPrompt, installPWA } from "@modules/pwa"
import { platform } from "~/platform"
import { useI18n } from "@composables/i18n"
import { useReadonlyStream } from "@composables/stream"
import { invokeAction } from "@helpers/actions"
2020-03-04 01:17:02 +00:00
const t = useI18n()
/**
* Once the PWA code is initialized, this holds a method
* that can be called to show the user the installation
* prompt.
*/
const showInstallButton = computed(() => !!pwaDefferedPrompt.value)
2021-08-28 15:18:13 +00:00
const showTeamsModal = ref(false)
const breakpoints = useBreakpoints(breakpointsTailwind)
const mdAndLarger = breakpoints.greater("md")
const network = reactive(useNetwork())
2021-08-01 14:34:25 +00:00
const currentUser = useReadonlyStream(
platform.auth.getProbableUserStream(),
platform.auth.getProbableUser()
)
2021-08-12 08:14:10 +00:00
// Template refs
const tippyActions = ref<any | null>(null)
const profile = ref<any | null>(null)
const settings = ref<any | null>(null)
const logout = ref<any | null>(null)
2020-03-04 01:17:02 +00:00
</script>