Skip to content

Commit

Permalink
console: Fix linting and login page
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Mar 5, 2025
1 parent c19ca42 commit ba7491a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
66 changes: 43 additions & 23 deletions pkg/webui/account/views/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,49 @@ const getScrollRestorationKey = location => {
return `${pathname}${page ? `?page=${page}` : ''}`
}

const Layout = () => (
<>
<ScrollRestoration getKey={getScrollRestorationKey} />
<ToastContainer />
<ErrorView errorRender={errorRender}>
<React.Fragment>
<Helmet
titleTemplate={`%s - ${siteTitle ? `${siteTitle} - ` : ''}${siteName}`}
defaultTitle={`${siteTitle ? `${siteTitle} - ` : ''}${siteName}`}
/>
<div className={style.container}>
<section className={style.content}>
<div className={style.main}>
<Logo className={style.loginLogo} unlockSize />
<Outlet />
</div>
</section>
<section className={style.visual} />
</div>
</React.Fragment>
</ErrorView>
</>
)
const Layout = () => {
const darkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches

const toggleTheme = theme => {
const htmlElement = document.documentElement

if (theme === 'dark') {
htmlElement.classList.add('dark')
htmlElement.classList.remove('light')
} else {
htmlElement.classList.add('light')
htmlElement.classList.remove('dark')
}
}

useEffect(() => {
toggleTheme(darkTheme ? 'dark' : 'light')
}, [darkTheme])

return (
<>
<ScrollRestoration getKey={getScrollRestorationKey} />
<ToastContainer />
<ErrorView errorRender={errorRender}>
<React.Fragment>
<Helmet
titleTemplate={`%s - ${siteTitle ? `${siteTitle} - ` : ''}${siteName}`}
defaultTitle={`${siteTitle ? `${siteTitle} - ` : ''}${siteName}`}
/>
<div className={style.container}>
<section className={style.content}>
<div className={style.main}>
<Logo className={style.loginLogo} unlockSize />
<Outlet />
</div>
</section>
<section className={style.visual} />
</div>
</React.Fragment>
</ErrorView>
</>
)
}

const AccountRoot = () => {
const user = useSelector(selectUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ const LatestDecodedPayloadPanel = ({ appId, events, shortCutLinkPath, className,
imageFetching,
isDevice,
modalVisible,
darkTheme,
],
)

Expand Down
14 changes: 12 additions & 2 deletions pkg/webui/console/containers/user-settings-theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'
import sharedMessages from '@ttn-lw/lib/shared-messages'
import PropTypes from '@ttn-lw/lib/prop-types'

import { updateUser } from '@console/store/actions/user'
import { updateUser, updateUserSuccess } from '@console/store/actions/user'

import { selectUserId } from '@console/store/selectors/logout'
import { selectSelectedUser } from '@console/store/selectors/users'
Expand All @@ -54,11 +54,20 @@ const validationSchema = Yup.object().shape({
})

const InnerThemeForm = ({ initialValues }) => {
const dispatch = useDispatch()
const { resetForm } = useFormContext()

const handleThemeChange = useCallback(
value => {
dispatch(updateUserSuccess({ console_preferences: { console_theme: value } }))
},
[dispatch],
)

const handleDiscardChanges = useCallback(() => {
resetForm(initialValues)
}, [resetForm, initialValues])
dispatch(updateUserSuccess(initialValues))
}, [resetForm, initialValues, dispatch])

return (
<>
Expand All @@ -68,6 +77,7 @@ const InnerThemeForm = ({ initialValues }) => {
horizontal
spaceBetween
className="m-vert-cs-xxl"
onChange={handleThemeChange}
>
<Radio
label={m.light}
Expand Down

0 comments on commit ba7491a

Please sign in to comment.