Skip to content

A self-hosted media server and file management system

fix sort ?

aminnausinf6c57df77334
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index 987caa36..5c7b8828 100755
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -1,5 +1,5 @@
-<script setup>
-import { ref } from 'vue';
+<script setup lang="ts">
+import { ref, watch } from 'vue';
import TextInputLabelled from '@/components/inputs/TextInputLabelled.vue';
import TablePagination from '@/components/table/TablePagination.vue';
@@ -28,12 +28,16 @@ const tableData = useTable(props);
const sortAscending = ref(true);
const lastSortKey = ref('');
-const handleSortChange = (sortKey) => {
- if (sortKey?.value) lastSortKey.value = sortKey?.value;
+const handleSortChange = (sortKey?: { title?: string; value?: string; disabled?: boolean }) => {
+ if (sortKey?.value) {
+ lastSortKey.value = sortKey.value;
+ }
if (!lastSortKey.value) return;
props.sortAction(lastSortKey.value, sortAscending.value ? 1 : -1);
};
+
+watch(props.data, tableData.handlePageReset, { immediate: true });
</script>
<template>
diff --git a/resources/js/stores/ContentStore.js b/resources/js/stores/ContentStore.js
index a707c4a5..44114ab9 100755
--- a/resources/js/stores/ContentStore.js
+++ b/resources/js/stores/ContentStore.js
@@ -21,15 +21,14 @@ export const useContentStore = defineStore('Content', () => {
// dir: {id: 1, name: 'anime', folders: ["id": "6", "name": "Frieren", "path": "anime/Frieren", "file_count": 28, "category_id": "1","series": null] } -> api/categories/1 -> folders dont hold video data
// folder: {id: 11, name: 'BOCCHI THE ROCK', videos: [id, name, pat, date, metadata], series: {}}
- const videoSortColumn = ref('title');
- const videoSortDir = ref(1);
+ const videoSort = ref({ column: 'title', dir: 1 });
const searchQuery = ref('');
const stateDirectory = ref({ id: 7, name: 'anime', folders: [] });
const stateFolder = ref({ id: 7, name: 'ODDTAXI', videos: [], series: null });
+ const stateVideo = ref({});
const stateFilteredPlaylist = computed(() => {
- // let dir = videoSortDir.value;
let list = stateFolder.value.videos;
let searchedList = searchQuery.value
@@ -48,22 +47,19 @@ export const useContentStore = defineStore('Content', () => {
})
: list;
- let sortedList = videoSortColumn.value
- ? searchedList.sort((videoA, videoB) => {
- if (videoSortColumn.value === 'date') {
- let dateA = new Date(videoA[videoSortColumn.value]);
- let dateB = new Date(videoB[videoSortColumn.value]);
- return (dateB - dateA) * videoSortDir.value;
- }
- if (videoSortColumn.value === 'name' || videoSortColumn.value === 'title')
- return videoA[videoSortColumn.value].localeCompare(videoB[videoSortColumn.value]) * videoSortDir.value;
- return (videoB[videoSortColumn.value] - videoA[videoSortColumn.value]) * videoSortDir.value;
- })
- : searchedList;
+ let sortedList = searchedList.sort((videoA, videoB) => {
+ if (videoSort.value.column === 'date') {
+ let dateA = new Date(videoA[videoSort.value.column]);
+ let dateB = new Date(videoB[videoSort.value.column]);
+ return (dateB - dateA) * videoSort.value.dir;
+ }
+ if (videoSort.value.column === 'name' || videoSort.value.column === 'title')
+ return videoA[videoSort.value.column].localeCompare(videoB[videoSort.value.column]) * videoSort.value.dir;
+ return (videoB[videoSort.value.column] - videoA[videoSort.value.column]) * videoSort.value.dir;
+ });
return sortedList;
}); // use a computed ref?
- const stateVideo = ref({});
const { pageTitle } = storeToRefs(AppStore);
const { userData } = storeToRefs(AuthStore);
@@ -82,8 +78,6 @@ export const useContentStore = defineStore('Content', () => {
}
function playlistFind(id) {
- console.log('find');
-
let result = stateFilteredPlaylist.value.length > 0 ? stateFilteredPlaylist.value[0] : {};
if (id && stateVideo.value.id === id) return;
@@ -281,6 +275,11 @@ export const useContentStore = defineStore('Content', () => {
};
}
+ function setVideoSort(val) {
+ videoSort.value = val;
+ console.log(val);
+ }
+
//#endregion
return {
@@ -291,6 +290,7 @@ export const useContentStore = defineStore('Content', () => {
stateVideo,
searchQuery,
stateFilteredPlaylist,
+ videoSort,
getRecords,
createRecord,
deleteRecord,
@@ -302,5 +302,6 @@ export const useContentStore = defineStore('Content', () => {
updateFolderData,
playlistFind,
playlistSort,
+ setVideoSort,
};
});
diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vue
index 121fc378..7e4a75f7 100755
--- a/resources/js/views/VideoView.vue
+++ b/resources/js/views/VideoView.vue
@@ -14,14 +14,13 @@ import TableBase from '../components/table/TableBase.vue';
const route = useRoute();
const loading = ref(true);
-const videoSortColumn = ref('title');
-const videoSortDir = ref(1);
+// const videoSort = ref({ column: 'title', dir: 1 });
const appStore = useAppStore();
const ContentStore = useContentStore();
const { selectedSideBar } = storeToRefs(appStore);
const { searchQuery, stateFilteredPlaylist, stateVideo, stateFolder } = storeToRefs(ContentStore);
-const { getFolder, getCategory, getRecords, playlistFind } = ContentStore;
+const { getFolder, getCategory, getRecords, playlistFind, setVideoSort } = ContentStore;
async function cycleSideBar(state) {
if (state === 'history') {
@@ -81,8 +80,9 @@ const sortingOptions = ref([
const handleSort = (column = 'date', dir = 1) => {
// playlistSort(column, dir);
- videoSortColumn.value = column;
- videoSortDir.value = dir;
+ setVideoSort({ column, dir });
+ // videoSortColumn.value = column;
+ // videoSortDir.value = dir;
};
const handleSearch = (query) => {
@@ -125,18 +125,7 @@ watch(() => selectedSideBar.value, cycleSideBar, { immediate: false });
<!-- <hr id='preData'> -->
<TableBase
- :data="
- stateFilteredPlaylist.sort((videoA, videoB) => {
- if (videoSortColumn === 'date') {
- let dateA = new Date(videoA[videoSortColumn]);
- let dateB = new Date(videoB[videoSortColumn]);
- return (dateB - dateA) * videoSortDir.value;
- }
- if (videoSortColumn === 'name' || videoSortColumn === 'title')
- return videoA[videoSortColumn].localeCompare(videoB[videoSortColumn]) * videoSortDir;
- return (videoB[videoSortColumn] - videoA[videoSortColumn]) * videoSortDir;
- })
- "
+ :data="stateFilteredPlaylist"
:row="VideoCard"
:clickAction="playlistFind"
:loading="loading"