The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Smol tweak to consent toast on mobile (#30195)
Joshen Lim7016b9db9089
diff --git a/apps/studio/components/ui/PageTelemetry.tsx b/apps/studio/components/ui/PageTelemetry.tsxindex 662cbd62e02..dbad4b6cfe6 100644--- a/apps/studio/components/ui/PageTelemetry.tsx+++ b/apps/studio/components/ui/PageTelemetry.tsx@@ -1,8 +1,7 @@import { Sha256 } from '@aws-crypto/sha256-browser'import * as Sentry from '@sentry/nextjs'import { useRouter } from 'next/router'-import { PropsWithChildren, useEffect, useRef } from 'react'-import { toast } from 'sonner'+import { PropsWithChildren, useEffect } from 'react'import { useParams, useUser } from 'common'import { useSendGroupsIdentifyMutation } from 'data/telemetry/send-groups-identify-mutation'@@ -13,7 +12,7 @@ import { usePrevious } from 'hooks/deprecated'import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'import { IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'lib/constants'import { useAppStateSnapshot } from 'state/app-state'-import { ConsentToast } from 'ui-patterns/ConsentToast'+import { useConsent } from 'ui-patterns/ConsentToast'const getAnonId = async (id: string) => {const hash = new Sha256()@@ -31,54 +30,21 @@ const PageTelemetry = ({ children }: PropsWithChildren<{}>) => {const snap = useAppStateSnapshot()const organization = useSelectedOrganization()- const consentToastId = useRef<string | number>()+ const { consentValue, hasAcceptedConsent } = useConsent()const previousPathname = usePrevious(router.pathname)- const consentFlag = LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT-- const consent = typeof window !== 'undefined' ? localStorage.getItem(consentFlag) : null- const trackTelemetryPH = consent === 'true'-+ const trackTelemetryPH = consentValue === 'true'const { mutate: sendPage } = useSendPageMutation()const { mutateAsync: sendPageLeave } = useSendPageLeaveMutation()const { mutate: sendGroupsIdentify } = useSendGroupsIdentifyMutation()const { mutate: sendGroupsReset } = useSendGroupsResetMutation()useEffect(() => {- if (typeof window !== 'undefined') {- const onAcceptConsent = () => {- snap.setIsOptedInTelemetry(true)- if (consentToastId.current) toast.dismiss(consentToastId.current)- }-- const onOptOut = () => {- snap.setIsOptedInTelemetry(false)- if (consentToastId.current) toast.dismiss(consentToastId.current)- }-- const hasAcknowledgedConsent = localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT)- snap.setIsOptedInTelemetry(- typeof hasAcknowledgedConsent === 'string'- ? hasAcknowledgedConsent === 'true'- : hasAcknowledgedConsent- )-- if (IS_PLATFORM && hasAcknowledgedConsent === null) {- setTimeout(() => {- consentToastId.current = toast(- <ConsentToast onAccept={onAcceptConsent} onOptOut={onOptOut} />,- {- id: 'consent-toast',- position: 'bottom-right',- duration: Infinity,- }- )- }, 300)- }+ if (consentValue !== null) {+ snap.setIsOptedInTelemetry(hasAcceptedConsent)}-// eslint-disable-next-line react-hooks/exhaustive-deps- }, [])+ }, [consentValue])useEffect(() => {function handleRouteChange() {diff --git a/apps/studio/data/telemetry/send-event-mutation.ts b/apps/studio/data/telemetry/send-event-mutation.tsindex 1fe377f8c4e..893f724a5ec 100644--- a/apps/studio/data/telemetry/send-event-mutation.ts+++ b/apps/studio/data/telemetry/send-event-mutation.ts@@ -1,9 +1,8 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { components } from 'api-types'-import { isBrowser } from 'common'+import { isBrowser, LOCAL_STORAGE_KEYS } from 'common'import { handleError, post } from 'data/fetchers'-import { LOCAL_STORAGE_KEYS } from 'lib/constants'import { useRouter } from 'next/router'import type { ResponseError } from 'types'diff --git a/apps/studio/data/telemetry/send-groups-identify-mutation.ts b/apps/studio/data/telemetry/send-groups-identify-mutation.tsindex 128ecdff8f5..98f636ff34f 100644--- a/apps/studio/data/telemetry/send-groups-identify-mutation.ts+++ b/apps/studio/data/telemetry/send-groups-identify-mutation.ts@@ -1,8 +1,8 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { components } from 'api-types'+import { LOCAL_STORAGE_KEYS } from 'common'import { handleError, post } from 'data/fetchers'-import { LOCAL_STORAGE_KEYS } from 'lib/constants'import type { ResponseError } from 'types'export type SendGroupsIdentifyVariables = components['schemas']['TelemetryGroupsIdentityBody']diff --git a/apps/studio/data/telemetry/send-groups-reset-mutation.ts b/apps/studio/data/telemetry/send-groups-reset-mutation.tsindex 435834fd1e4..586e4b5982b 100644--- a/apps/studio/data/telemetry/send-groups-reset-mutation.ts+++ b/apps/studio/data/telemetry/send-groups-reset-mutation.ts@@ -1,8 +1,8 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { components } from 'api-types'+import { LOCAL_STORAGE_KEYS } from 'common'import { handleError, post } from 'data/fetchers'-import { LOCAL_STORAGE_KEYS } from 'lib/constants'import type { ResponseError } from 'types'export type SendGroupsResetVariables = components['schemas']['TelemetryGroupsResetBody']diff --git a/apps/studio/data/telemetry/send-identify-mutation.ts b/apps/studio/data/telemetry/send-identify-mutation.tsindex 733f7ac4f60..640ddf51b45 100644--- a/apps/studio/data/telemetry/send-identify-mutation.ts+++ b/apps/studio/data/telemetry/send-identify-mutation.ts@@ -1,9 +1,9 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { components } from 'api-types'+import { LOCAL_STORAGE_KEYS } from 'common'import { handleError, post } from 'data/fetchers'import { Profile } from 'data/profile/types'-import { LOCAL_STORAGE_KEYS } from 'lib/constants'import type { ResponseError } from 'types'type SendIdentify = components['schemas']['TelemetryIdentifyBodyV2']diff --git a/apps/studio/data/telemetry/send-page-leave-mutation.ts b/apps/studio/data/telemetry/send-page-leave-mutation.tsindex 366931b13bd..d813dff1c2e 100644--- a/apps/studio/data/telemetry/send-page-leave-mutation.ts+++ b/apps/studio/data/telemetry/send-page-leave-mutation.ts@@ -1,8 +1,8 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { components } from 'api-types'+import { LOCAL_STORAGE_KEYS } from 'common'import { handleError, post } from 'data/fetchers'-import { LOCAL_STORAGE_KEYS } from 'lib/constants'import { useRouter } from 'next/router'import type { ResponseError } from 'types'diff --git a/apps/studio/data/telemetry/send-page-mutation.ts b/apps/studio/data/telemetry/send-page-mutation.tsindex ad32f1b6336..d85e13fb6f6 100644--- a/apps/studio/data/telemetry/send-page-mutation.ts+++ b/apps/studio/data/telemetry/send-page-mutation.ts@@ -1,9 +1,8 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { components } from 'api-types'-import { isBrowser } from 'common'+import { isBrowser, LOCAL_STORAGE_KEYS } from 'common'import { handleError, post } from 'data/fetchers'-import { LOCAL_STORAGE_KEYS } from 'lib/constants'import { useRouter } from 'next/router'import type { ResponseError } from 'types'diff --git a/apps/studio/lib/constants/index.ts b/apps/studio/lib/constants/index.tsindex 15a3cb2af51..1004802f502 100644--- a/apps/studio/lib/constants/index.ts+++ b/apps/studio/lib/constants/index.ts@@ -29,7 +29,6 @@ export const USAGE_APPROACHING_THRESHOLD = 0.75export const LOCAL_STORAGE_KEYS = {RECENTLY_VISITED_ORGANIZATION: 'supabase-organization',- TELEMETRY_CONSENT: 'supabase-consent-ph',UI_PREVIEW_NAVIGATION_LAYOUT: 'supabase-ui-preview-nav-layout',UI_PREVIEW_API_SIDE_PANEL: 'supabase-ui-api-side-panel',diff --git a/apps/studio/lib/local-storage.ts b/apps/studio/lib/local-storage.tsindex 0e9f0d8d477..21829ad0ce0 100644--- a/apps/studio/lib/local-storage.ts+++ b/apps/studio/lib/local-storage.ts@@ -1,4 +1,5 @@import { LOCAL_STORAGE_KEYS } from 'lib/constants'+import { LOCAL_STORAGE_KEYS as COMMON_LOCAL_STORAGE_KEYS } from 'common'const LOCAL_STORAGE_KEYS_ALLOWLIST = ['graphiql:theme',@@ -6,7 +7,7 @@ const LOCAL_STORAGE_KEYS_ALLOWLIST = ['supabaseDarkMode','supabase.dashboard.auth.debug','supabase.dashboard.auth.navigatorLock.disabled',- LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT,+ COMMON_LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT,LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL,LOCAL_STORAGE_KEYS.UI_PREVIEW_NAVIGATION_LAYOUT,LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,diff --git a/apps/studio/pages/_app.tsx b/apps/studio/pages/_app.tsxindex 63fa4d1a825..e8faca7e842 100644--- a/apps/studio/pages/_app.tsx+++ b/apps/studio/pages/_app.tsx@@ -106,6 +106,14 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {[supabase])+ const TelemetryContainer = useMemo(+ // eslint-disable-next-line react/display-name+ () => (props: any) => {+ return IS_PLATFORM ? <PageTelemetry>{props.children}</PageTelemetry> : <>{props.children}</>+ },+ []+ )+const errorBoundaryHandler = (error: Error, info: ErrorInfo) => {Sentry.withScope(function (scope) {scope.setTag('globalErrorBoundary', true)@@ -131,7 +139,7 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {<meta name="viewport" content="initial-scale=1.0, width=device-width" /></Head><MetaFaviconsPagesRouter applicationName="Supabase Studio" />- <PageTelemetry>+ <TelemetryContainer><TooltipProvider><RouteValidationWrapper><ThemeProvider@@ -157,7 +165,7 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {</ThemeProvider></RouteValidationWrapper></TooltipProvider>- </PageTelemetry>+ </TelemetryContainer>{!isTestEnv && <HCaptchaLoadedStore />}{!isTestEnv && <ReactQueryDevtools initialIsOpen={false} position="bottom-right" />}diff --git a/apps/studio/state/app-state.ts b/apps/studio/state/app-state.tsindex 9a8b06eecc4..71f10820099 100644--- a/apps/studio/state/app-state.ts+++ b/apps/studio/state/app-state.ts@@ -1,6 +1,8 @@+import { proxy, snapshot, useSnapshot } from 'valtio'+import { SupportedAssistantEntities } from 'components/ui/AIAssistantPanel/AIAssistant.types'import { LOCAL_STORAGE_KEYS } from 'lib/constants'-import { proxy, snapshot, useSnapshot } from 'valtio'+import { LOCAL_STORAGE_KEYS as COMMON_LOCAL_STORAGE_KEYS } from 'common'const EMPTY_DASHBOARD_HISTORY: {sql?: string@@ -56,7 +58,7 @@ export const appState = proxy({setIsOptedInTelemetry: (value: boolean | null) => {appState.isOptedInTelemetry = value === null ? false : valueif (typeof window !== 'undefined' && value !== null) {- localStorage.setItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT, value.toString())+ localStorage.setItem(COMMON_LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT, value.toString())}},showEnableBranchingModal: false,diff --git a/packages/ui-patterns/ConsentToast/index.tsx b/packages/ui-patterns/ConsentToast/index.tsxindex f20ed262bfe..502c9146758 100644--- a/packages/ui-patterns/ConsentToast/index.tsx+++ b/packages/ui-patterns/ConsentToast/index.tsx@@ -30,15 +30,27 @@ export const ConsentToast = ({ onAccept = noop, onOptOut = noop }: ConsentToastPtarget="_blank"rel="noreferrer noopener"href="https://supabase.com/privacy#8-cookies-and-similar-technologies-used-on-our-european-services"- className="underline underline-offset-2 decoration-foreground-lighter hover:decoration-foreground-light transition-all"+ className="hidden sm:inline underline underline-offset-2 decoration-foreground-lighter hover:decoration-foreground-light transition-all">Learn more</a>{' '}- <PrivacySettings className="inline sm:hidden underline text-light">+ </p>+ <div className="flex items-center justify-start gap-x-2 sm:hidden">+ <a+ target="_blank"+ rel="noreferrer noopener"+ href="https://supabase.com/privacy#8-cookies-and-similar-technologies-used-on-our-european-services"+ className="underline underline-offset-2 text-foreground-light hover:decoration-foreground-light transition-all"+ >+ Learn more+ </a>+ <span className="text-foreground-lighter text-xs">•</span>+ <PrivacySettings className="underline underline-offset-2 inline text-light">Privacy settings</PrivacySettings>- </p>+ </div></div>+<div className="flex items-center space-x-2"><Buttontype="default"