Cleaned up most vanilla try catches
This commit is contained in:
@@ -22,26 +22,25 @@ async function handleAction(): Promise<void> {
|
|||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
try {
|
const { error } = await tryCatch($fetch(`/api/calendars/${props.calendar.id}`, { method: "DELETE" }))
|
||||||
await $fetch(`/api/calendars/${props.calendar.id}`, { method: "DELETE" })
|
|
||||||
emit("on-close")
|
|
||||||
|
|
||||||
|
if (error) {
|
||||||
toast({
|
toast({
|
||||||
title: t("entity.calendar.deletedToast.title", { calendar: props.calendar.name }),
|
title: error.message,
|
||||||
variant: "success",
|
variant: "destructive"
|
||||||
duration: ToastLifetime.SHORT
|
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
if (err instanceof Error) {
|
|
||||||
toast({
|
|
||||||
title: err.message,
|
|
||||||
variant: "destructive"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("entity.calendar.deletedToast.title", { calendar: props.calendar.name }),
|
||||||
|
variant: "success",
|
||||||
|
duration: ToastLifetime.SHORT
|
||||||
|
})
|
||||||
|
|
||||||
|
emit("on-close")
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ async function handleSubmit() {
|
|||||||
const { error } = await tryCatch($fetch("/api/calendars/create", { method: "POST", body: { ...calendarSkeleton.value, worldId: props.worldId } }))
|
const { error } = await tryCatch($fetch("/api/calendars/create", { method: "POST", body: { ...calendarSkeleton.value, worldId: props.worldId } }))
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(error)
|
console.log(error.message)
|
||||||
isCreatingCalendar.value = false
|
isCreatingCalendar.value = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,17 +29,16 @@ async function handleSubmit() {
|
|||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
try {
|
const { error } = await tryCatch(submitSkeleton())
|
||||||
await submitSkeleton()
|
|
||||||
|
|
||||||
emit("event-created")
|
if (error) {
|
||||||
} catch (err) {
|
formErrors.message = error.message
|
||||||
if (err instanceof Error) {
|
|
||||||
formErrors.message = err.message
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit("event-created")
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,21 +22,20 @@ async function handleAction(): Promise<void> {
|
|||||||
|
|
||||||
const categoryName = categorySkeleton.value?.name
|
const categoryName = categorySkeleton.value?.name
|
||||||
|
|
||||||
try {
|
const { error } = await tryCatch(deleteCategoryFromSkeleton())
|
||||||
await deleteCategoryFromSkeleton()
|
|
||||||
|
|
||||||
toast({
|
if (error) {
|
||||||
title: t("entity.category.deletedToast.title", { category: categoryName }),
|
formErrors.message = error.message
|
||||||
variant: "success",
|
|
||||||
duration: ToastLifetime.MEDIUM
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof Error) {
|
|
||||||
formErrors.message = err.message
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("entity.category.deletedToast.title", { category: categoryName }),
|
||||||
|
variant: "success",
|
||||||
|
duration: ToastLifetime.MEDIUM
|
||||||
|
})
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,24 +22,23 @@ async function handleAction(): Promise<void> {
|
|||||||
|
|
||||||
const eventTitle = eventSkeleton.value.title
|
const eventTitle = eventSkeleton.value.title
|
||||||
|
|
||||||
try {
|
const { error } = await tryCatch(deleteEventFromSkeleton())
|
||||||
await deleteEventFromSkeleton()
|
|
||||||
|
|
||||||
isDeleteEventModalOpen.value = false
|
if (error) {
|
||||||
resetSkeleton()
|
formErrors.message = error.message
|
||||||
|
|
||||||
toast({
|
|
||||||
title: t("entity.calendar.event.deletedToast.title", { event: eventTitle }),
|
|
||||||
variant: "success",
|
|
||||||
duration: ToastLifetime.MEDIUM
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof Error) {
|
|
||||||
formErrors.message = err.message
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDeleteEventModalOpen.value = false
|
||||||
|
resetSkeleton()
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("entity.calendar.event.deletedToast.title", { event: eventTitle }),
|
||||||
|
variant: "success",
|
||||||
|
duration: ToastLifetime.MEDIUM
|
||||||
|
})
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -34,16 +34,20 @@ const validSkeleton = computed(() => validSkeletonGeneral.value && validSkeleton
|
|||||||
const isUpdatingCalendar = ref<boolean>(false)
|
const isUpdatingCalendar = ref<boolean>(false)
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
try {
|
isUpdatingCalendar.value = true
|
||||||
isUpdatingCalendar.value = true
|
|
||||||
await $fetch(`/api/calendars/${calendarSkeleton.value.id}`, { method: "PATCH", body: { ...calendarSkeleton.value, worldId: props.world?.id } })
|
|
||||||
|
|
||||||
emit("on-close")
|
const { error } = await tryCatch(
|
||||||
} catch (err) {
|
$fetch(`/api/calendars/${calendarSkeleton.value.id}`, { method: "PATCH", body: { ...calendarSkeleton.value, worldId: props.world?.id } })
|
||||||
console.log(err)
|
)
|
||||||
} finally {
|
|
||||||
|
if (error) {
|
||||||
|
console.log(error.message)
|
||||||
isUpdatingCalendar.value = false
|
isUpdatingCalendar.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit("on-close")
|
||||||
|
isUpdatingCalendar.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,19 +23,11 @@ async function handleAction() {
|
|||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
try {
|
const { error } = await tryCatch(updateEventFromSkeleton())
|
||||||
await updateEventFromSkeleton()
|
|
||||||
|
|
||||||
emit("event-updated")
|
if (error) {
|
||||||
|
|
||||||
toast({
|
|
||||||
title: t("entity.calendar.event.updatedToast.title", { event: eventSkeleton.value.title }),
|
|
||||||
variant: "success",
|
|
||||||
duration: ToastLifetime.SHORT
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const apiError = (err as any).data as APIError
|
const apiError = (error as any).data as APIError
|
||||||
|
|
||||||
apiError.data.errors.forEach((error) => {
|
apiError.data.errors.forEach((error) => {
|
||||||
toast({
|
toast({
|
||||||
@@ -45,10 +37,21 @@ async function handleAction() {
|
|||||||
duration: ToastLifetime.MEDIUM,
|
duration: ToastLifetime.MEDIUM,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} finally {
|
|
||||||
resetSkeleton()
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit("event-updated")
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("entity.calendar.event.updatedToast.title", { event: eventSkeleton.value.title }),
|
||||||
|
variant: "success",
|
||||||
|
duration: ToastLifetime.SHORT
|
||||||
|
})
|
||||||
|
|
||||||
|
isLoading.value = false
|
||||||
|
resetSkeleton()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,29 +21,27 @@ function closeMenu() {
|
|||||||
watch(user, closeMenu)
|
watch(user, closeMenu)
|
||||||
|
|
||||||
async function handleGoogleLogin() {
|
async function handleGoogleLogin() {
|
||||||
try {
|
const { error } = await auth.signInWithOAuth({
|
||||||
auth.signInWithOAuth({
|
provider: "google",
|
||||||
provider: "google",
|
options: {
|
||||||
options: {
|
queryParams: {
|
||||||
queryParams: {
|
access_type: "offline",
|
||||||
access_type: "offline",
|
prompt: "consent"
|
||||||
prompt: "consent"
|
},
|
||||||
},
|
redirectTo: profileUrl
|
||||||
redirectTo: profileUrl
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
} catch (err) {
|
if (error) {
|
||||||
console.log(err)
|
console.log(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleLogout() {
|
async function handleLogout() {
|
||||||
try {
|
const { error } = await auth.signOut()
|
||||||
const { error } = await auth.signOut()
|
|
||||||
|
|
||||||
if (error) throw error
|
if (error) {
|
||||||
} catch (err) {
|
console.log(error.message)
|
||||||
console.log(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,31 +17,30 @@ const isLoading = ref<boolean>(false)
|
|||||||
const emit = defineEmits(["on-close"])
|
const emit = defineEmits(["on-close"])
|
||||||
|
|
||||||
async function handleAction(): Promise<void> {
|
async function handleAction(): Promise<void> {
|
||||||
if (isLoading.value) return
|
if (isLoading.value || !props.world) return
|
||||||
if (!props.world) return
|
|
||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
|
||||||
try {
|
const { error } = await tryCatch(
|
||||||
await $fetch(`/api/worlds/${props.world.id}`, { method: "DELETE" })
|
$fetch(`/api/worlds/${props.world.id}`, { method: "DELETE" })
|
||||||
emit("on-close")
|
)
|
||||||
|
|
||||||
|
if (error) {
|
||||||
toast({
|
toast({
|
||||||
title: t("entity.world.deletedToast.title", { world: props.world.name }),
|
title: error.message,
|
||||||
variant: "success",
|
variant: "destructive"
|
||||||
duration: ToastLifetime.SHORT
|
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
if (err instanceof Error) {
|
|
||||||
toast({
|
|
||||||
title: err.message,
|
|
||||||
variant: "destructive"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("entity.world.deletedToast.title", { world: props.world.name }),
|
||||||
|
variant: "success",
|
||||||
|
duration: ToastLifetime.SHORT
|
||||||
|
})
|
||||||
|
emit("on-close")
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,16 +22,20 @@ const validSkeleton = computed(() => worldSkeleton.value.name)
|
|||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
if (!user.value) return
|
if (!user.value) return
|
||||||
|
|
||||||
try {
|
isLoading.value = true
|
||||||
isLoading.value = true
|
|
||||||
await $fetch("/api/worlds/create", { method: "POST", body: { ...worldSkeleton.value } })
|
|
||||||
|
|
||||||
emit("on-close")
|
const { error } = await tryCatch(
|
||||||
} catch (err) {
|
$fetch("/api/worlds/create", { method: "POST", body: { ...worldSkeleton.value } })
|
||||||
console.log(err)
|
)
|
||||||
} finally {
|
|
||||||
|
if (error) {
|
||||||
|
console.log(error.message)
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit("on-close")
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,22 +30,24 @@ const validSkeleton = computed(() => worldSkeleton.value.name)
|
|||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
if (!user.value || !worldSkeleton.value) return
|
if (!user.value || !worldSkeleton.value) return
|
||||||
|
|
||||||
try {
|
isLoading.value = true
|
||||||
isLoading.value = true
|
|
||||||
await $fetch(`/api/worlds/${worldSkeleton.value.id}`, { method: "PATCH", body: { ...worldSkeleton.value } })
|
|
||||||
|
|
||||||
toast({
|
const { error } = await tryCatch(
|
||||||
title: t("entity.world.updatedToast.title", { world: worldSkeleton.value.name }),
|
$fetch(`/api/worlds/${worldSkeleton.value.id}`, { method: "PATCH", body: { ...worldSkeleton.value } })
|
||||||
variant: "success",
|
)
|
||||||
duration: ToastLifetime.SHORT
|
|
||||||
})
|
|
||||||
|
|
||||||
emit("on-close")
|
if (error) {
|
||||||
} catch (err) {
|
console.log(error.message)
|
||||||
console.log(err)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("entity.world.updatedToast.title", { world: worldSkeleton.value.name }),
|
||||||
|
variant: "success",
|
||||||
|
duration: ToastLifetime.SHORT
|
||||||
|
})
|
||||||
|
|
||||||
|
emit("on-close")
|
||||||
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,22 +38,14 @@ function handleInsertedWorld(newWorld: WorldChannelPayload) {
|
|||||||
newWorld.createdAt = newWorld.created_at;
|
newWorld.createdAt = newWorld.created_at;
|
||||||
newWorld.gmId = newWorld.gm_id;
|
newWorld.gmId = newWorld.gm_id;
|
||||||
|
|
||||||
try {
|
worlds.value?.data.push(newWorld)
|
||||||
worlds.value?.data.push(newWorld)
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handles world deletion realtime events */
|
/** Handles world deletion realtime events */
|
||||||
function handleDeletedWorld(id: number) {
|
function handleDeletedWorld(id: number) {
|
||||||
if (!worlds.value?.data) return
|
if (!worlds.value?.data) return
|
||||||
|
|
||||||
try {
|
worlds.value.data.splice(worlds.value.data.findIndex(w => w.id === id), 1)
|
||||||
worlds.value.data.splice(worlds.value.data.findIndex(w => w.id === id), 1)
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -51,25 +51,17 @@ let worldChannel: RealtimeChannel
|
|||||||
function handleInsertedCalendar(newCalendar: CalendarChannelPayload) {
|
function handleInsertedCalendar(newCalendar: CalendarChannelPayload) {
|
||||||
if (!world.value) return
|
if (!world.value) return
|
||||||
|
|
||||||
newCalendar.createdAt = newCalendar.created_at;
|
newCalendar.createdAt = newCalendar.created_at
|
||||||
newCalendar.eventNb = [{ count: 0 }];
|
newCalendar.eventNb = [{ count: 0 }]
|
||||||
|
|
||||||
try {
|
world.value.data.calendars?.push(newCalendar)
|
||||||
world.value.data.calendars?.push(newCalendar)
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handles calendar deletion realtime events */
|
/** Handles calendar deletion realtime events */
|
||||||
function handleDeletedCalendar(id: number) {
|
function handleDeletedCalendar(id: number) {
|
||||||
if (!world.value) return
|
if (!world.value) return
|
||||||
|
|
||||||
try {
|
world.value.data.calendars?.splice(world.value.data.calendars.findIndex(c => c.id === id), 1)
|
||||||
world.value.data.calendars?.splice(world.value.data.calendars.findIndex(c => c.id === id), 1)
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -61,37 +61,33 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
const months = ref<CalendarMonth[]>([])
|
const months = ref<CalendarMonth[]>([])
|
||||||
|
|
||||||
function setActiveCalendar(calendarData: Calendar) {
|
function setActiveCalendar(calendarData: Calendar) {
|
||||||
try {
|
if (!calendarData.id) return
|
||||||
if (!calendarData.id) return
|
|
||||||
|
|
||||||
activeCalendar.value = {
|
activeCalendar.value = {
|
||||||
id: calendarData.id,
|
id: calendarData.id,
|
||||||
name: calendarData.name,
|
name: calendarData.name,
|
||||||
today: calendarData.today,
|
today: calendarData.today,
|
||||||
gmId: calendarData.world?.gmId
|
gmId: calendarData.world?.gmId
|
||||||
}
|
|
||||||
|
|
||||||
setDefaultDate(activeCalendar.value.today)
|
|
||||||
selectDate(activeCalendar.value.today)
|
|
||||||
setReadStatus(activeCalendar.value.gmId!)
|
|
||||||
|
|
||||||
if (!params.day) {
|
|
||||||
params.day = defaultDate.value.day.toString()
|
|
||||||
}
|
|
||||||
if (!params.month) {
|
|
||||||
params.month = defaultDate.value.month.toString()
|
|
||||||
}
|
|
||||||
if (!params.year) {
|
|
||||||
params.year = defaultDate.value.year.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
months.value = calendarData.months
|
|
||||||
|
|
||||||
baseEvents.value = calendarData.events
|
|
||||||
categories.value = calendarData.categories
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDefaultDate(activeCalendar.value.today)
|
||||||
|
selectDate(activeCalendar.value.today)
|
||||||
|
setReadStatus(activeCalendar.value.gmId!)
|
||||||
|
|
||||||
|
if (!params.day) {
|
||||||
|
params.day = defaultDate.value.day.toString()
|
||||||
|
}
|
||||||
|
if (!params.month) {
|
||||||
|
params.month = defaultDate.value.month.toString()
|
||||||
|
}
|
||||||
|
if (!params.year) {
|
||||||
|
params.year = defaultDate.value.year.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
months.value = calendarData.months
|
||||||
|
|
||||||
|
baseEvents.value = calendarData.events
|
||||||
|
categories.value = calendarData.categories
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = useUrlSearchParams("history", {
|
const params = useUrlSearchParams("history", {
|
||||||
|
|||||||
Reference in New Issue
Block a user