From c30a7f24a51bcfbbf99f3c09053641d55abb9430 Mon Sep 17 00:00:00 2001 From: Collin Henderson Date: Sat, 13 Apr 2024 14:07:25 -0400 Subject: [PATCH] more better flash bag and such --- app/Http/Controllers/SmartFiltersController.php | 8 ++++++-- .../components/shared/dialogs/SmartFilterDialog.vue | 2 -- resources/components/sidebar/SidebarSmartFilter.vue | 3 --- resources/composables/use-flash-bag/index.ts | 10 +++++++--- resources/views/dashboard.vue | 4 ++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/SmartFiltersController.php b/app/Http/Controllers/SmartFiltersController.php index e0fbd276..54730b48 100644 --- a/app/Http/Controllers/SmartFiltersController.php +++ b/app/Http/Controllers/SmartFiltersController.php @@ -43,13 +43,17 @@ public function update(Request $request, SmartFilter $smartFilter) $smartFilter->update($request->only(['name', 'body'])); - return redirect()->route('dashboard.show'); + return redirect() + ->route('dashboard.show') + ->with('success', 'Your smart filter has been updated.'); } public function destroy(SmartFilter $smartFilter) { $smartFilter->delete(); - return redirect()->route('dashboard.show'); + return redirect() + ->route('dashboard.show') + ->with('success', 'Your smart filter was deleted.'); } } diff --git a/resources/components/shared/dialogs/SmartFilterDialog.vue b/resources/components/shared/dialogs/SmartFilterDialog.vue index ac121b6c..e9da7055 100644 --- a/resources/components/shared/dialogs/SmartFilterDialog.vue +++ b/resources/components/shared/dialogs/SmartFilterDialog.vue @@ -48,7 +48,6 @@ watch( const addSmartFilter = async () => { try { await smartFiltersStore.addSmartFilter(form.fields) - showToast(`The '${form.fields.name}' smart filter was added.`) } catch (e) { const errors = e as Errors if (!errors[SPONSORSHIP_REQUIRED_ERROR]) { @@ -63,7 +62,6 @@ const updateSmartFilter = async () => { try { if (currentSmartFilter.value) { await smartFiltersStore.updateSmartFilter(currentSmartFilter.value.id, form.fields) - showToast(`The '${form.fields.name}' smart filter was updated.`) } } catch (e) { console.log(e) diff --git a/resources/components/sidebar/SidebarSmartFilter.vue b/resources/components/sidebar/SidebarSmartFilter.vue index a6d88485..a23ba578 100644 --- a/resources/components/sidebar/SidebarSmartFilter.vue +++ b/resources/components/sidebar/SidebarSmartFilter.vue @@ -2,7 +2,6 @@ import WatchValue from '@/components/shared/core/WatchValue.vue' import SidebarItem from '@/components/sidebar/SidebarItem.vue' import { useConfirm } from '@/composables/useConfirm' -import { useGlobalToast } from '@/composables/useGlobalToast' import { useSmartFilterDialog } from '@/composables/useSmartFilterDialog' import { useSmartFiltersStore } from '@/store/useSmartFiltersStore' import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue' @@ -17,7 +16,6 @@ const props = defineProps<{ const smartFiltersStore = useSmartFiltersStore() const { show: showSmartFilterDialog } = useSmartFilterDialog() const { isConfirmed } = useConfirm() -const { show: showToast } = useGlobalToast() const isContextMenuActive = ref(false) @@ -29,7 +27,6 @@ const deleteSmartFilter = async () => { }) ) { smartFiltersStore.deleteSmartFilter(props.smartFilter.id) - showToast(`'${props.smartFilter.name}' was deleted.`) } } diff --git a/resources/composables/use-flash-bag/index.ts b/resources/composables/use-flash-bag/index.ts index f74eced4..e6f74465 100644 --- a/resources/composables/use-flash-bag/index.ts +++ b/resources/composables/use-flash-bag/index.ts @@ -1,8 +1,12 @@ -export function useFlashBag(): App.Data.FlashBagData { +type ReactiveFlashBag = { + error: ComputedRef + success: ComputedRef +} +export function useFlashBag(): ReactiveFlashBag { const flash = useProperty('flash') return { - error: flash.value?.error ?? null, - success: flash.value?.success ?? null, + error: computed(() => flash.value?.error ?? null), + success: computed(() => flash.value?.success ?? null), } } diff --git a/resources/views/dashboard.vue b/resources/views/dashboard.vue index 3e5edaaf..852da725 100644 --- a/resources/views/dashboard.vue +++ b/resources/views/dashboard.vue @@ -79,8 +79,8 @@ registerHook('error', errors => { }) registerHook('success', () => { - if (flashBag.success) { - showToast(flashBag.success, ToastType.Success) + if (flashBag.success.value) { + showToast(flashBag.success.value, ToastType.Success) } })