Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change theme to drk/light instead of day/night #179

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cypress/e2e/explorer_latest_transaction_list_Xchain.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { expect } from 'chai'

let transactionsBody = {
transactions: [
{
Expand Down Expand Up @@ -279,7 +277,7 @@ describe('latest transaction list Xchainet', { tags: ['@explorer', '@suite'] },
})
})
cy.wait('@transactions').then(() => {
cy.get('.css-1voxykv-MuiPaper-root').should('be.visible')
cy.get('[aria-label="transaction-list"]').should('be.visible')
cy.get(
':nth-child(1) > .MuiGrid-grid-md-4 > .MuiGrid-container > .MuiGrid-grid-xs-8 > a > .MuiTypography-root',
)
Expand Down
11 changes: 7 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html lang="en" data-theme="night">
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="manifest" href="/manifest.json"/>
<link rel="manifest" href="/manifest.json" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
Expand Down Expand Up @@ -38,12 +38,12 @@
<div id="app"></div>
</body>
<style>
html[data-theme='day'] {
html[data-theme='light'] {
--background-color: #fff;
--secondary-background-color: #f1f5f9;
--text-color: #0f172a;
}
html[data-theme='night'] {
html[data-theme='dark'] {
--background-color: #0f172a;
--secondary-background-color: #1e293b;
--text-color: #ffffff;
Expand Down Expand Up @@ -101,6 +101,9 @@
></noscript
>
<script>
// set data-theme based on localStorage
const theme = localStorage.getItem('theme')
if (theme) document.documentElement.setAttribute('data-theme', theme)
let intervalId

function checkAppLoading() {
Expand Down
29 changes: 16 additions & 13 deletions src/components/Navbar/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { mdiWhiteBalanceSunny } from '@mdi/js'
import Icon from '@mdi/react'
import { Button, Typography, useTheme } from '@mui/material'
import { useStore } from 'Explorer/useStore'
import { getTheme, toggleTheme } from '../../redux/slices/theme'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'

import Icon from '@mdi/react'
import React from 'react'
import { mdiWhiteBalanceSunny } from '@mdi/js'
import store from 'wallet/store'
import { useAppDispatch, useAppSelector } from '../../hooks/reduxHooks'
import { useStore } from 'Explorer/useStore'
import useWidth from '../../hooks/useWidth'
import { getTheme, toggleTheme } from '../../redux/slices/theme'

export default function ThemeSwitcher() {
const { isDesktop, isMobile } = useWidth()
Expand All @@ -15,17 +16,19 @@ export default function ThemeSwitcher() {
const currentTheme = useAppSelector(getTheme)
const { changeTheme } = useStore()
const auth = useAppSelector(state => state.appConfig.isAuth)

const handleChangeTheme = () => {
if (currentTheme === 'light') document.documentElement.setAttribute('data-theme', 'dark')
else document.documentElement.setAttribute('data-theme', 'light')
changeTheme(currentTheme === 'light' ? 'dark' : 'light')
store.commit('updateTheme')
dispatch(toggleTheme())
}

return (
<Button
variant="text"
onClick={() => {
if (currentTheme === 'light')
document.documentElement.setAttribute('data-theme', 'night')
else document.documentElement.setAttribute('data-theme', 'day')
changeTheme(currentTheme === 'light' ? 'dark' : 'light')
store.commit('updateTheme')
dispatch(toggleTheme())
}}
onClick={handleChangeTheme}
startIcon={<Icon path={mdiWhiteBalanceSunny} size={1} />}
disableRipple
sx={{
Expand Down
4 changes: 2 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
--spacing-space-lg: 24px;
}

html[data-theme='day'] {
html[data-theme='light'] {
--bg: #f1f5f9;
--bg-1: 255, 255, 255;
--bg-light: #e2e8f0;
Expand Down Expand Up @@ -75,7 +75,7 @@ html[data-theme='day'] {
--camino-error-color: rgba(229, 67, 31, 1);
}

html[data-theme='night'] {
html[data-theme='dark'] {
--bg: #0f172a;
--bg-1: 36, 39, 41;
--bg-light: #1e293b;
Expand Down
11 changes: 1 addition & 10 deletions src/layout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ const MainLayout = ({ children }) => {
marginLeft: '10px',
marginRight: '10px',
minHeight: '200px',
backgroundColor: 'var(--camino-slate-slate-800)',
maxWidth: '500px',
}}
>
Expand All @@ -115,21 +114,13 @@ const MainLayout = ({ children }) => {
fontSize: '1.25rem !important',
mb: theme => theme.spacing(3),
textAlign: 'center',
color: 'var(--tailwind-slate-slate-200)',
}}
>
{!loadNetworks
? `Connecting to a new network, please wait.`
: `Loading networks, please wait.`}
</Typography>
<Typography
variant="caption"
gutterBottom
sx={{
textAlign: 'center',
color: 'var(--tailwind-slate-slate-200)',
}}
>
<Typography variant="caption" gutterBottom sx={{ textAlign: 'center' }}>
This will only take a few seconds. Please do not close the window.
</Typography>
<Box
Expand Down
15 changes: 7 additions & 8 deletions src/redux/slices/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ interface ITheme {
}

const getThemeFromLocalStorage = () => {
return 'dark'
// let theme = localStorage.getItem("theme") || undefined;

// if (theme) return theme;
// else {
// localStorage.setItem("theme", JSON.stringify("light"));
// return "light";
// }
let theme = localStorage.getItem('theme') || undefined

if (theme) return theme
else {
localStorage.setItem('theme', JSON.stringify('light'))
return 'light'
}
}

let initialState: ITheme = {
Expand Down
Loading