Skip to content

Commit

Permalink
feat: store array sort in session storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Jan 17, 2024
1 parent 53c980a commit 95c9393
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/main/webapp/src/components/layouts/FilesLayout.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script setup lang="ts">
import FileMenu from '@/components/FileMenu.vue';
import { app } from '@/constants.ts';
import { useConfigurationStore } from '@/stores/configurationStore.ts';
import type { File } from '@/types/fileType.ts';
import { dateToDuration } from '@/utils/dateFnsUtils.ts';
import { useSessionStorage } from '@vueuse/core';
import { storeToRefs } from 'pinia';
import { ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
Expand Down Expand Up @@ -32,17 +34,20 @@ const headers = ref<Array<any>>([
]);
const addColumnEditionDate = (): void => {
headers.value.splice(1, 0, {
title: t('information.edited'),
key: 'editionDate',
sortable: true,
headerProps: {
style: 'white-space: nowrap;',
},
cellProps: {
style: 'white-space: nowrap;',
},
});
const index = headers.value.findIndex((header) => header.key == 'editionDate');
if (index == -1) {
headers.value.splice(1, 0, {
title: t('information.edited'),
key: 'editionDate',
sortable: true,
headerProps: {
style: 'white-space: nowrap;',
},
cellProps: {
style: 'white-space: nowrap;',
},
});
}
};
const removeColumnEditionDate = (): void => {
Expand All @@ -57,14 +62,16 @@ watch(
},
{ immediate: true },
);
const sortBy = useSessionStorage<Array<any>>(`${app.slug}.sort-by`, [{ key: 'title', order: 'asc' }]);
</script>

<!-- eslint-disable vue/valid-v-slot -->
<template>
<v-data-table
:headers="headers"
:items="files"
:sort-by="[{ key: 'title', order: 'asc' }]"
v-model:sort-by="sortBy"
:search="search"
filter-keys="title"
:loading="files == undefined"
Expand Down

0 comments on commit 95c9393

Please sign in to comment.