Skip to content

A self-hosted media server and file management system

fix: table search query reactivity is broken

aminnausin0b9931388fb0
diff --git a/resources/js/components/dashboard/DashboardActivity.vue b/resources/js/components/dashboard/DashboardActivity.vue
index 36120b8a..9f574461 100644
--- a/resources/js/components/dashboard/DashboardActivity.vue
+++ b/resources/js/components/dashboard/DashboardActivity.vue
@@ -48,10 +48,6 @@ const handleSort = async (column: keyof CategoryResource = 'created_at', dir: -1
categories.value = tempList;
return tempList;
};
-
-const handleSearch = (query: string) => {
- searchQuery.value = query;
-};
</script>
<template>
@@ -78,6 +74,6 @@ const handleSearch = (query: string) => {
:loading="false"
:sort-action="handleSort"
:sorting-options="sortingOptions"
- @search="handleSearch"
+ v-model="searchQuery"
/>
</template>
diff --git a/resources/js/components/dashboard/DashboardLibraries.vue b/resources/js/components/dashboard/DashboardLibraries.vue
index 463d9d3a..682d322e 100644
--- a/resources/js/components/dashboard/DashboardLibraries.vue
+++ b/resources/js/components/dashboard/DashboardLibraries.vue
@@ -2,7 +2,7 @@
import type { CategoryResource, FolderResource, SeriesResource } from '@/types/resources';
import type { BreadCrumbItem } from '@/types/types';
-import { computed, onMounted, ref, watchEffect } from 'vue';
+import { computed, ref, watchEffect } from 'vue';
import { startScanFilesTask } from '@/service/siteAPI';
import { useDashboardStore } from '@/stores/DashboardStore';
import { useContentStore } from '@/stores/ContentStore';
@@ -212,9 +212,8 @@ watchEffect(() => {
const title = cachedLibrary.value ? `Content Libraries · ${cachedLibrary.value.name}` : 'Content Libraries';
pageTitle.value = title;
document.title = title;
+ searchQuery.value = '';
});
-
-onMounted(() => {});
</script>
<template>
<div class="flex items-center gap-2 justify-between flex-wrap">
@@ -246,11 +245,7 @@ onMounted(() => {});
:sort-action="handleFolderSort"
:click-action="handleFolderAction"
:sorting-options="folderSortingOptions"
- @search="
- (query: string) => {
- searchQuery = query;
- }
- "
+ v-model="searchQuery"
/>
<TableBase
@@ -263,11 +258,7 @@ onMounted(() => {});
:loading="isLoadingLibraries"
:sort-action="handleSort"
:sorting-options="sortingOptions"
- @search="
- (query: string) => {
- searchQuery = query;
- }
- "
+ v-model="searchQuery"
/>
<ModalBase :modalData="confirmModal" :action="submitDelete">
<template #description> Are you sure you want to delete this Library? </template>
diff --git a/resources/js/components/dashboard/DashboardTaskMenu.vue b/resources/js/components/dashboard/DashboardTaskMenu.vue
index c766e099..ed690310 100644
--- a/resources/js/components/dashboard/DashboardTaskMenu.vue
+++ b/resources/js/components/dashboard/DashboardTaskMenu.vue
@@ -8,7 +8,7 @@ import LucideFolderCheck from '~icons/lucide/folder-check';
import LucideFolderTree from '~icons/lucide/folder-tree';
import LucideFolderSync from '~icons/lucide/folder-sync';
-const props = withDefaults(defineProps<{ showScanAll?: boolean }>(), { showScanAll: true });
+withDefaults(defineProps<{ showScanAll?: boolean }>(), { showScanAll: true });
const emit = defineEmits({
handleClose: () => true,
diff --git a/resources/js/components/dashboard/DashboardTasks.vue b/resources/js/components/dashboard/DashboardTasks.vue
index 3f32b180..e924891c 100644
--- a/resources/js/components/dashboard/DashboardTasks.vue
+++ b/resources/js/components/dashboard/DashboardTasks.vue
@@ -122,10 +122,6 @@ const handleSort = async (column: keyof TaskResource = 'created_at', dir: -1 | 1
return tempList;
};
-const handleSearch = (query: string) => {
- searchQuery.value = query;
-};
-
const handleDelete = (id: number, type: '' | 'cancel' | 'subTask' = '', innerId?: number) => {
cachedID.value = id;
if (type == 'cancel') cancelModal.toggleModal(true);
@@ -246,7 +242,7 @@ onUnmounted(async () => {
:sort-action="handleSort"
:sorting-options="sortingOptions"
:table-styles="'gap-4 xs:gap-2'"
- @search="handleSearch"
+ v-model="searchQuery"
/>
<ModalBase :modalData="cancelModal" :action="submitCancel">
<template #description> Are you sure you want to cancel this task and all of its sub tasks? </template>
diff --git a/resources/js/components/dashboard/DashboardUsers.vue b/resources/js/components/dashboard/DashboardUsers.vue
index 3cfe3d86..b468415d 100644
--- a/resources/js/components/dashboard/DashboardUsers.vue
+++ b/resources/js/components/dashboard/DashboardUsers.vue
@@ -90,10 +90,6 @@ const handleSort = async (column: keyof UserResource = 'created_at', dir: -1 | 1
return tempList;
};
-const handleSearch = (query: string) => {
- searchQuery.value = query;
-};
-
const handleDelete = (id: number) => {
cachedID.value = id;
confirmModal.toggleModal(true);
@@ -147,7 +143,7 @@ const loadData = async (refresh: boolean = false) => {
:sort-action="handleSort"
:sorting-options="sortingOptions"
:table-styles="'gap-4 xs:gap-2'"
- @search="handleSearch"
+ v-model="searchQuery"
/>
<ModalBase :modalData="confirmModal" :action="submitDelete">
<template #description> Are you sure you want to remove this user? </template>
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index 3d87210c..ba3f35e6 100755
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -19,19 +19,17 @@ const props = withDefaults(defineProps<TableProps<T>>(), {
itemsPerPage: 12,
selectedID: null,
startAscending: true,
- searchQuery: '',
usePaginationIcons: false,
maxVisiblePages: 5,
noResultsMessage: 'No Results',
});
-const emit = defineEmits<(e: 'search', value: string) => void>();
-
const tableData = useTable(props);
const sortAscending = ref(props.startAscending);
const lastSortKey = ref('');
-const model = defineModel<string | undefined>({
+// Search Query
+const model = defineModel<string>({
required: false,
default: undefined,
});
@@ -49,35 +47,23 @@ const handleSortChange = (sortKey?: SortOption) => {
props.sortAction?.(lastSortKey.value as keyof T, sortAscending.value ? 1 : -1);
};
-const handleSearch = (event: InputEvent) => {
- const target = event.target as HTMLInputElement;
- const value = target.value;
-
- if (model.value !== undefined) {
- model.value = value;
- } else {
- tableData.fields.searchQuery = value;
- }
- emit('search', value);
-};
-
onMounted(() => {
if (props.useToolbar && props.sortAction) props.sortAction(lastSortKey.value as keyof T, props.startAscending ? 1 : -1);
});
</script>
<template>
- <!-- [&>*:not(:first-child)]:pt-4 -->
<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">
<TextInputLabelled
- :value="model ?? tableData.fields.searchQuery"
+ v-if="model !== undefined"
+ v-model="model"
:placeholder="`Search ${props.itemName ? `${props.itemName}...` : ''}`"
:id="'table-search'"
class="w-full sm:w-80"
title="Search with..."
- @input="handleSearch"
/>
+
<span class="flex items-end gap-2 flex-wrap">
<div class="flex gap-2 flex-col w-full sm:w-40 flex-1">
<InputSelect
diff --git a/resources/js/composables/useTable.ts b/resources/js/composables/useTable.ts
index a491b476..0cf31b7b 100644
--- a/resources/js/composables/useTable.ts
+++ b/resources/js/composables/useTable.ts
@@ -3,7 +3,6 @@ import { computed, reactive, ref, watch } from 'vue';
export default function useTable(props: any) {
const currentPage = ref(1);
const itemsPerPage = ref(props.itemsPerPage ?? 10);
- const searchQuery = ref(props.searchQuery ?? '');
const table = reactive({
filteredPage: computed(() => {
@@ -13,7 +12,7 @@ export default function useTable(props: any) {
return props.data.slice(minIndex, maxIndex);
}),
props,
- fields: { currentPage, itemsPerPage, searchQuery },
+ fields: { currentPage, itemsPerPage },
handlePageChange(page: number) {
currentPage.value = page;
},
diff --git a/resources/js/views/HistoryView.vue b/resources/js/views/HistoryView.vue
index 7da7c827..c4f51060 100755
--- a/resources/js/views/HistoryView.vue
+++ b/resources/js/views/HistoryView.vue
@@ -76,10 +76,6 @@ const handleSort = (column: keyof RecordResource, dir = 1) => {
recordsSort(column, dir);
};
-const handleSearch = (query: string) => {
- searchQuery.value = query;
-};
-
onMounted(() => {
pageTitle.value = 'History';
selectedSideBar.value = '';
@@ -102,7 +98,7 @@ onMounted(() => {
:useToolbar="true"
:sortAction="handleSort"
:sortingOptions="sortingOptions"
- @search="handleSearch"
+ v-model="searchQuery"
/>
</section>
<ModalBase :modalData="confirmModal" :action="submitDelete">
diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vue
index 878ba202..44920b97 100755
--- a/resources/js/views/VideoView.vue
+++ b/resources/js/views/VideoView.vue
@@ -127,10 +127,6 @@ const handleSort = (column = 'date', dir = 1) => {
playlistSort({ column, dir });
};
-const handleSearch = (query: string) => {
- searchQuery.value = query;
-};
-
const handleVideoAction = (e: Event, id: number, action: 'edit' | 'share') => {
if (!stateFolder.value?.videos) return;
@@ -207,8 +203,6 @@ watch(() => stateVideo.value, setVideoAsDocumentTitle, { immediate: true });
:sortingOptions="sortingOptions"
:selectedID="stateVideo?.id"
:startAscending="true"
- :search-query="searchQuery"
- @search="handleSearch"
v-model="searchQuery"
/>