Add ability to make a search without search string

This commit is contained in:
Chocobozzz 2021-11-12 15:07:06 +01:00
parent 99c18a2d78
commit ee291301c7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 18 additions and 53 deletions

View File

@ -10,7 +10,7 @@
},
"dependencies": {},
"devDependencies": {
"@jshmrtn/vue3-gettext": "^1.0.4",
"@jshmrtn/vue3-gettext": "^1.5.0",
"@sipec/vue3-tags-input": "^3.0.4",
"@types/axios": "^0.14.0",
"@types/markdown-it": "^10.0.1",

View File

@ -1,9 +1,9 @@
<template>
<div>
<my-header v-bind:indexName="indexName" v-bind:smallFormat="searchDone"></my-header>
<router-link v-if="searchDone" class="header-left-logo" to="/" @click="simpleFormReset(false)" :title="homeTitleMessage">
<div v-if="searchDone" class="header-left-logo">
<img src="/img/peertube-logo.svg" alt="">
</router-link>
</div>
<main>
<form id="search-anchor" class="search-container" v-bind:class="{ 'search-container-small': !searchDone }" role="search" onsubmit="return false;">
@ -15,7 +15,8 @@
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
<translate>Go!</translate>
<translate v-if="formSearch">Go!</translate>
<translate v-else>Explore!</translate>
</button>
</form>
@ -26,7 +27,7 @@
<search-warning class="search-warning" v-bind:indexName="indexName" v-bind:highlight="!searchDone"></search-warning>
<div class="results" v-if="searchDone">
<div class="filters" v-if="searchDone && searchedTerm">
<div class="filters">
<div class="button-rows">
<button class="filters-button peertube-button" v-on:click="toggleFilters()">
<translate>Filters</translate>
@ -191,28 +192,12 @@
</form>
</div>
<div id="results-anchor" class="results-summary" v-if="(searchedTerm && resultsCount === 0) || (resultsCount !== null && resultsCount !== 0)">
<span v-if="searchedTerm && resultsCount === 0" v-translate>No results found for</span>
<div id="results-anchor" class="results-summary">
<span v-if="resultsCount === 0">
<translate>No results found</translate></span>
&nbsp;
<span v-if="resultsCount !== null && resultsCount !== 0">
<translate :translate-n="resultsCount" translate-plural="%{resultsCount} results found for">%{resultsCount} result found for</translate>
</span>
&nbsp;
<strong>
{{ searchedTerm }}
<span v-if="activeFilters > 0">
<translate :translate-n="activeFilters" translate-plural="with %{activeFilters} active filters">with %{activeFilters} active filter</translate>
</span>
</strong>
&nbsp;
<span>
<translate :translate-n="instancesCount" translate-plural="on %{instancesCount} indexed PeerTube websites">on %{instancesCount} indexed PeerTube website</translate>
<span v-if="resultsCount">
<translate :translate-n="resultsCount" translate-plural="%{resultsCount} results found">%{resultsCount} result found</translate>
</span>
</div>
@ -294,6 +279,7 @@
padding: 0 15px 0 10px;
display: inline-flex;
align-items: center;
min-width: 100px;
svg {
margin-right: 10px;
@ -491,8 +477,6 @@
videosCount: null as number,
playlistsCount: null as number,
searchedTerm: '',
currentPage: 1,
pages: [],
resultsPerVideosPage: 10,
@ -548,11 +532,6 @@
const scrollToResults = urlPage && parseInt(urlPage) !== this.currentPage
this.loadUrl()
if (!this.formSearch) {
this.simpleFormReset(false)
this.scrollToTop()
return
}
this.doSearch()
if (scrollToResults) this.scrollToResults()
@ -694,10 +673,6 @@
}
return Array.from(languages)
},
homeTitleMessage (): string {
return this.$gettext('Display homepage')
}
},
@ -753,7 +728,6 @@
this.buildPages()
this.searchDone = true
this.searchedTerm = this.formSearch
} catch (err) {
console.error('Cannot do search.', err)
} finally {
@ -925,10 +899,6 @@
},
searchVideos (): Promise<ResultList<EnhancedVideo>> {
if (!this.formSearch) {
return Promise.resolve({ data: [], total: 0 })
}
if (!this.hasStillMoreVideosResults()) {
return Promise.resolve({ data: [], total: this.videosCount })
}
@ -939,7 +909,7 @@
},
searchChannels (): Promise<ResultList<EnhancedVideoChannel>> {
if (!this.formSearch || this.isChannelOrPlaylistSearchDisabled()) {
if (this.isChannelOrPlaylistSearchDisabled()) {
return Promise.resolve({ data: [], total: 0 })
}
@ -953,7 +923,7 @@
},
searchPlaylists (): Promise<ResultList<EnhancedPlaylist>> {
if (!this.formSearch || this.isChannelOrPlaylistSearchDisabled()) {
if (this.isChannelOrPlaylistSearchDisabled()) {
return Promise.resolve({ data: [], total: 0 })
}
@ -1029,11 +999,6 @@
else if (field === 'host') this.formHost = ''
},
simpleFormReset (searchDone = true) {
this.formSearch = ''
this.searchDone = searchDone
},
countActiveFilters () {
let count = 0

View File

@ -234,10 +234,10 @@
dependencies:
"@hapi/hoek" "^9.0.0"
"@jshmrtn/vue3-gettext@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@jshmrtn/vue3-gettext/-/vue3-gettext-1.0.4.tgz#a33faa87c9149013927aa6996540de95265443c5"
integrity sha512-FX2BcSnvutGpDG49NCIVuwIZ70x8sc9ARA1OPVrv8fOBk/IpgCTGzI9UihgAs0Ift3nDkAOM8k8MyI4SHIiG6g==
"@jshmrtn/vue3-gettext@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@jshmrtn/vue3-gettext/-/vue3-gettext-1.5.0.tgz#abafb2bd153cd85e10bd9464273321924d889aa4"
integrity sha512-wTy8IfWjYcRWeICyJJJ/NFRAGMymwksBcZgXlOcaHOoU3INapFUWgiDdr8vCCkJvjRMim2xFnKYHsIrsTJXJkg==
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"