1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-16 23:30:27 +05:30
Piped/src/components/NavBar.vue

228 lines
7.9 KiB
Vue
Raw Normal View History

2021-05-10 23:44:28 +05:30
<template>
<nav class="relative w-full flex flex-wrap items-center justify-center px-2 pb-2.5 sm:px-4">
<div class="flex flex-1 justify-start">
<router-link class="flex items-center text-3xl font-bold font-sans" :to="homePagePath"
><img
alt="logo"
src="/img/icons/logo.svg"
height="32"
width="32"
class="mr-[-0.6rem] w-10"
/>iped</router-link
2021-04-01 03:39:39 +05:30
>
</div>
<div class="search-container lt-md:hidden">
2021-04-01 03:39:39 +05:30
<input
2023-07-27 17:16:05 +05:30
ref="videoSearch"
v-model="searchText"
class="input h-10 w-72 pr-20"
2021-04-01 03:39:39 +05:30
type="text"
role="search"
:title="$t('actions.search')"
:placeholder="$t('actions.search')"
@keyup="onKeyUp"
@keypress="onKeyPress"
2021-04-01 03:39:39 +05:30
@focus="onInputFocus"
@blur="onInputBlur"
/>
<span v-if="searchText" class="delete-search" @click="searchText = ''"></span>
2021-04-01 03:39:39 +05:30
</div>
2023-07-27 17:16:05 +05:30
<button id="search-btn" class="input btn mx-1 h-10" @click="onSearchClick">
<div class="i-fa6-solid:magnifying-glass"></div>
</button>
2022-07-22 21:38:52 +05:30
<!-- three vertical lines for toggling the hamburger menu on mobile -->
<button class="mr-3 flex flex-col justify-end md:hidden" @click="showTopNav = !showTopNav">
2022-07-22 21:38:52 +05:30
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
</button>
<!-- navigation bar for large screen devices -->
<ul class="md:text-1xl hidden md:(flex flex flex-1 justify-end children:pl-3)">
2022-07-22 21:38:52 +05:30
<li v-if="shouldShowTrending">
<router-link v-t="'titles.trending'" to="/trending" />
</li>
<li>
<router-link v-t="'titles.preferences'" to="/preferences" />
</li>
<li v-if="shouldShowLogin">
<router-link v-t="'titles.login'" to="/login" />
</li>
2023-07-14 04:12:33 +05:30
<li v-if="shouldShowRegister">
2022-07-22 21:38:52 +05:30
<router-link v-t="'titles.register'" to="/register" />
</li>
<li v-if="shouldShowHistory">
<router-link v-t="'titles.history'" to="/history" />
</li>
2023-01-07 01:08:42 +05:30
<li>
2022-07-22 21:38:52 +05:30
<router-link v-t="'titles.playlists'" to="/playlists" />
</li>
<li v-if="!shouldShowTrending">
2022-07-22 21:38:52 +05:30
<router-link v-t="'titles.feed'" to="/feed" />
</li>
</ul>
2021-04-01 03:39:39 +05:30
</nav>
2022-07-22 21:38:52 +05:30
<!-- navigation bar for mobile devices -->
2023-05-26 14:22:28 +05:30
<div
2022-07-22 22:19:27 +05:30
v-if="showTopNav"
class="mobile-nav mb-4 flex flex-col children:(w-full flex items-center gap-1 border-b border-dark-100 p-1)"
2022-07-22 22:19:27 +05:30
>
2023-05-26 14:22:28 +05:30
<router-link v-if="shouldShowTrending" to="/trending">
<div class="i-fa6-solid:fire"></div>
<i18n-t keypath="titles.trending"></i18n-t>
</router-link>
<router-link to="/preferences">
<div class="i-fa6-solid:gear"></div>
<i18n-t keypath="titles.preferences"></i18n-t>
</router-link>
<router-link v-if="shouldShowLogin" to="/login">
<div class="i-fa6-solid:user"></div>
<i18n-t keypath="titles.login"></i18n-t>
</router-link>
<router-link v-if="shouldShowLogin" to="/register">
<div class="i-fa6-solid:user-plus"></div>
<i18n-t keypath="titles.register"></i18n-t>
</router-link>
<router-link v-if="shouldShowHistory" to="/history">
<div class="i-fa6-solid:clock-rotate-left"></div>
<i18n-t keypath="titles.history"></i18n-t>
</router-link>
<router-link to="/playlists">
<div class="i-fa6-solid:list"></div>
<i18n-t keypath="titles.playlists"></i18n-t>
</router-link>
<router-link v-if="!shouldShowTrending" to="/feed">
<div class="i-fa6-solid:play"></div>
<i18n-t keypath="titles.feed"></i18n-t>
</router-link>
</div>
2022-07-22 22:19:27 +05:30
<!-- search suggestions for mobile devices -->
<div class="search-container mb-2 w-full md:hidden">
2021-04-01 03:39:39 +05:30
<input
v-model="searchText"
2022-08-17 19:04:57 +05:30
class="input h-10 w-full"
2021-04-01 03:39:39 +05:30
type="text"
role="search"
:title="$t('actions.search')"
:placeholder="$t('actions.search')"
@keyup="onKeyUp"
@keypress="onKeyPress"
2021-04-01 03:39:39 +05:30
@focus="onInputFocus"
@blur="onInputBlur"
/>
<span v-if="searchText" class="delete-search" @click="searchText = ''"></span>
2021-04-01 03:39:39 +05:30
</div>
<SearchSuggestions
2022-09-11 23:31:58 +05:30
v-show="(searchText || showSearchHistory) && suggestionsVisible"
ref="searchSuggestions"
:search-text="searchText"
@searchchange="onSearchTextChange"
2021-04-01 03:39:39 +05:30
/>
</template>
<script>
2022-04-08 21:16:49 +05:30
import SearchSuggestions from "./SearchSuggestions.vue";
2022-06-26 14:27:12 +05:30
import hotkeys from "hotkeys-js";
2021-04-01 03:39:39 +05:30
export default {
components: {
2021-05-10 23:44:28 +05:30
SearchSuggestions,
2021-04-01 03:39:39 +05:30
},
data() {
return {
searchText: "",
2021-05-10 23:44:28 +05:30
suggestionsVisible: false,
2022-07-22 21:38:52 +05:30
showTopNav: false,
homePagePath: "/",
2023-07-14 04:12:33 +05:30
registrationDisabled: false,
2021-04-01 03:39:39 +05:30
};
},
computed: {
shouldShowLogin(_this) {
return _this.getAuthToken() == null;
},
2023-07-14 04:12:33 +05:30
shouldShowRegister(_this) {
return _this.registrationDisabled == false ? _this.shouldShowLogin : false;
},
shouldShowHistory(_this) {
return _this.getPreferenceBoolean("watchHistory", false);
},
shouldShowTrending(_this) {
return _this.getPreferenceString("homepage", "trending") != "trending";
},
showSearchHistory(_this) {
return _this.getPreferenceBoolean("searchHistory", false) && localStorage.getItem("search_history");
2022-09-11 23:31:58 +05:30
},
},
2023-07-27 17:16:05 +05:30
mounted() {
this.fetchAuthConfig();
const query = new URLSearchParams(window.location.search).get("search_query");
if (query) this.onSearchTextChange(query);
this.focusOnSearchBar();
this.homePagePath = this.getHomePage(this);
},
2021-04-01 03:39:39 +05:30
methods: {
2022-06-26 14:27:12 +05:30
// focus on search bar when Ctrl+k is pressed
focusOnSearchBar() {
hotkeys("ctrl+k", event => {
event.preventDefault();
this.$refs.videoSearch.focus();
});
},
onKeyUp(e) {
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
e.preventDefault();
}
this.$refs.searchSuggestions.onKeyUp(e);
},
onKeyPress(e) {
2021-04-01 03:39:39 +05:30
if (e.key === "Enter") {
2023-07-17 14:13:58 +05:30
this.submitSearch(e);
2021-04-01 03:39:39 +05:30
}
},
onInputFocus() {
2022-09-11 23:31:58 +05:30
if (this.showSearchHistory) this.$refs.searchSuggestions.refreshSuggestions();
2021-04-01 03:39:39 +05:30
this.suggestionsVisible = true;
},
onInputBlur() {
this.suggestionsVisible = false;
2021-04-06 15:40:17 +05:30
},
onSearchTextChange(searchText) {
this.searchText = searchText;
2021-05-10 23:44:28 +05:30
},
2023-07-14 04:12:33 +05:30
async fetchAuthConfig() {
this.fetchJson(this.authApiUrl() + "/config").then(config => {
this.registrationDisabled = config?.registrationDisabled === true;
});
},
onSearchClick(e) {
this.submitSearch(e);
},
submitSearch(e) {
e.target.blur();
this.$router.push({
name: "SearchResults",
query: { search_query: this.searchText },
});
return;
},
2021-05-10 23:44:28 +05:30
},
2021-04-01 03:39:39 +05:30
};
</script>
2022-11-17 16:14:47 +05:30
<style>
.search-container {
@apply relative inline-flex items-center;
}
.delete-search {
@apply absolute right-3 cursor-pointer rounded-full bg-[#ccc] w-4 h-4 text-center text-black opacity-50 hover:(opacity-70) text-size-[10px];
2022-11-17 16:14:47 +05:30
}
.mobile-nav div {
@apply mx-1;
2022-11-17 16:14:47 +05:30
}
@media screen and (max-width: 848px) {
#search-btn {
display: none;
}
}
2022-11-17 16:14:47 +05:30
</style>