Skip to content

Commit

Permalink
add filter setting in url
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilReinking committed Nov 9, 2023
1 parent fd2ad0e commit d232515
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand All @@ -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;
}
</script>
6 changes: 2 additions & 4 deletions resources/js/components/Dashboard/FormListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const publishForm = async () => {
};
const unpublishForm = async () => {
await callUnpublishForm(props.form)
await callUnpublishForm(props.form);
window.location.reload();
};
Expand All @@ -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);
Expand Down

0 comments on commit d232515

Please sign in to comment.