Skip to content

Commit

Permalink
fix(database): loader bar broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed May 1, 2022
1 parent 73b7144 commit 2df3607
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions packages/better-write-app/src/use/storage/supabase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useAbsoluteStore } from '@/store/absolute'
import { useAuthStore } from '@/store/auth'
import { createClient } from '@supabase/supabase-js'
import { useNProgress } from '@vueuse/integrations/useNProgress'
import {
ProjectObject,
Maybe,
Expand All @@ -27,7 +26,6 @@ export const useSupabase = () => {
const ABSOLUTE = useAbsoluteStore()
const AUTH = useAuthStore()

const { isLoading } = useNProgress()
const toast = useToast()
const { t } = useI18n()
const env = useEnv()
Expand All @@ -43,8 +41,6 @@ export const useSupabase = () => {
notification: boolean = true
) => {
return new Promise((res) => {
isLoading.value = true

s.auth
.signIn(
{
Expand All @@ -65,18 +61,14 @@ export const useSupabase = () => {
.catch(() => {
res(404)
})
.finally(() => {
isLoading.value = false
})
.finally(() => {})
})
}

const login = (
provider: SupabaseIntegrations,
notification: boolean = true
) => {
isLoading.value = true

s.auth
.signIn({ provider }, { redirectTo: env.getCorrectLocalUrl() })
.then(async ({ error }) => {
Expand All @@ -88,30 +80,23 @@ export const useSupabase = () => {
if (notification) toast(t('editor.auth.login.error'))
})
.finally(() => {
isLoading.value = false
ABSOLUTE.auth.supabase = false
})
}

const out = () => {
isLoading.value = true

s.auth
.signOut()
.then(() => {
AUTH.account.user = null

router.push('/')
})
.finally(() => {
isLoading.value = false
})
.finally(() => {})
}

const getProjects = async (): Promise<Maybe<ProjectObject[]>> => {
try {
isLoading.value = true

const {
data: projects,
error,
Expand All @@ -130,13 +115,10 @@ export const useSupabase = () => {
} catch (error: any) {
toast.error(error.message)
} finally {
isLoading.value = false
}
}

const saveProject = async () => {
isLoading.value = true

const { data, error } = await s.from('projects').upsert(
{
// @ts-ignore
Expand All @@ -146,8 +128,6 @@ export const useSupabase = () => {
{ onConflict: 'id' }
)

isLoading.value = false

if (error) {
toast.error(error.message)

Expand Down Expand Up @@ -181,15 +161,11 @@ export const useSupabase = () => {
const deleteProject = async (context: ProjectObject) => {
if (!confirm(t('toast.project.deleteAlert'))) return

isLoading.value = true

const { error } = await s
.from('projects')
.delete({ returning: 'minimal' })
.match({ id: context.id })

isLoading.value = false

if (error) {
toast.error(error.message)

Expand All @@ -202,14 +178,10 @@ export const useSupabase = () => {
const loadProject = async (context: ProjectObject) => {
AUTH.account.project_id_activity = context.id || null

isLoading.value = true

storage.normalize().then(() => {
project.onLoadProject(context, false).then(() => {
local.onSaveProject(false).then(() => {
router.push('/editor').finally(() => {
isLoading.value = false
})
router.push('/editor').finally(() => {})
})
})
})
Expand Down

0 comments on commit 2df3607

Please sign in to comment.