Files
materio-d9/web/themes/custom/materiotheme/vuejs/components/Pages/Base.vue
T
bachirandClaude Opus 5.5 1e882d5bda Search texts and states, help tooltip, wider field (F4)
materio_sapi: result messages with real plurals; without any exact
match the results are called close (the neighbour search always finds
some). Former help sentence of the base page kept, French corrected.
Messages in SearchMessage, unit tested; French added by update 11002.

materiotheme: placeholder "Describe the material you are looking for",
wider search field, "?" button with a help tooltip and clickable
examples, "Loading…", "End of results"; texts in vuejs/i18n/search.js.
Page title "Base" restored without a search (keys is an array, test its
length).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ShDspHaZGwHoRZCsPBJzsM
2026-11-23 16:44:28 +01:00

155 lines
4.7 KiB
Vue

<template>
<div id="Base">
<div class="loading" v-if="!searchinfos">
<span>{{ text.loading }}</span>
</div>
<div class="cards-list" v-else>
<!-- aria-live: screen readers announce the result message of each search (F1). -->
<aside class="search-info" aria-live="polite">
{{ searchinfos }}
</aside>
<div class="loading" v-if="!items.length & !noresults">
<span>{{ text.loading }}</span>
</div>
<ul v-else>
<li v-for="item in displayedItems" v-bind:key="item.id">
<Card v-if="item.bundle == 'materiau'" :item="item"/>
<CardThematique v-if="item.bundle == 'thematique'" :item="item"/>
</li>
</ul>
<infinite-loading
v-if="count > limit && displayedItems.length >= limit"
:identifier="searchId"
@infinite="nextPage"
>
<div slot="no-more">{{ text.end }}</div>
</infinite-loading>
</div>
</div>
</template>
<script>
import Card from 'vuejs/components/Content/Card'
import CardThematique from 'vuejs/components/Content/CardThematique'
import { mapState, mapActions } from 'vuex'
import { searchTexts } from 'vuejs/i18n/search'
export default {
name: "Base",
data() {
return {
pagetitle:"Base",
// searchinfos: null
}
},
computed: {
...mapState({
items: state => state.Search.items,
searchinfos: state => state.Search.infos,
count: state => state.Search.count,
noresults: state => state.Search.noresults,
limit: state => state.Search.limit,
searchId: state => state.Search.searchId,
keys: state => state.Search.keys
}),
text: searchTexts,
// items is a sparse array (pages placed by offset); drop the holes left by
// pages that returned fewer results than the limit before rendering.
displayedItems () {
return this.items.filter(Boolean)
}
},
// Title of the browser tab: the phrase searched (F3).
metaInfo () {
return {
title: this.keys && this.keys.length ? this.keys.join(', ') : 'Base'
}
},
methods: {
// terms of an URL: a JSON list, possibly malformed in an old or edited
// link; never break the page for it (F3).
parseTerms (value) {
try {
const terms = JSON.parse(value)
return Array.isArray(terms) ? terms : []
} catch (e) {
return []
}
},
...mapActions({
newSearch: 'Search/newSearch',
nextPage: 'Search/nextPage'
}),
// infiniteHandler($state){
// console.log('inifiniteHandler', $state)
// this.nextPage()
// }
},
created() {
// at first page load or first route entering launch a search if params exists in url query
console.log('Base created() location',window.location)
let params = new URLSearchParams(window.location.search)
if (params.has('keys')) {
const r = /,\s?$/
let keys = params.get('keys').replace(r,'').split(', ')
console.log('Base created, keys', keys)
this.$store.commit('Search/setKeys', keys)
this.pagetitle = keys.join(', ') //params.get('keys')
} else {
this.$store.commit('Search/reSetKeys')
this.pagetitle = 'Base'
}
if (params.has('terms')) {
console.log('Base created, has terms', params.get('terms'))
// this.$store.commit('Search/setTerms', params.get('terms').split(','))
this.$store.commit('Search/setTerms', this.parseTerms(params.get('terms')))
} else {
this.$store.commit('Search/reSetTerms')
}
// The filters parameter of former URLs is ignored (F2).
this.newSearch()
},
beforeRouteUpdate (to, from, next) {
// when query change launch a new search
console.log('Base beforeRouteUpdate', to, from, next)
// todo text field of search form is not emptying on clicking on base after a search
// this.$store.commit('Search/setKeys', to.query.keys)
if (to.query.hasOwnProperty('terms')) {
// to.query.terms is a raw JSON string (see SearchForm.submit) and must be
// parsed like in created(), otherwise getResults() double-encodes it and
// the backend silently drops the terms (less relevant results).
this.$store.commit('Search/setTerms', this.parseTerms(to.query.terms))
}else{
this.$store.commit('Search/reSetTerms')
}
if (to.query.hasOwnProperty('keys')) {
const r = /,\s?$/
let keys = to.query.keys.replace(r,'').split(', ')
console.log('Base created, keys', keys)
this.$store.commit('Search/setKeys', keys)
this.pagetitle = to.query.keys
}else{
this.$store.commit('Search/reSetKeys')
}
this.newSearch()
next()
},
components: {
Card,
CardThematique
}
}
</script>
<style lang="scss" scoped>
</style>