2021-05-10 23:44:28 +05:30
|
|
|
<template>
|
2022-01-12 16:57:08 +05:30
|
|
|
<nav class="flex flex-wrap items-center justify-center px-2 sm:px-4 py-2.5 w-full relative">
|
2022-03-14 20:27:42 +05:30
|
|
|
<div class="flex-1 flex justify-start">
|
2021-12-27 20:16:34 +05:30
|
|
|
<router-link class="flex font-bold text-3xl items-center font-sans font-bold" to="/"
|
2021-08-22 15:57:09 +05:30
|
|
|
><img
|
|
|
|
alt="logo"
|
|
|
|
src="/img/icons/logo.svg"
|
|
|
|
height="32"
|
|
|
|
width="32"
|
2021-12-27 20:16:33 +05:30
|
|
|
class="w-10 mr-[-0.6rem]"
|
2021-08-22 15:57:09 +05:30
|
|
|
/>iped</router-link
|
2021-04-01 03:39:39 +05:30
|
|
|
>
|
|
|
|
</div>
|
2021-12-27 20:16:36 +05:30
|
|
|
<div class="<md:hidden">
|
2021-04-01 03:39:39 +05:30
|
|
|
<input
|
2021-10-09 00:22:51 +05:30
|
|
|
v-model="searchText"
|
2021-12-27 20:16:36 +05:30
|
|
|
class="input !w-72 !h-10"
|
2021-04-01 03:39:39 +05:30
|
|
|
type="text"
|
2021-09-22 03:28:25 +05:30
|
|
|
role="search"
|
2022-06-26 14:27:12 +05:30
|
|
|
ref="videoSearch"
|
2021-09-22 03:28:25 +05:30
|
|
|
:title="$t('actions.search')"
|
|
|
|
:placeholder="$t('actions.search')"
|
2021-04-07 14:52:55 +05:30
|
|
|
@keyup="onKeyUp"
|
2021-12-04 12:34:44 +05:30
|
|
|
@keypress="onKeyPress"
|
2021-04-01 03:39:39 +05:30
|
|
|
@focus="onInputFocus"
|
|
|
|
@blur="onInputBlur"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-07-22 21:38:52 +05:30
|
|
|
<!-- three vertical lines for toggling the hamburger menu on mobile -->
|
|
|
|
<button class="md:hidden flex flex-col justify-end mr-3" @click="showTopNav = !showTopNav">
|
|
|
|
<span class="line"></span>
|
|
|
|
<span class="line"></span>
|
|
|
|
<span class="line"></span>
|
|
|
|
</button>
|
|
|
|
<!-- navigation bar for large screen devices -->
|
|
|
|
<ul class="hidden md:(flex-1 flex justify-end flex text-1xl children:pl-3)">
|
|
|
|
<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>
|
|
|
|
<li v-if="shouldShowLogin">
|
|
|
|
<router-link v-t="'titles.register'" to="/register" />
|
|
|
|
</li>
|
|
|
|
<li v-if="shouldShowHistory">
|
|
|
|
<router-link v-t="'titles.history'" to="/history" />
|
|
|
|
</li>
|
|
|
|
<li v-if="authenticated">
|
|
|
|
<router-link v-t="'titles.playlists'" to="/playlists" />
|
|
|
|
</li>
|
|
|
|
<li v-if="authenticated && !shouldShowTrending">
|
|
|
|
<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 -->
|
|
|
|
<ul v-if="showTopNav" class="flex flex-col justify-center items-end mb-4 children:(my-0.5 mr-5)">
|
|
|
|
<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>
|
|
|
|
<li v-if="shouldShowLogin">
|
|
|
|
<router-link v-t="'titles.register'" to="/register" />
|
|
|
|
</li>
|
|
|
|
<li v-if="shouldShowHistory">
|
|
|
|
<router-link v-t="'titles.history'" to="/history" />
|
|
|
|
</li>
|
|
|
|
<li v-if="authenticated">
|
|
|
|
<router-link v-t="'titles.playlists'" to="/playlists" />
|
|
|
|
</li>
|
|
|
|
<li v-if="authenticated && !shouldShowTrending">
|
|
|
|
<router-link v-t="'titles.feed'" to="/feed" />
|
|
|
|
</li>
|
|
|
|
</ul>
|
2021-12-27 20:16:26 +05:30
|
|
|
<div class="w-full md:hidden">
|
2021-04-01 03:39:39 +05:30
|
|
|
<input
|
2021-10-09 00:22:51 +05:30
|
|
|
v-model="searchText"
|
2021-12-27 20:16:36 +05:30
|
|
|
class="input !h-10 !w-full"
|
2021-04-01 03:39:39 +05:30
|
|
|
type="text"
|
2021-09-22 03:28:25 +05:30
|
|
|
role="search"
|
|
|
|
:title="$t('actions.search')"
|
|
|
|
:placeholder="$t('actions.search')"
|
2021-04-07 14:52:55 +05:30
|
|
|
@keyup="onKeyUp"
|
2021-12-04 12:34:44 +05:30
|
|
|
@keypress="onKeyPress"
|
2021-04-01 03:39:39 +05:30
|
|
|
@focus="onInputFocus"
|
|
|
|
@blur="onInputBlur"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<SearchSuggestions
|
2021-04-06 15:40:17 +05:30
|
|
|
v-show="searchText && suggestionsVisible"
|
2021-04-07 14:52:55 +05:30
|
|
|
ref="searchSuggestions"
|
2021-10-09 00:22:51 +05:30
|
|
|
: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,
|
2021-04-01 03:39:39 +05:30
|
|
|
};
|
|
|
|
},
|
2022-01-12 10:57:38 +05:30
|
|
|
mounted() {
|
2022-01-12 16:57:08 +05:30
|
|
|
const query = new URLSearchParams(window.location.search).get("search_query");
|
|
|
|
if (query) this.onSearchTextChange(query);
|
2022-06-26 14:27:12 +05:30
|
|
|
this.focusOnSearchBar();
|
2022-01-12 10:57:38 +05:30
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
computed: {
|
|
|
|
shouldShowLogin(_this) {
|
|
|
|
return _this.getAuthToken() == null;
|
|
|
|
},
|
2021-08-22 15:57:09 +05:30
|
|
|
shouldShowHistory(_this) {
|
|
|
|
return _this.getPreferenceBoolean("watchHistory", false);
|
|
|
|
},
|
2022-07-20 21:22:25 +05:30
|
|
|
shouldShowTrending(_this) {
|
|
|
|
return _this.getPreferenceString("homepage", "trending") != "trending";
|
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
},
|
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();
|
|
|
|
});
|
|
|
|
},
|
2021-04-07 14:52:55 +05:30
|
|
|
onKeyUp(e) {
|
2021-12-04 12:34:44 +05:30
|
|
|
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") {
|
2021-07-15 00:52:00 +05:30
|
|
|
e.target.blur();
|
2021-04-01 03:39:39 +05:30
|
|
|
this.$router.push({
|
|
|
|
name: "SearchResults",
|
2021-05-10 23:44:28 +05:30
|
|
|
query: { search_query: this.searchText },
|
2021-04-01 03:39:39 +05:30
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onInputFocus() {
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
2021-04-01 03:39:39 +05:30
|
|
|
};
|
|
|
|
</script>
|
2022-06-26 14:27:12 +05:30
|
|
|
<style>
|
|
|
|
.input:focus {
|
|
|
|
@apply border-2 border-red-500;
|
|
|
|
box-shadow: 0 0 15px rgba(239, 68, 68, var(--tw-border-opacity));
|
|
|
|
}
|
|
|
|
</style>
|