diff --git a/src/components/Facet.vue b/src/components/Facet.vue
index 5a4da81..86fff1a 100644
--- a/src/components/Facet.vue
+++ b/src/components/Facet.vue
@@ -45,9 +45,10 @@ function onToggle (event: Event) {
+}
+
\ No newline at end of file
diff --git a/src/stores/facets.ts b/src/stores/facets.ts
index 64fa69f..40673e6 100644
--- a/src/stores/facets.ts
+++ b/src/stores/facets.ts
@@ -11,14 +11,20 @@ export const useFacetStore = defineStore('facets', () => {
const facets: Ref = ref([])
const facetExpanded: Ref<{ [key: string]: boolean | undefined }> = ref({})
- const computedExpansionState: {[key: string]: WritableComputedRef } = {}
+ const computedExpansionState: { [key: string]: WritableComputedRef } = {}
+ const isMobile = typeof window !== 'undefined' && window.innerWidth <= 700
+ const facetsOpen = ref(!isMobile)
// ------------------------------
// Computed properties
const facetNames = computed(() => { return facets.value.map(f => f.name) })
- function expanded (facetName: string) {
+ function toggleFacets() {
+ facetsOpen.value = !facetsOpen.value
+ }
+
+ function expanded(facetName: string) {
let expansionState = computedExpansionState[facetName]
if (!expansionState) {
expansionState = computed({
@@ -37,7 +43,7 @@ export const useFacetStore = defineStore('facets', () => {
// ------------------------------
// Actions
- function expandAll (expandedNames = facetNames.value) {
+ function expandAll(expandedNames = facetNames.value) {
const expanded = { ...facetExpanded.value }
for (const facetName of expandedNames) {
expanded[facetName] = true
@@ -45,16 +51,16 @@ export const useFacetStore = defineStore('facets', () => {
facetExpanded.value = expanded
}
- function collapseAll () {
+ function collapseAll() {
facetExpanded.value = {}
}
- function facetForName (name: string): Facet | undefined {
+ function facetForName(name: string): Facet | undefined {
return facets.value.find((f) => f.name === name)
}
// ------------------------------
// Store
- return { facets, expanded, facetNames, facetForName, expandAll, collapseAll }
+ return { facets, expanded, facetNames, facetForName, expandAll, collapseAll, facetsOpen, toggleFacets }
})
diff --git a/test/stores/facets.test.ts b/test/stores/facets.test.ts
index 8d00446..eab7a29 100644
--- a/test/stores/facets.test.ts
+++ b/test/stores/facets.test.ts
@@ -11,6 +11,18 @@ describe('facets', () => {
setActivePinia(createPinia())
})
+ describe('test toggle funtion', () => {
+ it('should toggle facetsOpen', () => {
+ const store = useFacetStore()
+ const initial = store.facetsOpen
+ store.toggleFacets()
+ expect(store.facetsOpen).toBe(!initial)
+
+ store.toggleFacets()
+ expect(store.facetsOpen).toBe(initial)
+ })
+ })
+
describe('without data', () => {
describe('facets', () => {
it('is initially empty', () => {