The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Refactor themeing logic for dashboard to use useTheme from common, and fix theme changing via cmdk for dashboard
Joshen Lim145a9c857d2a
diff --git a/packages/common/Providers.tsx b/packages/common/Providers.tsxindex 1e27eb0f948..72da69f37c8 100644--- a/packages/common/Providers.tsx+++ b/packages/common/Providers.tsx@@ -37,10 +37,13 @@ export const ThemeProvider = ({ children }: ThemeProviderProps) => {const toggleTheme: UseThemeProps['toggleTheme'] = (darkMode) => {const newMode = typeof darkMode === 'boolean' ? darkMode : !isDarkMode-localStorage.setItem('supabaseDarkMode', newMode.toString())const key = localStorage.getItem('supabaseDarkMode')+ const newTheme = key === 'true' ? 'dark' : 'light'+ const currentTheme = isDarkMode ? 'dark' : 'light'++ document.body.classList.replace(currentTheme, newTheme)document.documentElement.className = key === 'true' ? 'dark' : ''setIsDarkMode(newMode)diff --git a/studio/components/interfaces/Database/Wrappers/WrappersDisabledState.tsx b/studio/components/interfaces/Database/Wrappers/WrappersDisabledState.tsxindex 014c060780f..a93c531cbdd 100644--- a/studio/components/interfaces/Database/Wrappers/WrappersDisabledState.tsx+++ b/studio/components/interfaces/Database/Wrappers/WrappersDisabledState.tsx@@ -8,10 +8,12 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'import { checkPermissions, useStore } from 'hooks'import { useParams } from 'common/hooks'import { BASE_PATH } from 'lib/constants'+import { useTheme } from 'common'const WrappersDisabledState = () => {const { ui, meta } = useStore()const { ref } = useParams()+ const { isDarkMode } = useTheme()const wrappersExtension = meta.extensions.byId('wrappers')const vaultExtension = meta.extensions.byId('supabase_vault')const isNotAvailable = wrappersExtension === undefined || vaultExtension === undefined@@ -66,7 +68,7 @@ const WrappersDisabledState = () => {style={{backgroundSize: '45%',backgroundPosition: '105% 40%',- backgroundImage: ui.isDarkTheme+ backgroundImage: isDarkMode? `url("${BASE_PATH}/img/wrappers-dark.png")`: `url("${BASE_PATH}/img/wrappers-light.png")`,}}diff --git a/studio/components/interfaces/Home/ExampleProject.tsx b/studio/components/interfaces/Home/ExampleProject.tsxindex 32f76b8bfaf..94be8f388d4 100644--- a/studio/components/interfaces/Home/ExampleProject.tsx+++ b/studio/components/interfaces/Home/ExampleProject.tsx@@ -1,6 +1,5 @@import { FC } from 'react'-import { IconChevronRight } from 'ui'-import { useStore } from 'hooks'+import { IconChevronRight, useTheme } from 'ui'import Link from 'next/link'import { BASE_PATH } from 'lib/constants'@@ -12,8 +11,7 @@ interface Props {}const ExampleProject: FC<Props> = ({ framework, title, description, url }) => {- const { ui } = useStore()- const { isDarkTheme } = ui+ const { isDarkMode } = useTheme()return (<Link href={url}>@@ -32,7 +30,7 @@ const ExampleProject: FC<Props> = ({ framework, title, description, url }) => {className="transition-all group-hover:scale-110"src={`${BASE_PATH}/img/libraries/${framework.toLowerCase()}${['expo', 'nextjs'].includes(framework.toLowerCase())- ? isDarkTheme+ ? isDarkMode? '-dark': '': ''diff --git a/studio/components/interfaces/Settings/Vault/VaultToggle.tsx b/studio/components/interfaces/Settings/Vault/VaultToggle.tsxindex 510e6d66e70..192e88dd02c 100644--- a/studio/components/interfaces/Settings/Vault/VaultToggle.tsx+++ b/studio/components/interfaces/Settings/Vault/VaultToggle.tsx@@ -8,12 +8,14 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'import { checkPermissions, useStore } from 'hooks'import { useParams } from 'common/hooks'import { BASE_PATH } from 'lib/constants'+import { useTheme } from 'common'interface Props {}const VaultToggle: FC<Props> = () => {const { meta, ui } = useStore()const { ref } = useParams()+ const { isDarkMode } = useTheme()const [isEnabling, setIsEnabling] = useState(false)const canToggleVault = checkPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'extensions')@@ -64,7 +66,7 @@ const VaultToggle: FC<Props> = () => {style={{backgroundSize: isNotAvailable ? '50%' : '40%',backgroundPosition: '100% 24%',- backgroundImage: ui.isDarkTheme+ backgroundImage: isDarkMode? `url("${BASE_PATH}/img/vault-dark.png")`: `url("${BASE_PATH}/img/vault-light.png")`,}}diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsxindex 87ab1f2c8db..7ca0765a00a 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/JsonEditor/JsonCodeEditor.tsx@@ -1,5 +1,6 @@import Editor, { useMonaco } from '@monaco-editor/react'-import { FC, useEffect, useRef, useState } from 'react'+import { useTheme } from 'common'+import { FC, useEffect, useRef } from 'react'interface Props {queryId?: string@@ -16,31 +17,29 @@ const JsonEditor: FC<Props> = ({}) => {const monaco = useMonaco()const editorRef = useRef()- const [theme, setTheme] = useState(localStorage.getItem('theme'))+ const { isDarkMode } = useTheme()useEffect(() => {if (monaco) {- const darkTheme = theme ? (theme === 'dark' ? true : false) : true-// Supabase theming (Can't seem to get it to work for now)monaco.editor.defineTheme('supabase', {base: 'vs-dark', // can also be vs-dark or hc-blackinherit: true, // can also be false to completely replace the builtin rulesrules: [// @ts-ignore- { background: darkTheme ? '1f1f1f' : '30313f' },+ { background: isDarkMode ? '1f1f1f' : '30313f' },{ token: 'string.sql', foreground: '24b47e' },{ token: 'comment', foreground: '666666' },{ token: 'predefined.sql', foreground: 'D4D4D4' },],colors: {- 'editor.background': darkTheme ? '#1f1f1f' : '#30313f',+ 'editor.background': isDarkMode ? '#1f1f1f' : '#30313f',// 'editorGutter.background': '#30313f',// 'editorLineNumber.foreground': '#555671',},})}- }, [theme, monaco])+ }, [isDarkMode, monaco])const onMount = (editor: any, monaco: any) => {editorRef.current = editordiff --git a/studio/components/interfaces/TableGridEditor/ViewDefinition.tsx b/studio/components/interfaces/TableGridEditor/ViewDefinition.tsxindex 6df9807aa53..e9269cc423f 100644--- a/studio/components/interfaces/TableGridEditor/ViewDefinition.tsx+++ b/studio/components/interfaces/TableGridEditor/ViewDefinition.tsx@@ -1,10 +1,10 @@import { useRef } from 'react'import Editor from '@monaco-editor/react'import { timeout } from 'lib/helpers'-import { useStore } from 'hooks'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import { useViewDefinitionQuery } from 'data/database/view-definition-query'import ShimmeringLoader from 'components/ui/ShimmeringLoader'+import { useTheme } from 'common'export interface ViewDefinitionProps {name: string@@ -14,8 +14,7 @@ const ViewDefinition = ({ name }: ViewDefinitionProps) => {const editorRef = useRef(null)const monacoRef = useRef(null)- const { ui } = useStore()- const { isDarkTheme } = ui+ const { isDarkMode } = useTheme()const { project } = useProjectContext()const { data: definition, isLoading } = useViewDefinitionQuery({@@ -56,7 +55,7 @@ const ViewDefinition = ({ name }: ViewDefinitionProps) => {<div className="flex-grow overflow-y-auto border-t border-scale-400"><EditorclassName="monaco-editor"- theme={isDarkTheme ? 'vs-dark' : 'vs'}+ theme={isDarkMode ? 'vs-dark' : 'vs'}onMount={handleEditorOnMount}defaultLanguage="pgsql"defaultValue={definition}diff --git a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsxindex 3d534b80502..4c5de0c7e4d 100644--- a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx+++ b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx@@ -14,15 +14,17 @@ import {} from './NavigationBar.utils'import NavigationIconButton from './NavigationIconButton'import { useParams } from 'common/hooks'+import { useTheme } from 'common'interface Props {}const NavigationBar: FC<Props> = ({}) => {const router = useRouter()- const { ref: projectRef } = useParams()const { ui } = useStore()- const projectBaseInfo = ui.selectedProjectBaseInfo+ const { isDarkMode, toggleTheme } = useTheme()+ const { ref: projectRef } = useParams()+ const projectBaseInfo = ui.selectedProjectBaseInfoconst ongoingIncident = useFlag('ongoingIncident')const activeRoute = router.pathname.split('/')[3]@@ -102,10 +104,11 @@ const NavigationBar: FC<Props> = ({}) => {<Dropdown.Label>Theme</Dropdown.Label><Dropdown.RadioGroupkey="theme"- value={ui.themeOption}- onChange={(e: any) => ui.onThemeOptionChange(e)}+ value={isDarkMode ? 'dark' : 'light'}+ onChange={(e: any) => toggleTheme(e === 'dark')}>- <Dropdown.Radio value="system">System default</Dropdown.Radio>+ {/* [Joshen] Removing system default for now, needs to be supported in useTheme from common packages */}+ {/* <Dropdown.Radio value="system">System default</Dropdown.Radio> */}<Dropdown.Radio value="dark">Dark</Dropdown.Radio><Dropdown.Radio value="light">Light</Dropdown.Radio></Dropdown.RadioGroup>diff --git a/studio/components/to-be-cleaned/Docs/Pages/Introduction.tsx b/studio/components/to-be-cleaned/Docs/Pages/Introduction.tsxindex 091bba0e6e4..1385f70b9bd 100644--- a/studio/components/to-be-cleaned/Docs/Pages/Introduction.tsx+++ b/studio/components/to-be-cleaned/Docs/Pages/Introduction.tsx@@ -1,9 +1,9 @@import Image from 'next/image'import { AutoApiService } from 'data/config/project-api-query'-import { useStore } from 'hooks'import { BASE_PATH } from 'lib/constants'import Snippets from '../Snippets'import CodeSnippet from '../CodeSnippet'+import { useTheme } from 'common'const libs = [{@@ -26,8 +26,7 @@ interface Props {}export default function Introduction({ autoApiService, selectedLang }: Props) {- const { ui } = useStore()- const { isDarkTheme } = ui+ const { isDarkMode } = useTheme()return (<>@@ -66,7 +65,7 @@ export default function Introduction({ autoApiService, selectedLang }: Props) {><Imagesrc={`${BASE_PATH}/img/icons/reference-${- isDarkTheme ? lib.icon : `${lib.icon}-light`+ isDarkMode ? lib.icon : `${lib.icon}-light`}.svg`}width={16}height={16}diff --git a/studio/hooks/misc/useStore.tsx b/studio/hooks/misc/useStore.tsxindex a998f78d3d1..0c7072a0381 100644--- a/studio/hooks/misc/useStore.tsx+++ b/studio/hooks/misc/useStore.tsx@@ -1,11 +1,12 @@import { useMonaco } from '@monaco-editor/react'import { autorun } from 'mobx'-import { createContext, FC, useContext, useEffect, useCallback } from 'react'+import { createContext, FC, useContext, useEffect } from 'react'import toast from 'react-hot-toast'import { IRootStore } from 'stores'import { getTheme } from 'components/ui/CodeEditor'import SparkBar from 'components/ui/SparkBar'+import { useTheme } from 'common'const StoreContext = createContext<IRootStore>(undefined!)@@ -24,29 +25,18 @@ interface StoreProvider {export const StoreProvider: FC<StoreProvider> = ({ children, rootStore }) => {const monaco = useMonaco()const { ui } = rootStore- const { theme } = ui+ const { isDarkMode } = useTheme()useEffect(() => {if (monaco) {- const theme: any = getTheme(ui.isDarkTheme)+ const theme: any = getTheme(isDarkMode)monaco.editor.defineTheme('supabase', theme)}- }, [theme, monaco])-- const matchMediaEvent = useCallback(() => {- ui.themeOption === 'system' &&- ui.setTheme(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')- }, [])+ }, [isDarkMode, monaco])useEffect(() => {ui.load()- if (window?.matchMedia('(prefers-color-scheme: dark)')?.addEventListener) {- // backwards compatibility for safari < v14- // limited support for addEventListener()- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', matchMediaEvent)- }-autorun(() => {if (ui.notification) {const { id, category, error, message, description, progress, duration } = ui.notification@@ -100,11 +90,6 @@ export const StoreProvider: FC<StoreProvider> = ({ children, rootStore }) => {})}-- return () =>- window- .matchMedia('(prefers-color-scheme: dark)')- .removeEventListener('change', matchMediaEvent)}, [])return <StoreContext.Provider value={rootStore}>{children}</StoreContext.Provider>diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsxindex 1f980b652b3..db8552f921b 100644--- a/studio/pages/_app.tsx+++ b/studio/pages/_app.tsx@@ -25,7 +25,7 @@ import Head from 'next/head'import Script from 'next/script'import { AppPropsWithLayout } from 'types'-+import { ThemeProvider } from 'common'import { useEffect, useState } from 'react'import { Hydrate, QueryClientProvider } from '@tanstack/react-query'import { ReactQueryDevtools } from '@tanstack/react-query-devtools'@@ -145,9 +145,13 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {<PageTelemetry><TooltipProvider><RouteValidationWrapper>- <CommandMenuWrapper>- <AppBannerWrapper>{getLayout(<Component {...pageProps} />)}</AppBannerWrapper>- </CommandMenuWrapper>+ <ThemeProvider>+ <CommandMenuWrapper>+ <AppBannerWrapper>+ {getLayout(<Component {...pageProps} />)}+ </AppBannerWrapper>+ </CommandMenuWrapper>+ </ThemeProvider></RouteValidationWrapper></TooltipProvider></PageTelemetry>diff --git a/studio/pages/account/me.tsx b/studio/pages/account/me.tsxindex 6c00e76aa4e..987dc33bfe6 100644--- a/studio/pages/account/me.tsx+++ b/studio/pages/account/me.tsx@@ -10,6 +10,7 @@ import { useStore } from 'hooks'import { useSession } from 'lib/auth'import Link from 'next/link'import { NextPageWithLayout } from 'types'+import { useTheme } from 'common'const User: NextPageWithLayout = () => {return (@@ -142,29 +143,24 @@ const Profile = ({ profile }: { profile?: ProfileType }) => {}const ThemeSettings = observer(() => {- const { ui } = useStore()+ const { isDarkMode, toggleTheme } = useTheme()return (<Panel title={<h5 key="panel-title">Theme</h5>}><Panel.Content><Listbox- value={ui.themeOption}+ value={isDarkMode ? 'dark' : 'light'}label="Interface theme"descriptionText="Choose a theme preference"layout="horizontal"style={{ width: '50%' }}- icon={- ui.themeOption === 'light' ? (- <IconSun />- ) : ui.themeOption === 'dark' ? (- <IconMoon />- ) : undefined- }- onChange={(themeOption: any) => ui.onThemeOptionChange(themeOption)}+ icon={isDarkMode ? <IconMoon /> : <IconSun />}+ onChange={(themeOption: any) => toggleTheme(themeOption === 'dark')}>- <Listbox.Option label="System default" value="system">+ {/* [Joshen] Removing system default for now, needs to be supported in useTheme from common packages */}+ {/* <Listbox.Option label="System default" value="system">System default- </Listbox.Option>+ </Listbox.Option> */}<Listbox.Option label="Dark" value="dark">Dark</Listbox.Option>diff --git a/studio/pages/project/[ref]/api/graphiql.tsx b/studio/pages/project/[ref]/api/graphiql.tsxindex a719540f4c8..95492f7a2d1 100644--- a/studio/pages/project/[ref]/api/graphiql.tsx+++ b/studio/pages/project/[ref]/api/graphiql.tsx@@ -12,10 +12,13 @@ import { DocsLayout } from 'components/layouts'import Connecting from 'components/ui/Loading/Loading'import { useSessionAccessTokenQuery } from 'data/auth/session-access-token-query'import { useProjectApiQuery } from 'data/config/project-api-query'+import { useTheme } from 'common'const GraphiQLPage: NextPageWithLayout = () => {const { ref: projectRef } = useParams()const { ui, meta } = useStore()+ const { isDarkMode } = useTheme()+ const theme = isDarkMode ? 'dark' : 'light'const isExtensionsLoading = meta.extensions.isLoadingconst pgGraphqlExtension = meta.extensions.byId('pg_graphql')@@ -77,7 +80,7 @@ const GraphiQLPage: NextPageWithLayout = () => {)}- return <GraphiQL fetcher={fetcher} theme={ui.theme} accessToken={anonKey} />+ return <GraphiQL fetcher={fetcher} theme={theme} accessToken={anonKey} />}GraphiQLPage.getLayout = (page) => <DocsLayout title="GraphiQL">{page}</DocsLayout>diff --git a/studio/pages/project/[ref]/editor/[id].tsx b/studio/pages/project/[ref]/editor/[id].tsxindex f9c3996736a..b07d2a557da 100644--- a/studio/pages/project/[ref]/editor/[id].tsx+++ b/studio/pages/project/[ref]/editor/[id].tsx@@ -19,9 +19,11 @@ import { NextPageWithLayout, SchemaView } from 'types'import { JsonEditValue } from 'components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.types'import { ProjectContextFromParamsProvider } from 'components/layouts/ProjectLayout/ProjectContext'import { ForeignRowSelectorProps } from 'components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector'+import { useTheme } from 'common'const TableEditorPage: NextPageWithLayout = () => {const router = useRouter()+ const { isDarkMode } = useTheme()const { id, ref: projectRef } = useParams()const [_, setParams] = useUrlState({ arrayKeys: ['filter', 'sort'] })@@ -259,7 +261,7 @@ const TableEditorPage: NextPageWithLayout = () => {onExpandJSONEditor={onExpandJSONEditor}onEditForeignKeyColumnValue={onEditForeignKeyColumnValue}onClosePanel={onClosePanel}- theme={ui.themeOption == 'dark' ? 'dark' : 'light'}+ theme={isDarkMode ? 'dark' : 'light'}/><ConfirmationModaldangerdiff --git a/studio/pages/project/[ref]/sql/index.tsx b/studio/pages/project/[ref]/sql/index.tsxindex e45b4fc7301..3f1407056c2 100644--- a/studio/pages/project/[ref]/sql/index.tsx+++ b/studio/pages/project/[ref]/sql/index.tsx@@ -9,32 +9,33 @@ import getPgsqlSignatureHelpProvider from 'components/to-be-cleaned/SqlEditor/Pgimport { useStore } from 'hooks'import { SQLEditorLayout } from 'components/layouts'import { NextPageWithLayout } from 'types'+import { useTheme } from 'common'const SqlEditor: NextPageWithLayout = () => {- const { meta, ui } = useStore()- const { isDarkTheme } = ui+ const { meta } = useStore()+ const { isDarkMode } = useTheme()const sqlEditorStore: any = useSqlStore()const monaco = useMonaco()useEffect(() => {if (monaco) {monaco.editor.defineTheme('supabase', {- base: isDarkTheme ? 'vs-dark' : 'vs', // can also be hc-black+ base: isDarkMode ? 'vs-dark' : 'vs', // can also be hc-blackinherit: true, // can also be false to completely replace the builtin rulesrules: [- { token: '', background: isDarkTheme ? '1f1f1f' : 'f0f0f0' },+ { token: '', background: isDarkMode ? '1f1f1f' : 'f0f0f0' },{ token: 'string.sql', foreground: '24b47e' },{ token: 'comment', foreground: '666666' },// { token: 'predefined.sql', foreground: 'D4D4D4' },],colors: {- 'editor.background': isDarkTheme ? '#1f1f1f' : '#f0f0f0',+ 'editor.background': isDarkMode ? '#1f1f1f' : '#f0f0f0',// 'editorGutter.background': '#30313f',// 'editorLineNumber.foreground': '#555671',},})}- }, [monaco, isDarkTheme])+ }, [monaco, isDarkMode])useEffect(() => {if (monaco) {diff --git a/studio/stores/UiStore.ts b/studio/stores/UiStore.tsindex b568fcc85ab..46a522e6b21 100644--- a/studio/stores/UiStore.ts+++ b/studio/stores/UiStore.ts@@ -6,22 +6,14 @@ import Telemetry, { GoogleAnalyticsProps } from 'lib/telemetry'export interface IUiStore {language: 'en-US'- theme: 'dark' | 'light'- themeOption: 'dark' | 'light' | 'system'-selectedProjectRef?: string- isDarkTheme: booleanselectedProject?: ProjectselectedProjectBaseInfo?: ProjectBaseselectedOrganization?: Organizationnotification?: Notificationpermissions?: Permission[]-googleAnalyticsProps?: GoogleAnalyticsProps-load: () => void- setTheme: (theme: 'dark' | 'light') => void- onThemeOptionChange: (themeOption: 'dark' | 'light' | 'system') => voidsetProjectRef: (ref?: string) => voidsetOrganizationSlug: (slug?: string) => voidsetNotification: (notification: Notification) => string@@ -32,9 +24,6 @@ export interface IUiStore {export default class UiStore implements IUiStore {rootStore: IRootStorelanguage: 'en-US' = 'en-US'- theme: 'dark' | 'light' = 'dark'- themeOption: 'dark' | 'light' | 'system' = 'dark'-selectedProjectRef?: stringselectedOrganizationSlug?: stringnotification?: Notification@@ -95,10 +84,6 @@ export default class UiStore implements IUiStore {return undefined}- get isDarkTheme() {- return this.theme === 'dark'- }-get googleAnalyticsProps() {return {screenResolution:@@ -109,37 +94,6 @@ export default class UiStore implements IUiStore {load() {if (typeof window === 'undefined') return- const localStorageThemeOption = window.localStorage.getItem('theme')- if (localStorageThemeOption === 'system') {- this.themeOption = localStorageThemeOption- return this.setTheme(- window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'- )- }- if (localStorageThemeOption === 'light') {- this.themeOption = localStorageThemeOption- return this.setTheme('light')- }- window.localStorage.setItem('theme', 'dark')- this.themeOption = 'dark'- this.setTheme('dark')- }-- setTheme(theme: 'dark' | 'light') {- document.body.classList.replace(this.theme, theme)- this.theme = theme- }-- onThemeOptionChange(themeOption: 'dark' | 'light' | 'system') {- this.themeOption = themeOption- if (themeOption === 'system') {- window.localStorage.setItem('theme', 'system')- return this.setTheme(- window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'- )- }- window.localStorage.setItem('theme', themeOption)- this.setTheme(themeOption)}setProjectRef(ref?: string) {