Skip to content

A self-hosted media server and file management system

feat: sorting folders in sidebar

aminnausinb9f2cabc5423
diff --git a/resources/js/components/panels/VideoSidebar.vue b/resources/js/components/panels/VideoSidebar.vue
index 301ec3e8..ea11d8d6 100755
--- a/resources/js/components/panels/VideoSidebar.vue
+++ b/resources/js/components/panels/VideoSidebar.vue
@@ -1,11 +1,14 @@
<script setup lang="ts">
import type { FolderResource, SeriesResource } from '@/types/resources';
+import type { GenericSortOption, SortDir } from '@/types/types';
+import type { Ref } from 'vue';
-import { ref, watch, type Ref } from 'vue';
+import { computed, ref, watch } from 'vue';
import { useContentStore } from '@/stores/ContentStore';
import { toFormattedDate } from '@/service/util';
import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
+import { sortObject } from '@/service/sort/baseSort';
import ButtonClipboard from '@/components/pinesUI/ButtonClipboard.vue';
import ButtonText from '@/components/inputs/ButtonText.vue';
@@ -16,19 +19,55 @@ import ModalBase from '@/components/pinesUI/ModalBase.vue';
import TableBase from '@/components/table/TableBase.vue';
import useModal from '@/composables/useModal';
+import ProiconsFilterCancel from '~icons/proicons/filter-cancel';
+import ProiconsFilter from '~icons/proicons/filter';
+import ButtonIcon from '../inputs/ButtonIcon.vue';
+
+const folderSortingOptions: GenericSortOption<FolderResource>[] = [
+ {
+ title: 'Title',
+ value: 'name',
+ disabled: false,
+ },
+ {
+ title: 'Date Created',
+ value: 'created_at',
+ disabled: false,
+ },
+ {
+ title: 'Size',
+ value: 'total_size',
+ disabled: false,
+ },
+ {
+ title: 'File Count',
+ value: 'file_count',
+ disabled: false,
+ },
+];
+
const editFolderModal = useModal({ title: 'Edit Folder Details', submitText: 'Submit Details' });
const shareModal = useModal({ title: 'Share Video' });
const cachedFolder = ref<FolderResource>();
const shareLink = ref('');
+const folderSortDir = ref<SortDir>(1);
+const folderSortKey = ref<keyof FolderResource>(folderSortingOptions[0].value);
+const showFilters = ref(false);
+
const { stateRecords, stateDirectory, stateFolder } = storeToRefs(useContentStore()) as unknown as {
stateRecords: any;
stateDirectory: Ref<{ name: string; folders: FolderResource[] }>;
stateFolder: Ref<FolderResource>;
};
+
const { updateFolderData } = useContentStore();
const { selectedSideBar } = storeToRefs(useAppStore());
+const sortedFolders = computed<FolderResource[]>(() => {
+ return [...stateDirectory.value.folders].sort(sortObject<FolderResource>(folderSortKey.value, folderSortDir.value));
+});
+
const handleShare = (link: string) => {
if (!link || link[0] !== '/') return;
@@ -62,18 +101,32 @@ watch(
</script>
<template>
- <div class="flex py-1 flex-col gap-2">
- <h2 id="sidebar-title" class="text-2xl h-8 w-full capitalize dark:text-white truncate">{{ selectedSideBar }}</h2>
+ <div class="flex flex-col gap-2 py-1">
+ <div class="flex items-center justify-between">
+ <h2 id="sidebar-title" class="h-8 w-full truncate text-2xl capitalize dark:text-white">
+ {{ selectedSideBar }}
+ </h2>
+ <ButtonIcon
+ v-if="stateDirectory.folders.length > 10 && selectedSideBar === 'folders'"
+ class="!size-8 !p-0 dark:!ring-transparent hover:dark:!bg-violet-700 [&>*]:size-6"
+ @click="showFilters = !showFilters"
+ title="Toggle Filters"
+ >
+ <template #icon>
+ <component :is="showFilters ? ProiconsFilterCancel : ProiconsFilter" />
+ </template>
+ </ButtonIcon>
+ </div>
+
<hr class="" />
</div>
-
<TableBase
v-if="selectedSideBar === 'folders'"
id="list-content-folders"
- :data="stateDirectory.folders"
+ :data="sortedFolders"
:row="FolderCard"
:otherAction="handleFolderAction"
- :useToolbar="false"
+ :useToolbar="stateDirectory.folders.length > 10 && showFilters"
:startAscending="true"
:row-attributes="{
categoryName: stateDirectory.name,
@@ -83,20 +136,27 @@ watch(
:max-visible-pages="3"
:pagination-class="'!justify-center !flex-col-reverse'"
:use-pagination-icons="true"
+ :sort-action="
+ (sortKey: keyof FolderResource, sortDir: SortDir) => {
+ folderSortDir = sortDir;
+ folderSortKey = sortKey;
+ }
+ "
+ :sorting-options="folderSortingOptions"
/>
- <section v-if="selectedSideBar === 'history'" id="list-content-history" class="flex gap-2 flex-wrap">
+ <section v-if="selectedSideBar === 'history'" id="list-content-history" class="flex flex-wrap gap-2">
<RecordCard v-for="(record, index) in stateRecords.slice(0, 10)" :key="record.id" :record="record" :index="index" @clickAction="handleShare" />
<ButtonText
v-if="stateRecords.length > 0"
to="/history"
:title="'View All Watch History'"
- :class="'text-sm h-8 mx-auto mt-2 mb-2 hover:!bg-white dark:!bg-primary-dark-800/70 !bg-primary-800 dark:hover:!bg-primary-dark-600 line-clamp-1 truncate !rounded-full hover:!ring-violet-400 hover:dark:!ring-violet-700 hover:ring-[0.125rem]'"
+ :class="'mx-auto mb-2 mt-2 line-clamp-1 h-8 truncate !rounded-full !bg-primary-800 text-sm hover:!bg-white hover:ring-[0.125rem] hover:!ring-violet-400 dark:!bg-primary-dark-800/70 dark:hover:!bg-primary-dark-600 hover:dark:!ring-violet-700'"
:variant="'form'"
target=""
>
<template #text>View More</template>
</ButtonText>
- <h3 v-show="stateRecords.length < 1" class="text-gray-500 dark:text-gray-400 tracking-wider w-full py-2">Nothing Yet...</h3>
+ <h3 v-show="stateRecords.length < 1" class="w-full py-2 tracking-wider text-gray-500 dark:text-gray-400">Nothing Yet...</h3>
</section>
<ModalBase :modalData="shareModal">
<template #description> Copy link to clipboard to share it.</template>
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index ba3f35e6..63d3dc3f 100755
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -53,8 +53,8 @@ onMounted(() => {
</script>
<template>
- <section class="flex flex-col gap-4 w-full">
- <section v-if="props.useToolbar" class="flex justify-center sm:justify-between flex-col sm:flex-row gap-2">
+ <section class="flex w-full flex-col gap-3">
+ <section v-if="props.useToolbar" class="flex flex-col justify-center gap-2 sm:flex-row sm:justify-between">
<TextInputLabelled
v-if="model !== undefined"
v-model="model"
@@ -64,8 +64,8 @@ onMounted(() => {
title="Search with..."
/>
- <span class="flex items-end gap-2 flex-wrap">
- <div class="flex gap-2 flex-col w-full sm:w-40 flex-1">
+ <span :class="['flex flex-wrap items-end gap-2', { 'flex-1': model === undefined }]">
+ <div class="flex w-full flex-1 flex-col gap-2 sm:w-40">
<InputSelect
:name="'sort'"
:placeholder="'Sort by...'"
@@ -97,7 +97,7 @@ onMounted(() => {
<section :class="[useGrid || `flex w-full flex-wrap gap-2 ${tableStyles ?? ''}`]">
<div
v-if="loading || tableData.filteredPage.length === 0"
- class="col-span-full flex items-center justify-center text-center text-lg text-gray-500 dark:text-gray-400 uppercase tracking-wider w-full gap-2"
+ class="col-span-full flex w-full items-center justify-center gap-2 text-center text-lg uppercase tracking-wider text-gray-500 dark:text-gray-400"
>
<p>{{ loading ? '...Loading' : noResultsMessage }}</p>
<SvgSpinners90RingWithBg v-show="loading" />
diff --git a/resources/js/types/types.ts b/resources/js/types/types.ts
index 5b283ed1..c0075ad3 100644
--- a/resources/js/types/types.ts
+++ b/resources/js/types/types.ts
@@ -174,6 +174,12 @@ export declare type SortOption = {
disabled?: boolean;
};
+export declare type GenericSortOption<T> = {
+ title: string;
+ value: keyof T;
+ disabled?: boolean;
+};
+
export interface TableProps<T> {
useToolbar?: boolean;
usePagination?: boolean;