Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: export theme-settings with observer for theme-option

Harsh Karande1d0d13e308e9
diff --git a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
index 5a306b8dab0..3d97b49b5fc 100644
--- a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
+++ b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
@@ -1,4 +1,4 @@
-import React, { FC, useState } from 'react'
+import React, { FC } from 'react'
import Link from 'next/link'
import { observer } from 'mobx-react-lite'
import { useRouter } from 'next/router'
@@ -21,8 +21,6 @@ const NavigationBar: FC<Props> = ({}) => {
const productRoutes = generateProductRoutes(projectRef)
const otherRoutes = generateOtherRoutes(projectRef)
- const [value, setValue] = useState(ui.themeOption)
-
return (
<div className="h-screen w-14 flex flex-col justify-between p-2 overflow-y-hidden bg-sidebar-light dark:bg-sidebar-dark border-r dark:border-dark">
<ul className="flex flex-col space-y-2">
@@ -82,11 +80,8 @@ const NavigationBar: FC<Props> = ({}) => {
<div className="w-[240px] py-1 flex items-center justify-between">
<Typography.Text>Theme</Typography.Text>
<Select
- value={value}
- onChange={(e: any) => {
- setValue(e.target.value)
- ui.onThemeOptionChange(e.target.value)
- }}
+ value={ui.themeOption}
+ onChange={(e: any) => ui.onThemeOptionChange(e.target.value)}
>
<Select.Option value="system">System default</Select.Option>
<Select.Option value="dark">Dark</Select.Option>
diff --git a/studio/pages/account/me.tsx b/studio/pages/account/me.tsx
index 7668db3415a..3a3190a7cc5 100644
--- a/studio/pages/account/me.tsx
+++ b/studio/pages/account/me.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react'
+import React from 'react'
import { observer } from 'mobx-react-lite'
import { IconMoon, IconSun, Select, Typography } from '@supabase/ui'
@@ -77,9 +77,8 @@ const ProfileCard = observer(() => {
)
})
-function ThemeSettings() {
+const ThemeSettings = observer(() => {
const { ui } = useStore()
- const [value, setValue] = useState(ui.themeOption)
return (
<Panel
@@ -91,16 +90,19 @@ function ThemeSettings() {
>
<Panel.Content>
<Select
- value={value}
+ value={ui.themeOption}
label="Interface theme"
descriptionText="Choose a theme preference"
layout="horizontal"
style={{ width: '50%' }}
- icon={value === 'light' ? <IconSun /> : value === 'dark' ? <IconMoon /> : undefined}
- onChange={(e: any) => {
- setValue(e.target.value)
- ui.onThemeOptionChange(e.target.value)
- }}
+ icon={
+ ui.themeOption === 'light' ? (
+ <IconSun />
+ ) : ui.themeOption === 'dark' ? (
+ <IconMoon />
+ ) : undefined
+ }
+ onChange={(e: any) => ui.onThemeOptionChange(e.target.value)}
>
<Select.Option value="system">System default</Select.Option>
<Select.Option value="dark">Dark</Select.Option>
@@ -109,4 +111,4 @@ function ThemeSettings() {
</Panel.Content>
</Panel>
)
-}
+})