Skip to content

A self-hosted media server and file management system

feat: extract media sorting options to shared location

aminnausin9e2e425addef
diff --git a/resources/js/constants/sortingOptions.ts b/resources/js/constants/sortingOptions.ts
index cde60792..47c04f3e 100644
--- a/resources/js/constants/sortingOptions.ts
+++ b/resources/js/constants/sortingOptions.ts
@@ -1,5 +1,5 @@
+import type { CategoryResource, FolderResource, VideoResource } from '@/contracts/media';
import type { GenericSortOption } from '@/types/types';
-import type { CategoryResource, FolderResource } from '@/contracts/media';
export const librarySortingOptions: GenericSortOption<CategoryResource>[] = [
{
@@ -46,3 +46,66 @@ export const folderSortingOptions: GenericSortOption<FolderResource>[] = [
value: 'file_count',
},
];
+
+export const mediaSortingOptions = (folder: FolderResource): GenericSortOption<VideoResource>[] => [
+ {
+ title: 'Title',
+ value: 'title',
+ disabled: false,
+ },
+ {
+ title: 'Date Uploaded',
+ value: 'file_modified_at',
+ disabled: false,
+ },
+ {
+ title: 'Date Released',
+ value: 'released_at',
+ disabled: false,
+ },
+ {
+ title: 'Views',
+ value: 'view_count',
+ disabled: false,
+ },
+ {
+ title: 'Artist',
+ value: 'artist',
+ disabled: !folder.is_majority_audio,
+ hidden: !folder.is_majority_audio,
+ },
+ {
+ title: 'Album',
+ value: 'album',
+ disabled: !folder.is_majority_audio,
+ hidden: !folder.is_majority_audio,
+ },
+ {
+ title: folder.is_majority_audio ? 'Track Number' : `Episode`,
+ value: 'episode',
+ disabled: false,
+ },
+ {
+ title: folder.is_majority_audio ? 'Disc Number' : 'Season',
+ value: 'season',
+ disabled: false,
+ },
+ {
+ title: 'Duration',
+ value: 'duration',
+ disabled: false,
+ },
+ {
+ title: 'File Size',
+ value: 'file_size',
+ disabled: false,
+ },
+ {
+ title: 'Watch Progress',
+ value: 'progress_percentage',
+ },
+ {
+ title: 'Times Completed',
+ value: 'completion_count',
+ },
+];
diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vue
index fee8dd40..404d9580 100755
--- a/resources/js/views/VideoView.vue
+++ b/resources/js/views/VideoView.vue
@@ -5,6 +5,7 @@ import type { ComputedRef } from 'vue';
import type { SortDir } from '@/service/sort/types';
import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue';
+import { mediaSortingOptions } from '@/constants/sortingOptions';
import { useContentStore } from '@/stores/ContentStore';
import { useModalStore } from '@/stores/ModalStore';
import { toParamNumber } from '@/util/route';
@@ -74,68 +75,7 @@ async function reload() {
//#region TABLE
-const sortingOptions = computed(() => [
- {
- title: 'Title',
- value: 'title',
- disabled: false,
- },
- {
- title: 'Date Uploaded',
- value: 'file_modified_at',
- disabled: false,
- },
- {
- title: 'Date Released',
- value: 'released_at',
- disabled: false,
- },
- {
- title: 'Views',
- value: 'view_count',
- disabled: false,
- },
- {
- title: 'Artist',
- value: 'artist',
- disabled: !stateFolder.value.is_majority_audio,
- hidden: !stateFolder.value.is_majority_audio,
- },
- {
- title: 'Album',
- value: 'album',
- disabled: !stateFolder.value.is_majority_audio,
- hidden: !stateFolder.value.is_majority_audio,
- },
- {
- title: stateFolder.value.is_majority_audio ? 'Track Number' : `Episode`,
- value: 'episode',
- disabled: false,
- },
- {
- title: stateFolder.value.is_majority_audio ? 'Disc Number' : 'Season',
- value: 'season',
- disabled: false,
- },
- {
- title: 'Duration',
- value: 'duration',
- disabled: false,
- },
- {
- title: 'File Size',
- value: 'file_size',
- disabled: false,
- },
- {
- title: 'Watch Progress',
- value: 'progress_percentage',
- },
- {
- title: 'Times Completed',
- value: 'completion_count',
- },
-]) satisfies ComputedRef<GenericSortOption<VideoResource>[]>; // Idk what the point of using satisfies is
+const sortingOptions = computed(() => mediaSortingOptions(stateFolder.value)) satisfies ComputedRef<GenericSortOption<VideoResource>[]>; // Idk what the point of using satisfies is
const handleSort = (column: keyof VideoResource = 'file_modified_at', dir: SortDir = 1) => {
playlistSort({ column, dir });