mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 12:14:33 +01:00
working
This commit is contained in:
@@ -4,7 +4,7 @@ export async function useCategories() {
|
||||
const { data: categories, refresh }
|
||||
= await useAsyncData<CategoryType[]>(async () => await useRequestFetch()('/api/categories'))
|
||||
|
||||
async function getCategory(id: number) {
|
||||
async function getCategory(id: number): CategoryType {
|
||||
return categories.data.value.find(category => category.id === id)
|
||||
}
|
||||
|
||||
|
||||
18
app/composables/icons.ts
Normal file
18
app/composables/icons.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export function useIcons() {
|
||||
const loading = ref(false)
|
||||
async function search(query: string) {
|
||||
if (query) {
|
||||
loading.value = true
|
||||
}
|
||||
const response = await $fetch('/api/icons/search', {
|
||||
query: { query },
|
||||
})
|
||||
loading.value = false
|
||||
return response.icons
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
search,
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CreateTabSchema, TabType, UpdateTabSchema } from '~~/types/types'
|
||||
import type { CreateTabSchema, type TabType, UpdateTabSchema } from '~~/types/types'
|
||||
|
||||
export async function useTabs() {
|
||||
const { data: tabs, refresh }
|
||||
@@ -32,6 +32,21 @@ export async function useTabs() {
|
||||
.catch(error => useErrorToast('Tab update failed!', `Error: ${error}`))
|
||||
}
|
||||
|
||||
async function setTabPrimary(tab, primary: boolean) {
|
||||
await $fetch(`/api/tabs/${tab.id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
primary,
|
||||
categoryId: tab.categoryId,
|
||||
}),
|
||||
})
|
||||
.then(async () => {
|
||||
await refresh()
|
||||
useSuccessToast('Tab favorite toggled with success!')
|
||||
})
|
||||
.catch(error => useErrorToast('Cannot toggle Tab favorite!', `Error: ${error}`))
|
||||
}
|
||||
|
||||
async function deleteTab(id: number) {
|
||||
await $fetch(`/api/tabs/${id}`, {
|
||||
method: 'DELETE',
|
||||
@@ -47,5 +62,6 @@ export async function useTabs() {
|
||||
deleteTab,
|
||||
getTabsForCategory,
|
||||
updateTab,
|
||||
setTabPrimary,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
export function useUserLimit() {
|
||||
function hasUserFreePlan() {
|
||||
return true
|
||||
export async function useUserLimit() {
|
||||
const { user } = useUserSession()
|
||||
const { categories } = await useCategories()
|
||||
const { tabs } = await useTabs()
|
||||
|
||||
const hasPaidPlan = computed(() => user.value.subscription !== 'free')
|
||||
|
||||
function canCreateCategory() {
|
||||
if (hasPaidPlan.value)
|
||||
return true
|
||||
return categories.value.length < 3
|
||||
}
|
||||
|
||||
function getRemainingCategories() {
|
||||
if (!hasUserFreePlan())
|
||||
return -1
|
||||
return 3
|
||||
}
|
||||
|
||||
function getRemainingTabs(category_id: number) {
|
||||
if (!hasUserFreePlan())
|
||||
return -1
|
||||
return category_id * 3
|
||||
function canCreateTabInCategory(categoryId: number): boolean {
|
||||
if (hasPaidPlan.value)
|
||||
return true
|
||||
return tabs.filter(tab => tab.categoryId === categoryId).length < 5
|
||||
}
|
||||
|
||||
return {
|
||||
getRemainingCategories,
|
||||
getRemainingTabs,
|
||||
hasPaidPlan,
|
||||
userLimits,
|
||||
canCreateCategory,
|
||||
canCreateTabInCategory,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user