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": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"@jshmrtn/vue3-gettext": "^1.0.4", "@jshmrtn/vue3-gettext": "^1.5.0",
"@sipec/vue3-tags-input": "^3.0.4", "@sipec/vue3-tags-input": "^3.0.4",
"@types/axios": "^0.14.0", "@types/axios": "^0.14.0",
"@types/markdown-it": "^10.0.1", "@types/markdown-it": "^10.0.1",

View File

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

View File

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