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: dark theme support #148

Merged
merged 56 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f4a0327
dark theme added
AmitChauhan63390 Nov 6, 2024
a486e66
color switches to pink when tab is selected
AmitChauhan63390 Nov 7, 2024
9634b22
fixed issue: Theme going default when refreshing the page
AmitChauhan63390 Nov 7, 2024
024468f
Merge branch 'getmaxun:master' into ui-fix
AmitChauhan63390 Nov 8, 2024
2d964fb
Recordscreen darkkmode updated
AmitChauhan63390 Nov 8, 2024
1c6199d
minor hovering effect
AmitChauhan63390 Nov 8, 2024
36243d8
text color changed
AmitChauhan63390 Nov 9, 2024
0f801b7
recording window theme changed
AmitChauhan63390 Nov 10, 2024
5354282
rightpanel theme changed
AmitChauhan63390 Nov 10, 2024
965044a
Merge branch 'develop' into ui-fix
AmitChauhan63390 Nov 23, 2024
f71822f
some fixes
AmitChauhan63390 Nov 23, 2024
e9e9070
tab indicator default color changed to ff00c3
AmitChauhan63390 Nov 23, 2024
3cf0786
pinkish buttons
AmitChauhan63390 Nov 24, 2024
587dacd
mui blue color fixes
AmitChauhan63390 Dec 7, 2024
655eadc
forms
AmitChauhan63390 Dec 8, 2024
9b667c9
Merge branch 'develop' into ui-fix
AmitChauhan63390 Dec 8, 2024
f11b36b
forms
AmitChauhan63390 Dec 8, 2024
b2de5f3
Merge branch 'develop' into ui-fix
RohitR311 Jan 8, 2025
3134edf
feat: rm ThemeProvider
RohitR311 Jan 8, 2025
0d5ac2b
feat: add dark mode to project name
RohitR311 Jan 8, 2025
3f9afc1
feat: add toggle dark theme button
RohitR311 Jan 8, 2025
65cdef3
feat: change comment for button
RohitR311 Jan 8, 2025
15c29a8
feat: change comment for tabs
RohitR311 Jan 8, 2025
74527d5
feat: change comment for form labels
RohitR311 Jan 8, 2025
12aaf61
feat: reset light theme
RohitR311 Jan 8, 2025
70086dd
feat: change dark theme config for navbar
RohitR311 Jan 8, 2025
eb50f4f
feat: rm bg color for right side panel
RohitR311 Jan 8, 2025
f9644d3
feat: change finish button color
RohitR311 Jan 8, 2025
afcd69b
feat: change finish button border color
RohitR311 Jan 8, 2025
5b89111
feat: change navbar icons styling
RohitR311 Jan 8, 2025
cefa5df
feat: change bg color on hover
RohitR311 Jan 8, 2025
753d1d8
feat: change bg color on hover
RohitR311 Jan 8, 2025
843db67
feat: add styling to right side panel buttons
RohitR311 Jan 8, 2025
8ea90a7
feat: add style to select attribute button
RohitR311 Jan 8, 2025
07f1aba
feat: add default bg color on selection
RohitR311 Jan 8, 2025
8cb7269
feat: add styling for cancel button
RohitR311 Jan 8, 2025
e0c3cf7
feat: add styling for cancel button
RohitR311 Jan 8, 2025
baf0845
feat: add styling for cancel button
RohitR311 Jan 8, 2025
9210d2f
feat: add styling for cancel button
RohitR311 Jan 8, 2025
94bb35c
feat: add theme icon and change colors
RohitR311 Jan 8, 2025
d6374ba
feat: change styling for buttons
RohitR311 Jan 8, 2025
4df8b4c
feat: change outpreview styling
RohitR311 Jan 8, 2025
fa2f586
feat: rm hover effect for username
RohitR311 Jan 8, 2025
7772411
feat: revert element styling
RohitR311 Jan 8, 2025
df2db05
feat: change proxy tabs styling
RohitR311 Jan 8, 2025
91c42b8
feat: change styling for remote browser tab
RohitR311 Jan 8, 2025
589c490
feat: change icon buttons styling for browser navbar
RohitR311 Jan 8, 2025
95694d3
feat: change styling for loader component
RohitR311 Jan 8, 2025
2aee3e6
feat: change styling for light theme in recording page
RohitR311 Jan 8, 2025
e46736a
feat: change styling for finish button
RohitR311 Jan 8, 2025
7705e1e
feat: change styling for discard button
RohitR311 Jan 8, 2025
8666c5e
feat: change styling for cancel button{
RohitR311 Jan 8, 2025
e907615
feat: revert canvas changes to latest
RohitR311 Jan 8, 2025
521ce57
feat: change width and styling
RohitR311 Jan 8, 2025
56e2d78
feat: change styling for browser content
RohitR311 Jan 8, 2025
7c44280
feat: revert browser window border radius
RohitR311 Jan 8, 2025
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
23 changes: 16 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ThemeProvider, createTheme } from "@mui/material/styles";
import { GlobalInfoProvider } from "./context/globalInfo";
import { PageWrapper } from "./pages/PageWrappper";
import i18n from "./i18n";
import ThemeModeProvider from './context/theme-provider';


