Skip to content

Commit

Permalink
Fix loading issue on first signin
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Oct 9, 2024
1 parent d123b1f commit 0d56531
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
21 changes: 6 additions & 15 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useSearchParams, redirect } from 'next/navigation'
import { useSession } from 'next-auth/react'
import { useEffect, useMemo } from 'react'
import posthog from 'posthog-js'
import { Center, Spinner } from '@chakra-ui/react'
import { driver } from 'driver.js'
import 'driver.js/dist/driver.css'

Expand Down Expand Up @@ -71,13 +70,13 @@ export default function AdminPage() {
const { data: session } = useSession()
const { selectedWebId } = useAppContext()
const isOwnerOfCurrentWeb = useIsOwnerOfCurrentWeb()
const { allowedWebs, isLoadingWebs } = useAllowedWebs()
const { listings, isPending: isListingsPending } = useListings()
const { permissions, isPending: isPermissionsPending } = usePermissions()
const { allowedWebs } = useAllowedWebs()
const { listings, isPending: isLoadingListings } = useListings()
const { permissions, isPending: isLoadingPermissions } = usePermissions()
const { mutate: deleteListing } = useDeleteListing()

const allowedListings = useMemo(() => {
if (isPermissionsPending || isListingsPending) return null
if (isLoadingListings || isLoadingPermissions) return null
if (isOwnerOfCurrentWeb || session.user.admin) return listings

if (permissions?.webIds?.includes(selectedWebId)) return listings
Expand All @@ -87,8 +86,8 @@ export default function AdminPage() {
})
}, [
session,
isPermissionsPending,
isListingsPending,
isLoadingPermissions,
isLoadingListings,
isOwnerOfCurrentWeb,
listings,
permissions?.webIds,
Expand Down Expand Up @@ -119,14 +118,6 @@ export default function AdminPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [firstTime])

if (isLoadingWebs || allowedListings === null) {
return (
<Center height="50vh">
<Spinner size="xl" />
</Center>
)
}

if (allowedWebs.length === 0) {
redirect('/admin/welcome')
}
Expand Down
4 changes: 3 additions & 1 deletion prisma/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PrismaClient } from '@prisma/client'

const prisma = global.prisma || new PrismaClient()
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }

const prisma = globalForPrisma.prisma || new PrismaClient()

if (process.env.NODE_ENV === 'development') {
global.prisma = prisma
Expand Down

0 comments on commit 0d56531

Please sign in to comment.