-
-
Save codeagencybe/f49a4aeaa09d865fcd29452870ad8591 to your computer and use it in GitHub Desktop.
useUpload.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getSupabaseBrowserClient } from "@midday/supabase/browser-client"; | |
import { getUserDetails } from "@midday/supabase/queries"; | |
import { upload } from "@midday/supabase/storage"; | |
import { useState } from "react"; | |
export function useUpload() { | |
const supabase = getSupabaseBrowserClient(); | |
const [isLoading, setLoading] = useState(false); | |
const uploadFile = async ({ bucketName, file, path }) => { | |
setLoading(true); | |
const { data: userData } = await getUserDetails(supabase); | |
const basePath = `${bucketName}/${userData?.team_id}/${path}`; | |
const filePath = `${userData?.team_id}/${path}/${file.name}`; | |
const url = await upload(supabase, { | |
path: basePath, | |
file, | |
}); | |
setLoading(false); | |
return { | |
url, | |
path: filePath, | |
}; | |
}; | |
return { | |
uploadFile, | |
isLoading, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment