mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-25 17:10:26 +01:00
Working
This commit is contained in:
@@ -14,7 +14,7 @@ export async function useCategories() {
|
||||
await useSuccessToast('Category successfully created!', category.color)
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Category creation failed!', error as string)
|
||||
useErrorToast('Category creation failed!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function useCategories() {
|
||||
await useSuccessToast('Category successfully updated!')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Category update failed!', error as string)
|
||||
useErrorToast('Category update failed!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function useCategories() {
|
||||
await useSuccessToast('Category successfully deleted!')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Category deletion failed!', error as string)
|
||||
useErrorToast('Category deletion failed!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function useTabs() {
|
||||
useSuccessToast('Tab successfully created!', tab.color)
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Tab creation failed!', error as string)
|
||||
useErrorToast('Tab creation failed!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export async function useTabs() {
|
||||
useSuccessToast('Tab successfully updated!')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Tab update failed!', error as string)
|
||||
useErrorToast('Tab update failed!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export async function useTabs() {
|
||||
useSuccessToast(`Tab ${tab.name} ${primary ? 'set as favorite' : 'unset as favorite'}!`, 'yellow')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Cannot toggle favorite state for tab!', error as string)
|
||||
useErrorToast('Cannot toggle favorite state for tab!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ export async function useTabs() {
|
||||
useSuccessToast('Tab successfully deleted!')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('Tab deletion failed!', error as string)
|
||||
useErrorToast('Tab deletion failed!', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,16 @@ export async function useUserLimits() {
|
||||
function canCreateCategory() {
|
||||
if (hasPaidPlan.value)
|
||||
return true
|
||||
if (!userLimits.value.categories)
|
||||
return false
|
||||
return userLimits.value.categories.length < MAX_CATEGORIES
|
||||
}
|
||||
|
||||
function canCreateTabInCategory(categoryId: number): boolean {
|
||||
if (hasPaidPlan.value)
|
||||
return true
|
||||
if (!userLimits.value.categories || !userLimits.value.categories.find(category => category.id === categoryId))
|
||||
return false
|
||||
return userLimits.value.categories.find(category => category.id === categoryId).tabs.length < MAX_TABS_PER_CATEGORY
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
export async function useUser() {
|
||||
const { fetch } = useUserSession()
|
||||
const { fetch, session } = useUserSession()
|
||||
|
||||
async function deleteAvatar() {
|
||||
try {
|
||||
await useRequestFetch()('/api/users/avatars', {
|
||||
await $fetch('/api/users/avatars', {
|
||||
method: 'DELETE',
|
||||
})
|
||||
useSuccessToast('Avatar successfully deleted!')
|
||||
await fetch()
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('An error occurred while deleting your avatar', error as string)
|
||||
useErrorToast('An error occurred while deleting your avatar', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function useUser() {
|
||||
formData.append('file', file)
|
||||
|
||||
try {
|
||||
await useRequestFetch()('/api/users/avatars', {
|
||||
await $fetch('/api/users/avatars', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
@@ -32,12 +32,29 @@ export async function useUser() {
|
||||
useSuccessToast('Avatar successfully uploaded!')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('An error occurred while uploading your avatar', error as string)
|
||||
useErrorToast('An error occurred while uploading your avatar', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
async function updateUser(user: Partial<UserInsert>) {
|
||||
try {
|
||||
await $fetch('/api/users/me', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(user),
|
||||
})
|
||||
console.log(session.value)
|
||||
await fetch()
|
||||
console.log(session.value)
|
||||
useSuccessToast('User successfully updated!')
|
||||
}
|
||||
catch (error) {
|
||||
useErrorToast('An error occurred while updating your user', String(error))
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
deleteAvatar,
|
||||
uploadAvatar,
|
||||
updateUser,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user