const theme = createTheme({
Expand Down Expand Up @@ -85,15 +86,23 @@ const theme = createTheme({

function App() {
return (
<ThemeProvider theme={theme}>
<ThemeModeProvider>
<GlobalInfoProvider>
<Routes>
<Route path="/*" element={<PageWrapper />} />
</Routes>
</GlobalInfoProvider>
</ThemeModeProvider>

// <ThemeProvider theme={theme}>

<GlobalInfoProvider>
<Routes>
<Route path="/*" element={<PageWrapper />} />
</Routes>
</GlobalInfoProvider>
// <GlobalInfoProvider>
// <Routes>
// <Route path="/*" element={<PageWrapper />} />
// </Routes>
// </GlobalInfoProvider>

</ThemeProvider>
// </ThemeProvider>
);
}

Expand Down
17 changes: 13 additions & 4 deletions src/components/atoms/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import styled from "styled-components";
import { Stack } from "@mui/material";
import { useThemeMode } from "../../context/theme-provider";

interface LoaderProps {
text: string;
}

export const Loader: React.FC<LoaderProps> = ({ text }) => {
const { darkMode } = useThemeMode();

return (
<Stack direction="column" sx={{ margin: "30px 0px", alignItems: "center" }}>
<DotsContainer>
Expand All @@ -14,16 +17,22 @@ export const Loader: React.FC<LoaderProps> = ({ text }) => {
<Dot />
<Dot />
</DotsContainer>
<StyledParagraph>{text}</StyledParagraph>
<StyledParagraph darkMode={darkMode}>{text}</StyledParagraph>
</Stack>
);
};

const StyledParagraph = styled.p`
font-size: large;
interface StyledParagraphProps {
darkMode: boolean;
}

const StyledParagraph = styled.p<StyledParagraphProps>`
font-size: medium;
font-weight: 700;
font-family: inherit;
color: #333;
color: ${({ darkMode }) => (darkMode ? 'white' : 'black')};
margin-top: 20px;
flex-wrap: wrap;
`;

const DotsContainer = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/RecorderIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const RecordingIcon = () => {
textIndent: 0,
textTransform: 'none',
}}
fill="white"
fill="black"
d="m82.048,962.36c-0.18271-0.003-0.35147-0.001-0.53125,0.0312-0.69633,0.12662-1.3353,0.54943-1.7812,1.1562l-0.03125-0.0312-0.03125,0.0625-18.031,22.125h-44.438c-2.809,0-5.0938,2.2847-5.0938,5.0938v35.531c0,2.8091,2.2847,5.125,5.0938,5.125h20.562l-1.3125,4.5938h-0.71875c-1.1137,0-2.0312,0.9175-2.0312,2.0312v2.2188c0,1.1137,0.91751,2.0625,2.0312,2.0625h19.938c1.1137,0,2.0312-0.9488,2.0312-2.0625v-2.2188c0-1.1137-0.91751-2.0312-2.0312-2.0312h-0.71875l-1.3438-4.5938h20.438c2.809,0,5.0938-2.3159,5.0938-5.125v-35.531c0-1.7706-0.90663-3.3369-2.2812-4.25l10.531-17.625,0.03125-0.0625c0.84234-1.2783,0.51486-3.0308-0.75-3.9062l-3.0312-2.0938c-0.48208-0.33338-1.0456-0.49073-1.5938-0.5zm-0.21875,1.6875c0.28723-0.0523,0.57635,0.0338,0.84375,0.21875l3.0312,2.0938c0.53421,0.36973,0.65504,1.0569,0.28125,1.5938a0.85008,0.85008,0,0,0,-0.03125,0.0312l-17.906,30.062-9.0938-6.3125,22.094-27.125a0.85008,0.85008,0,0,0,0.03125,-0.0625c0.18694-0.26873,0.46277-0.4477,0.75-0.5zm-64.625,23.344,43.062,0-2.3438,2.9062-40.688,0c-0.0312-0.002-0.06255-0.002-0.09375,0-0.0312-0.002-0.06255-0.002-0.09375,0-0.38644,0.0753-0.69183,0.45007-0.6875,0.84375v34.844c0.003,0.4514,0.42377,0.857,0.875,0.8437h56.781c0.44088,0,0.84048-0.4028,0.84375-0.8437v-34.844c-0.008-0.25538-0.13841-0.50419-0.34375-0.65625l1.5-2.5c0.87419,0.61342,1.4375,1.6512,1.4375,2.8125v35.531c0,1.8967-1.5096,3.4063-3.4062,3.4063h-56.844c-1.8966,0-3.4062-1.5096-3.4062-3.4063v-35.531c0-1.8966,1.5096-3.4062,3.4062-3.4062zm0.875,4.5938,38.469,0-1.0312,1.25,0,0.0312c-0.48971,0.60518-0.64056,1.3922-0.5,2.0312,0.14234,0.64722,0.49536,1.1659,0.84375,1.6562a0.85008,0.85008,0,0,0,0.1875,0.21875l1.2812,0.875c-1.0387,0.79518-2.0706,1.1661-3.2188,1.6562-1.4337,0.61212-3.0045,1.4512-4.3438,3.375-1.1451,1.6448-1.0525,3.5446-0.78125,5.3437,0.27121,1.7991,0.70152,3.5802,0.5625,5.2188a0.85008,0.85008,0,0,0,1.2188,0.8437c1.4928-0.7039,3.3085-0.9361,5.0938-1.3125s3.6049-0.9489,4.75-2.5937c1.34-1.9249,1.5559-3.6628,1.625-5.2188,0.05552-1.2502,0.05447-2.363,0.4375-3.625l1.2812,0.875c1.2744,0.8814,3.0499,0.4785,3.8438-0.8437l0.03125-0.031,1.125-1.9063a0.85008,0.85008,0,0,0,0.03125,-0.0312l0.03125-0.0312a0.85008,0.85008,0,0,0,0.09375,-0.21875l4.0625-6.8125v32.406h-55.094v-33.156zm39.812,1.0625,9.3125,6.4375-0.84375,1.4062a0.85008,0.85008,0,0,0,-0.03125,0c-0.33037,0.5726-0.86691,0.7168-1.4062,0.3438l-2.1875-1.5-0.1875-0.15625-0.65625-0.4375-1.8438-1.2812-0.84375-0.59375-0.0625-0.0312-1.9688-1.3438c-0.25075-0.36937-0.4494-0.7387-0.5-0.96875-0.0558-0.25371-0.0497-0.34572,0.15625-0.59375l1.0625-1.2812zm0.84375,5.9688,0.34375,0.25,1.8438,1.25,0.375,0.25c-0.60662,1.6994-0.69236,3.2017-0.75,4.5-0.0657,1.481-0.18871,2.7295-1.3125,4.3438-0.76502,1.0988-2.0465,1.5537-3.7188,1.9062-1.3283,0.2801-2.854,0.5618-4.3438,1.0625-0.0521-1.5631-0.29881-3.0716-0.5-4.4062-0.25388-1.6841-0.29624-3.0262,0.46875-4.125,1.1246-1.6154,2.2602-2.1673,3.625-2.75,1.1932-0.5094,2.5901-1.1274,3.9688-2.2813zm-30.5,2.5313c-1.6815,0-3.0625,1.4119-3.0625,3.0937s1.381,3.0313,3.0625,3.0313,3.0625-1.3495,3.0625-3.0313-1.381-3.0937-3.0625-3.0937zm0,1.7187c0.76283,0,1.375,0.612,1.375,1.375s-0.61217,1.3438-1.375,1.3438-1.3438-0.5808-1.3438-1.3438,0.58092-1.375,1.3438-1.375zm8,5.6563c-3.3379,0.1812-7.1915,2.4749-10.344,4.6875-3.1522,2.2126-5.5625,4.4062-5.5625,4.4062-0.3273,0.3027-0.36527,0.8915-0.0625,1.2188,0.30273,0.3272,0.89151,0.334,1.2188,0.031,0,0,2.3185-2.1046,5.375-4.25s6.8989-4.2667,9.4688-4.4063c1.6177-0.088,4.3314,1.0381,6.5312,2.25,2.1999,1.212,3.9375,2.4375,3.9375,2.4375,0.35264,0.3353,1.001,0.2728,1.2812-0.125,0.28024-0.3977,0.12188-1.0307-0.3125-1.25,0,0-1.7602-1.2941-4.0625-2.5625-2.3024-1.2684-5.0831-2.567-7.4688-2.4375zm3.2812,22.562,12.344,0,1.3438,4.5312-15,0,1.3125-4.5312zm-3.7812,6.25,19.938,0c0.20135,0,0.3125,0.1424,0.3125,0.3437v2.2188c0,0.2013-0.11115,0.3437-0.3125,0.3437h-19.938c-0.20135,0-0.34375-0.1424-0.34375-0.3437v-2.2188c0-0.2013,0.1424-0.3437,0.34375-0.3437z" />
</g>
</g>
Expand Down
19 changes: 8 additions & 11 deletions src/components/atoms/buttons/buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import styled from 'styled-components';
import { useThemeMode } from '../../../context/theme-provider';

export const NavBarButton = styled.button<{ disabled: boolean }>`


export const NavBarButton = styled.button<{ disabled: boolean, mode: 'light' | 'dark' }>`
margin-left: 10px;
margin-right: 5px;
padding: 0;
border: none;
background-color: transparent;
background-color: ${mode => mode ? '#333' : '#ffffff'};
cursor: ${({ disabled }) => disabled ? 'default' : 'pointer'};
width: 24px;
height: 24px;
border-radius: 12px;
outline: none;
color: ${({ disabled }) => disabled ? '#999' : '#333'};
color: ${mode => mode ? '#ffffff' : '#333333'};


Comment on lines +6 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix style functions to correctly access the mode prop

In the styled component, the template literals should access the mode prop correctly. Currently, background-color: ${mode => mode ? ...} does not access the mode prop as intended.

Apply this diff to fix the issue:

 export const NavBarButton = styled.button<{ disabled: boolean, mode: 'light' | 'dark' }>`
     margin-left: 10px;
     margin-right: 5px;
     padding: 0;
     border: none;
-    background-color: ${mode => mode ? '#333' : '#ffffff'};
+    background-color: ${({ mode }) => mode === 'dark' ? '#333' : '#ffffff'};
     cursor: ${({ disabled }) => disabled ? 'default' : 'pointer'};
     width: 24px;
     height: 24px;
     border-radius: 12px;
     outline: none;
-    color: ${mode => mode ? '#ffffff' : '#333333'};
+    color: ${({ mode }) => mode === 'dark' ? '#ffffff' : '#333333'};
  
 `;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const NavBarButton = styled.button<{ disabled: boolean, mode: 'light' | 'dark' }>`
margin-left: 10px;
margin-right: 5px;
padding: 0;
border: none;
background-color: transparent;
background-color: ${mode => mode ? '#333' : '#ffffff'};
cursor: ${({ disabled }) => disabled ? 'default' : 'pointer'};
width: 24px;
height: 24px;
border-radius: 12px;
outline: none;
color: ${({ disabled }) => disabled ? '#999' : '#333'};
color: ${mode => mode ? '#ffffff' : '#333333'};
export const NavBarButton = styled.button<{ disabled: boolean, mode: 'light' | 'dark' }>`
margin-left: 10px;
margin-right: 5px;
padding: 0;
border: none;
background-color: ${({ mode }) => mode === 'dark' ? '#333' : '#ffffff'};
cursor: ${({ disabled }) => disabled ? 'default' : 'pointer'};
width: 24px;
height: 24px;
border-radius: 12px;
outline: none;
color: ${({ mode }) => mode === 'dark' ? '#ffffff' : '#333333'};


${({ disabled }) => disabled ? null : `
&:hover {
background-color: #ddd;
}
&:active {
background-color: #d0d0d0;
}
`};
`;

export const UrlFormButton = styled.button`
Expand Down
36 changes: 26 additions & 10 deletions src/components/molecules/ActionDescriptionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import { useActionContext } from '../../context/browserActions';
import MaxunLogo from "../../assets/maxunlogo.png";
import { useTranslation } from 'react-i18next';

const CustomBoxContainer = styled.div`
interface CustomBoxContainerProps {
isDarkMode: boolean;
}

Comment on lines +8 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using MUI's theme system instead of prop drilling

The isDarkMode prop is being passed through multiple components when MUI's theme system could handle this more elegantly.

Consider using MUI's theme system:

interface CustomBoxContainerProps {
  theme: Theme;  // Use MUI's Theme type
}

const CustomBoxContainer = styled.div<CustomBoxContainerProps>`
position: relative;
min-width: 250px;
width: auto;
min-height: 100px;
height: auto;
// border: 2px solid #ff00c3;
border-radius: 5px;
background-color: white;
background-color: ${({ isDarkMode }) => (isDarkMode ? '#313438' : 'white')};
color: ${({ isDarkMode }) => (isDarkMode ? 'white' : 'black')};
Comment on lines +19 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use theme tokens instead of hardcoded colors

Hardcoded colors (#313438, white) should be replaced with theme tokens for better maintainability and consistency.

Consider this implementation:

- background-color: ${({ isDarkMode }) => (isDarkMode ? '#313438' : 'white')};
- color: ${({ isDarkMode }) => (isDarkMode ? 'white' : 'black')};
+ background-color: ${({ theme }) => theme.palette.background.paper};
+ color: ${({ theme }) => theme.palette.text.primary};

- border-bottom: 20px solid ${({ isDarkMode }) => (isDarkMode ? '#313438' : 'white')};
+ border-bottom: 20px solid ${({ theme }) => theme.palette.background.paper};

Also applies to: 33-33

margin: 80px 13px 25px 13px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
`;

const Triangle = styled.div`
const Triangle = styled.div<CustomBoxContainerProps>`
position: absolute;
top: -15px;
left: 50%;
Expand All @@ -26,7 +31,7 @@ const Triangle = styled.div`
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 20px solid white;
border-bottom: 20px solid ${({ isDarkMode }) => (isDarkMode ? '#313438' : 'white')};
`;

const Logo = styled.img`
Expand All @@ -44,7 +49,8 @@ const Content = styled.div`
text-align: left;
`;

const ActionDescriptionBox = () => {

const ActionDescriptionBox = ({ isDarkMode }: { isDarkMode: boolean }) => {
const { t } = useTranslation();
const { getText, getScreenshot, getList, captureStage } = useActionContext() as {
getText: boolean;
Expand Down Expand Up @@ -93,9 +99,19 @@ const ActionDescriptionBox = () => {
<Checkbox
checked={index < currentStageIndex}
disabled
sx={{
color: isDarkMode ? 'white' : 'default',
'&.Mui-checked': {
color: isDarkMode ? '#90caf9' : '#1976d2',
},
}}
/>
}
label={<Typography variant="body2" gutterBottom>{text}</Typography>}
label={
<Typography variant="body2" gutterBottom color={isDarkMode ? 'white' : 'textPrimary'}>
{text}
</Typography>
}
/>
))}
</Box>
Expand All @@ -112,9 +128,9 @@ const ActionDescriptionBox = () => {
};

return (
<CustomBoxContainer>
<Logo src={MaxunLogo} alt='maxun_logo' />
<Triangle />
<CustomBoxContainer isDarkMode={isDarkMode}>
<Logo src={MaxunLogo} alt="Maxun Logo" />
<Triangle isDarkMode={isDarkMode} />
<Content>
{renderActionDescription()}
</Content>
Expand Down
25 changes: 12 additions & 13 deletions src/components/molecules/ActionSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { useRef } from 'react';
import styled from "styled-components";
import { Button } from "@mui/material";
//import { ActionDescription } from "../organisms/RightSidePanel";
import * as Settings from "./action-settings";
import { useSocketStore } from "../../context/socket";

interface ActionSettingsProps {
action: string;
darkMode?: boolean;
}

export const ActionSettings = ({ action }: ActionSettingsProps) => {

export const ActionSettings = ({ action, darkMode = false }: ActionSettingsProps) => {
const settingsRef = useRef<{ getSettings: () => object }>(null);
const { socket } = useSocketStore();

Expand All @@ -20,30 +19,27 @@ export const ActionSettings = ({ action }: ActionSettingsProps) => {
return <Settings.ScreenshotSettings ref={settingsRef} />;
case 'scroll':
return <Settings.ScrollSettings ref={settingsRef} />;
case 'scrape':
return <Settings.ScrapeSettings ref={settingsRef} />;
case 'scrape':
return <Settings.ScrapeSettings ref={settingsRef} />;
case 'scrapeSchema':
return <Settings.ScrapeSchemaSettings ref={settingsRef} />;
default:
return null;
}
}
};

const handleSubmit = (event: React.SyntheticEvent) => {
event.preventDefault();
//get the data from settings
const settings = settingsRef.current?.getSettings();
//Send notification to the server and generate the pair
socket?.emit(`action`, {
action,
settings
});
}
};
Comment on lines 31 to +38
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for socket events

The form submission doesn't handle potential socket connection errors.

  const handleSubmit = (event: React.SyntheticEvent) => {
    event.preventDefault();
    const settings = settingsRef.current?.getSettings();
-   socket?.emit(`action`, {
-     action,
-     settings
-   });
+   if (!socket?.connected) {
+     console.error('Socket not connected');
+     return;
+   }
+   try {
+     socket.emit(`action`, {
+       action,
+       settings
+     });
+   } catch (error) {
+     console.error('Failed to emit action:', error);
+   }
  };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleSubmit = (event: React.SyntheticEvent) => {
event.preventDefault();
//get the data from settings
const settings = settingsRef.current?.getSettings();
//Send notification to the server and generate the pair
socket?.emit(`action`, {
action,
settings
});
}
};
const handleSubmit = (event: React.SyntheticEvent) => {
event.preventDefault();
const settings = settingsRef.current?.getSettings();
if (!socket?.connected) {
console.error('Socket not connected');
return;
}
try {
socket.emit(`action`, {
action,
settings
});
} catch (error) {
console.error('Failed to emit action:', error);
}
};


return (
<div>
{/* <ActionDescription>Action settings:</ActionDescription> */}
<ActionSettingsWrapper action={action}>
<ActionSettingsWrapper action={action} darkMode={darkMode}>
<form onSubmit={handleSubmit}>
<DisplaySettings />
<Button
Expand All @@ -64,10 +60,13 @@ export const ActionSettings = ({ action }: ActionSettingsProps) => {
);
};

const ActionSettingsWrapper = styled.div<{ action: string }>`
// Ensure that the Wrapper accepts the darkMode prop for styling adjustments.
const ActionSettingsWrapper = styled.div<{ action: string; darkMode: boolean }>`
display: flex;
flex-direction: column;
align-items: ${({ action }) => action === 'script' ? 'stretch' : 'center'};;
align-items: ${({ action }) => (action === 'script' ? 'stretch' : 'center')};
justify-content: center;
margin-top: 20px;
background-color: ${({ darkMode }) => (darkMode ? '#1E1E1E' : 'white')};
color: ${({ darkMode }) => (darkMode ? 'white' : 'black')};
`;
55 changes: 40 additions & 15 deletions src/components/molecules/BrowserNavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type {
FC,
} from 'react';
import type { FC } from 'react';
import styled from 'styled-components';

import ReplayIcon from '@mui/icons-material/Replay';
Expand All @@ -13,15 +11,38 @@ import { useCallback, useEffect, useState } from "react";
import { useSocketStore } from "../../context/socket";
import { getCurrentUrl } from "../../api/recording";
import { useGlobalInfoStore } from '../../context/globalInfo';

const StyledNavBar = styled.div<{ browserWidth: number }>`
import { useThemeMode } from '../../context/theme-provider';

// const StyledNavBar = styled.div<{ browserWidth: number; isDarkMode: boolean }>`
// display: flex;
// align-items: center;
// padding: 10px 20px;
// background-color: ${({ isDarkMode }) => (isDarkMode ? '#2C2F33' : '#F5F5F5')};
// width: ${({ browserWidth }) => `${browserWidth}px`};
// border-radius: 0px 0px 8px 8px;
// box-shadow: ${({ isDarkMode }) => (isDarkMode ? '0px 2px 10px rgba(0, 0, 0, 0.2)' : '0px 2px 10px rgba(0, 0, 0, 0.1)')};
// transition: background-color 0.3s ease, box-shadow 0.3s ease;
// margin-bottom: 15px;
// `;

const StyledNavBar = styled.div<{ browserWidth: number; isDarkMode: boolean }>`
display: flex;
padding: 12px 0px;
background-color: #f6f6f6;
background-color: ${({ isDarkMode }) => (isDarkMode ? '#2C2F33' : '#f6f6f6')};
width: ${({ browserWidth }) => browserWidth}px;
border-radius: 0px 5px 0px 0px;
`;

const IconButton = styled(NavBarButton)<{ mode: string }>`
background-color: ${({ mode }) => (mode === 'dark' ? '#2C2F33' : '#f6f6f6')};
transition: background-color 0.3s ease, transform 0.1s ease;
color: ${({ mode }) => (mode === 'dark' ? '#FFFFFF' : '#333')};
cursor: pointer;
&:hover {
background-color: ${({ mode }) => (mode === 'dark' ? '#586069' : '#D0D0D0')};
}
`;

interface NavBarProps {
browserWidth: number;
handleUrlChanged: (url: string) => void;
Expand All @@ -31,6 +52,7 @@ const BrowserNavBar: FC<NavBarProps> = ({
browserWidth,
handleUrlChanged,
}) => {
const isDarkMode = useThemeMode().darkMode;

const { socket } = useSocketStore();
const { recordingUrl, setRecordingUrl } = useGlobalInfoStore();
Expand Down Expand Up @@ -67,7 +89,7 @@ const BrowserNavBar: FC<NavBarProps> = ({
socket.off('urlChanged', handleCurrentUrlChange);
}
}
}, [socket, handleCurrentUrlChange])
}, [socket, handleCurrentUrlChange]);

const addAddress = (address: string) => {
if (socket) {
Expand All @@ -78,38 +100,41 @@ const BrowserNavBar: FC<NavBarProps> = ({
};

return (
<StyledNavBar browserWidth={900}>
<NavBarButton
<StyledNavBar browserWidth={browserWidth} isDarkMode={isDarkMode}>
<IconButton
type="button"
onClick={() => {
socket?.emit('input:back');
}}
disabled={false}
mode={isDarkMode ? 'dark' : 'light'}
>
<ArrowBackIcon />
</NavBarButton>
</IconButton>

<NavBarButton
<IconButton
type="button"
onClick={() => {
socket?.emit('input:forward');
}}
disabled={false}
mode={isDarkMode ? 'dark' : 'light'}
>
<ArrowForwardIcon />
</NavBarButton>
</IconButton>

<NavBarButton
<IconButton
type="button"
onClick={() => {
if (socket) {
handleRefresh()
handleRefresh();
}
}}
disabled={false}
mode={isDarkMode ? 'dark' : 'light'}
>
<ReplayIcon />
</NavBarButton>
</IconButton>

<UrlForm
currentAddress={recordingUrl}
Expand Down
Loading