From d2325153496462a813eea2b4bcf0dfd3ca785ac5 Mon Sep 17 00:00:00 2001 From: Philipp Reinking Date: Thu, 9 Nov 2023 14:09:27 +0100 Subject: [PATCH] add filter setting in url --- app/Http/Controllers/DashboardController.php | 6 +++++- resources/js/Pages/Dashboard.vue | 13 +++++++++++++ resources/js/components/Dashboard/FormListItem.vue | 6 ++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index a4d067a5..01927b1e 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -9,7 +9,11 @@ class DashboardController extends Controller { public function show(Request $request) { - $forms = $request->user()->forms; + $request->validate([ + 'filter' => 'in:published,unpublished,trashed', + ]); + + $forms = $request->user()->forms()->withFilter($request->filter ?? null)->get(); return Inertia::render('Dashboard', [ 'initialForms' => $forms, diff --git a/resources/js/Pages/Dashboard.vue b/resources/js/Pages/Dashboard.vue index adb540b6..bca6d355 100644 --- a/resources/js/Pages/Dashboard.vue +++ b/resources/js/Pages/Dashboard.vue @@ -61,6 +61,9 @@ import FilterControl from "@/components/Dashboard/FilterControl.vue"; import { ref } from "vue"; import { callListForms } from "@/api/forms"; import { D9Spinner } from "@deck9/ui"; +import { useUrlSearchParams } from "@vueuse/core"; + +const params = useUrlSearchParams("history"); const props = withDefaults( defineProps<{ @@ -81,10 +84,20 @@ const changeFilter = async (setting: FilterSetting) => { const response = await callListForms(setting); filter.value = setting; forms.value = response.data; + + if (setting) { + params.filter = setting; + } else { + delete params.filter; + } } catch (e) { console.warn(e); } finally { isLoading.value = false; } }; + +if (params.filter) { + filter.value = params.filter as FilterSetting; +} diff --git a/resources/js/components/Dashboard/FormListItem.vue b/resources/js/components/Dashboard/FormListItem.vue index 3d295e42..42cb9c45 100644 --- a/resources/js/components/Dashboard/FormListItem.vue +++ b/resources/js/components/Dashboard/FormListItem.vue @@ -229,7 +229,7 @@ const publishForm = async () => { }; const unpublishForm = async () => { - await callUnpublishForm(props.form) + await callUnpublishForm(props.form); window.location.reload(); }; @@ -243,9 +243,7 @@ const restoreForm = async () => { }; const deleteForm = async () => { - window.confirm( - "Are you sure you want to delete your form?" - ); + window.confirm("Are you sure you want to delete your form?"); await callDeleteForm(props.form);