aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/views/layout/left/LayoutLeft.vue
blob: bb3e747e7094414a2ce9dd6ffdaf83c017637a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!-- ldgallery - A static generator which turns a collection of tagged
--             pictures into a searchable web gallery.
--
-- Copyright (C) 2019-2022  Guillaume FOUET
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General Public License
-- along with this program.  If not, see <https://www.gnu.org/licenses/>.
-->

<template>
  <div
    class="flex-column"
    :class="$style.sidebar"
  >
    <LayoutTagList v-model="searchFilters" />
    <LayoutTagInput
      v-model="searchFilters"
      @search="search"
      @opening="isOpenSearch=true"
      @closing="isOpenSearch=false"
    />
    <!-- We disable the components beneath the Dropdown for accessibility purposes -->
    <LayoutCommandSearch
      v-show="!isOpenSearch"
      @clear="clear"
      @search="search"
    />
    <h1
      v-show="!isOpenSearch"
      :class="$style.title"
    >
      {{ t("panelLeft.propositions.related") }}
    </h1>
    <div
      v-show="!isOpenSearch"
      class="scrollbar no-scroll-x"
      :class="$style.flexShrinkFully"
    >
      <LayoutProposition
        v-for="category in galleryStore.tagsCategories"
        :key="category.tag"
        v-model:search-filters="searchFilters"
        :category="galleryStore.tagsIndex[category.tag]"
        :show-category="galleryStore.tagsCategories.length > 1"
        :tags-index="category.index"
        :current-tags="currentTags"
      />
    </div>

    <template v-if="galleryStore.currentItem">
      <div class="flex-grow-1" />
      <h1
        :class="[$style.infoPanelTitleBar, $style.title]"
        class="flex"
        @click="infoOpen = !infoOpen"
      >
        {{ t("panelLeft.information.title") }}
        <fa-icon :icon="infoOpen ? faCaretDown : faCaretUp" />
      </h1>
      <transition name="slide">
        <LayoutInformation
          v-show="infoOpen"
          :item="galleryStore.currentItem"
          class="scrollbar no-scroll-x"
        />
      </transition>
    </template>
  </div>
</template>

<script setup lang="ts">
import { TagSearch } from '@/@types/tag';
import { useNavigation } from '@/services/navigation';
import { useGalleryStore } from '@/store/galleryStore';
import { faCaretDown, faCaretUp } from '@fortawesome/free-solid-svg-icons';
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router';
import LayoutCommandSearch from './LayoutCommandSearch.vue';
import LayoutInformation from './LayoutInformation.vue';
import LayoutProposition from './LayoutProposition.vue';
import LayoutTagInput from './LayoutTagInput.vue';
import LayoutTagList from './LayoutTagList.vue';

const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const navigation = useNavigation();
const galleryStore = useGalleryStore();

const searchFilters = ref<TagSearch[]>([]);
const infoOpen = ref(true);
const isOpenSearch = ref(false);

function clear() {
  searchFilters.value = [];
  search();
}

function search() {
  const lastDirectory = navigation.getLastDirectory(galleryStore.currentItemPath);
  router.push({ path: lastDirectory.path, query: serializeSearch() }).catch(err => {
    if (err.name !== 'NavigationDuplicated') throw err;
  });
}

function serializeSearch() {
  const query: Record<string, null> = {};
  searchFilters.value.forEach(filter => (query[filter.display] = null));
  return query;
}

const currentTags = computed(() => galleryStore.currentItem?.tags ?? []);

watch(() => route.query, (query) => {
  const filters = Object.keys(query);
  if (filters.length > 0) galleryStore.search(filters).then(search => (searchFilters.value = [...search]));
}, { immediate: true });
</script>

<style lang="scss" module>
@import "~@/assets/scss/theme";

.sidebar {
  .title {
    background-color: $proposed-category-bgcolor;
    color: $title-color;
    padding: 0.2em 0.5em;
    margin: 0 0 1px 0;
    font-variant: small-caps;
    justify-content: space-between;
    user-select: none;

    >svg {
      color: $link;
      margin-top: 2px; // Fixes a vertical centering issue with the carret
    }
  }

  .infoPanelTitleBar {
    cursor: pointer;
  }
}

.flexShrinkFully {
  flex-shrink: 1000;
}
</style>