Skip to content

Commit 699661a

Browse files
ci-botAniket-Engg
authored andcommitted
switch icon based on current theme. fix console error for settings
1 parent 427c957 commit 699661a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

libs/remix-ui/top-bar/src/lib/remix-ui-topbar.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ export function RemixUiTopbar () {
3636
const [latestReleaseNotesUrl, setLatestReleaseNotesUrl] = useState<string>('')
3737
const [currentReleaseVersion, setCurrentReleaseVersion] = useState<string>('')
3838
const [menuItems, setMenuItems] = useState<any[]>([])
39+
const [showTheme, setShowTheme] = useState<boolean>(false)
3940
const subMenuIconRef = useRef<any>(null)
41+
const themeIconRef = useRef<any>(null)
4042
const [showSubMenuFlyOut, setShowSubMenuFlyOut] = useState<boolean>(false)
41-
useOnClickOutside([subMenuIconRef], () => setShowSubMenuFlyOut(false))
43+
useOnClickOutside([subMenuIconRef, themeIconRef], () => setShowSubMenuFlyOut(false))
44+
useOnClickOutside([themeIconRef], () => setShowTheme(false))
4245
const workspaceRenameInput = useRef()
4346
const cloneUrlRef = useRef<HTMLInputElement>()
4447

@@ -285,6 +288,15 @@ export function RemixUiTopbar () {
285288
const theme = await plugin.call('theme', 'currentTheme')
286289
return theme
287290
}
291+
292+
useEffect(() => {
293+
const run = async () => {
294+
const theme = await getCurrentTheme()
295+
setCurrentTheme(theme)
296+
}
297+
run()
298+
}, [])
299+
288300
const renameModalMessage = (workspaceName?: string) => {
289301
return (
290302
<div className='d-flex flex-column'>
@@ -512,7 +524,7 @@ export function RemixUiTopbar () {
512524
/>
513525
)}
514526
</>
515-
<Dropdown className="ml-5" data-id="topbar-themeIcon">
527+
<Dropdown className="ml-5" data-id="topbar-themeIcon" show={showTheme} ref={themeIconRef}>
516528
<Dropdown.Toggle
517529
as={Button}
518530
variant="outline-secondary"
@@ -522,8 +534,13 @@ export function RemixUiTopbar () {
522534
padding: '0.35rem 0.5rem',
523535
fontSize: '0.8rem'
524536
}}
537+
onClick={async () => {
538+
const theme = await getCurrentTheme()
539+
setCurrentTheme(theme)
540+
setShowTheme(!showTheme)
541+
}}
525542
>
526-
<i className="fas fa-sun-bright mr-2"></i>
543+
<i className={`fas ${currentTheme && currentTheme.name.includes('Dark') ? 'fa-moon' : 'fa-sun-bright'} mr-2`}></i>
527544
Theme
528545
</Dropdown.Toggle>
529546
<Dropdown.Menu
@@ -559,7 +576,6 @@ export function RemixUiTopbar () {
559576
className=""
560577
onClick={async () => {
561578
plugin.call('menuicons', 'select', 'settings')
562-
plugin.call('tabs', 'focus', 'settings')
563579
_paq.push(['trackEvent', 'topbar', 'header', 'Settings'])
564580
}}
565581
data-id="topbar-settingsIcon"

0 commit comments

Comments
 (0)