mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 23:19:23 +08:00
There were two bugs when trying to run the integrations page locally with NEXT_PUBLIC_IS_PLATFORM=false: 1. The IS_PLATFORM check imported from common was not evaluating correctly to a boolean. This is because I slapped a 'use client' on the entire common package last year -_-""" which caused all its imports to be evaluated to functions when used in server components. I have now moved the 'use client's down to the submodules that actually need it. 2. When the integrations submenu is empty, the navigation menu errors out because it expects all navigation items to either have children or have links. Have updated this to gracefully hide empty headers.
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
'use client'
|
|
|
|
import { useSyncExternalStore } from 'react'
|
|
import type * as React from 'react'
|
|
|
|
export const detectBrowser = () => {
|
|
if (!navigator) return undefined
|
|
|
|
if (navigator.userAgent.indexOf('Chrome') !== -1) {
|
|
return 'Chrome'
|
|
} else if (navigator.userAgent.indexOf('Firefox') !== -1) {
|
|
return 'Firefox'
|
|
} else if (navigator.userAgent.indexOf('Safari') !== -1) {
|
|
return 'Safari'
|
|
}
|
|
}
|
|
|
|
export const isBrowser = typeof window !== 'undefined'
|
|
|
|
const prefersReducedMotionMediaQuery =
|
|
isBrowser && window.matchMedia('(prefers-reduced-motion: reduce)')
|
|
|
|
/**
|
|
* @returns boolean value If the user has expressed their preference for reduced motion.
|
|
*/
|
|
export const useReducedMotion = (): boolean => {
|
|
if (!prefersReducedMotionMediaQuery) return false
|
|
return useSyncExternalStore(
|
|
(callback) => {
|
|
prefersReducedMotionMediaQuery.addEventListener('change', callback)
|
|
return () => {
|
|
prefersReducedMotionMediaQuery.removeEventListener('change', callback)
|
|
}
|
|
},
|
|
() => prefersReducedMotionMediaQuery.matches,
|
|
() => false
|
|
)
|
|
}
|
|
|
|
export function ensurePlatformSuffix(apiUrl: string) {
|
|
return apiUrl.endsWith('/platform') ? apiUrl : `${apiUrl}/platform`
|
|
}
|
|
|
|
export function mergeRefs<T>(...refs: React.Ref<T>[]): React.RefCallback<T> {
|
|
return (value) => {
|
|
refs.forEach((ref) => {
|
|
if (typeof ref === 'function') {
|
|
ref(value)
|
|
} else if (ref !== null) {
|
|
if (typeof ref === 'object' && ref !== null && 'current' in ref) {
|
|
;(ref as any).current = value
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|