Skip to content

Commit

Permalink
more better flash bag and such
Browse files Browse the repository at this point in the history
  • Loading branch information
syropian committed Apr 13, 2024
1 parent 9cb29bb commit c30a7f2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
8 changes: 6 additions & 2 deletions app/Http/Controllers/SmartFiltersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
2 changes: 0 additions & 2 deletions resources/components/shared/dialogs/SmartFilterDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions resources/components/sidebar/SidebarSmartFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -29,7 +27,6 @@ const deleteSmartFilter = async () => {
})
) {
smartFiltersStore.deleteSmartFilter(props.smartFilter.id)
showToast(`'${props.smartFilter.name}' was deleted.`)
}
}
</script>
Expand Down
10 changes: 7 additions & 3 deletions resources/composables/use-flash-bag/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export function useFlashBag(): App.Data.FlashBagData {
type ReactiveFlashBag = {
error: ComputedRef<null | string>
success: ComputedRef<null | string>
}
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),
}
}
4 changes: 2 additions & 2 deletions resources/views/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down

0 comments on commit c30a7f2

Please sign in to comment.