From 00510820a2794efcadbc83f7f8b54318fe198ecb Mon Sep 17 00:00:00 2001
From: Zéro~Informatique
Date: Tue, 26 Jul 2022 08:44:34 +0200
Subject: viewer: migrate to vue 3, general refactoring and cleanup

Non-exhaustive list of fixes and improvements done at the same time:

- html default background to grey (avoids white flash during init)
- unified links behavior
- added more theme variables
- removed the flex-expand transition (it wasn't working) and replaced it
  with a slide
- fixed LdLoading not centered on the content
- title on removable tags
- fixed an issue with encoded URI from vue-router
- unified Item resource URLs
- removed the iframe for PlainTextViewer (it wasn't working properly)
  and replaced it with a pre
- fixed clear and search buttons tabindex
- fixed the information panel bumping up during the fade animation of
  tag's dropdown
- fixed some focus outlines not appearing correctly
- moved CSS variables to the :root context
- Code cleaning

GitHub: closes #217
GitHub: closes #300
GitHub: closes #297
GitHub: closes #105
GitHub: closes #267
GitHub: closes #275
GitHub: closes #228
GitHub: closes #215
GitHub: closes #112
---
 viewer/src/views/GalleryNavigation.vue | 106 ++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 54 deletions(-)

(limited to 'viewer/src/views/GalleryNavigation.vue')

diff --git a/viewer/src/views/GalleryNavigation.vue b/viewer/src/views/GalleryNavigation.vue
index 200637e..0869aaf 100644
--- a/viewer/src/views/GalleryNavigation.vue
+++ b/viewer/src/views/GalleryNavigation.vue
@@ -1,7 +1,7 @@
 <!-- ldgallery - A static generator which turns a collection of tagged
 --             pictures into a searchable web gallery.
 --
--- Copyright (C) 2019-2020  Guillaume FOUET
+-- 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
@@ -19,65 +19,63 @@
 
 <template>
   <div>
-    <ld-error v-if="isError" icon="folder-open" :message="$t('gallery.unknown-resource')" />
-    <gallery-search v-else-if="isSearch" :path="path" />
-    <component :is="componentName" v-else :key="componentKey" :item="$galleryStore.currentItem" />
+    <LdNotice
+      v-if="isError"
+      :icon="faFolderOpen"
+      :message="t('gallery.unknown-resource')"
+    />
+    <GallerySearch v-else-if="isSearch" />
+    <component
+      :is="componentName"
+      v-else
+      :key="componentKey"
+      :item="galleryStore.currentItem"
+    />
   </div>
 </template>
 
-<script lang="ts">
-import { ItemType } from "@/@types/ItemType";
-import Navigation from "@/services/navigation";
-import GallerySearch from "@/views/GallerySearch.vue";
-import { Component, Prop, Vue, Watch } from "vue-property-decorator";
+<script setup lang="ts">
+import { ItemType } from '@/@types/itemType';
+import LdNotice from '@/components/LdNotice.vue';
+import { isDirectory } from '@/services/itemGuards';
+import { useGalleryStore } from '@/store/galleryStore';
+import { faFolderOpen } from '@fortawesome/free-solid-svg-icons';
+import { computedEager } from '@vueuse/shared';
+import { computed, watchEffect } from 'vue';
+import { useI18n } from 'vue-i18n';
+import GallerySearch from './GallerySearch.vue';
+import AudioViewer from './item_handlers/AudioViewer.vue';
+import DirectoryViewer from './item_handlers/DirectoryViewer.vue';
+import DownloadViewer from './item_handlers/DownloadViewer.vue';
+import MarkdownViewer from './item_handlers/MarkdownViewer.vue';
+import PdfViewer from './item_handlers/PdfViewer.vue';
+import PictureViewer from './item_handlers/PictureViewer.vue';
+import PlainTextViewer from './item_handlers/PlainTextViewer.vue';
+import VideoViewer from './item_handlers/VideoViewer.vue';
 
-@Component({
-  components: {
-    GallerySearch,
-  },
-})
-export default class GalleryNavigation extends Vue {
-  @Prop(String) readonly path!: string;
-  @Prop(Array) readonly query!: string[];
+const props = defineProps({
+  path: { type: String, required: true },
+  query: { type: Array<string>, required: true },
+});
 
-  readonly COMPONENT_BY_TYPE: Record<ItemType, string> = {
-    directory: "ld-directory-viewer",
-    picture: "ld-picture-viewer",
-    plaintext: "ld-plain-text-viewer",
-    markdown: "ld-markdown-viewer",
-    pdf: "ld-pdf-viewer",
-    video: "ld-video-viewer",
-    audio: "ld-audio-viewer",
-    other: "ld-download-viewer",
-  };
+const { t } = useI18n();
+const galleryStore = useGalleryStore();
 
-  mounted() {
-    this.pathChanged();
-  }
+const COMPONENT_BY_TYPE: Record<ItemType, unknown> = {
+  directory: DirectoryViewer,
+  picture: PictureViewer,
+  plaintext: PlainTextViewer,
+  markdown: MarkdownViewer,
+  pdf: PdfViewer,
+  video: VideoViewer,
+  audio: AudioViewer,
+  other: DownloadViewer,
+};
 
-  get isError() {
-    return this.checkType(null);
-  }
+const isError = computedEager(() => !galleryStore.currentItem?.properties.type);
+const isSearch = computedEager(() => isDirectory(galleryStore.currentItem) && props.query.length > 0);
+const componentName = computed(() => COMPONENT_BY_TYPE[galleryStore.currentItem?.properties.type ?? ItemType.OTHER]);
+const componentKey = computed(() => galleryStore.currentItem?.path ?? '');
 
-  get isSearch() {
-    return this.checkType(ItemType.DIRECTORY) && this.query.length > 0;
-  }
-
-  get componentName() {
-    return this.COMPONENT_BY_TYPE[this.$galleryStore.currentItem?.properties.type ?? ItemType.OTHER];
-  }
-
-  get componentKey() {
-    return this.$galleryStore.currentItem?.path ?? "";
-  }
-
-  @Watch("path")
-  pathChanged() {
-    this.$galleryStore.setCurrentPath(this.path);
-  }
-
-  checkType(type: ItemType | null): boolean {
-    return Navigation.checkType(this.$galleryStore.currentItem, type);
-  }
-}
+watchEffect(() => (galleryStore.currentPath = props.path));
 </script>
-- 
cgit v1.2.3

