Initial commit: expo-popcore-app
This commit is contained in:
48
hooks/use-activates.ts
Normal file
48
hooks/use-activates.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { loomart } from "@/lib/auth"
|
||||
import { ApiError } from "@/lib/types"
|
||||
import { useState } from "react"
|
||||
export const useActivates = () => {
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [error, setError] = useState<ApiError | null>(null)
|
||||
const [data, setData] = useState<{
|
||||
activities: {
|
||||
title: string;
|
||||
titleEn: string;
|
||||
desc: string;
|
||||
descEn: string;
|
||||
coverUrl: string;
|
||||
link: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
id: string;
|
||||
videoUrl?: string | null | undefined;
|
||||
isActive?: boolean | null | undefined;
|
||||
sortOrder?: number | null | undefined;
|
||||
}[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
totalPages: number;
|
||||
}>()
|
||||
const load = async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const { data, error } = await loomart.activities.list({ isActive: true })
|
||||
console.log({ data, error })
|
||||
if (error) {
|
||||
setError(error)
|
||||
return;
|
||||
}
|
||||
setData(data)
|
||||
} catch (e) {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
load,
|
||||
loading,
|
||||
error,
|
||||
data
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user