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

Support dark mode #167

Merged
merged 6 commits into from
Jul 23, 2024
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
6 changes: 6 additions & 0 deletions client/src/Annotation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SetupPage from "../SetupPage"
import { useSettings } from "../SettingsProvider"
import { setIn } from "seamless-immutable"
import config from "../config.js"
import { CssBaseline } from "@mui/material"
import { useSnackbar } from "../SnackbarContext"
import { getImagesAnnotation } from "../utils/send-data-to-server"
import CircularProgress from "@mui/material/CircularProgress"
Expand All @@ -12,6 +13,8 @@ import AlertDialog from "../AlertDialog"
import { clear_db, getSettings } from "../utils/get-data-from-server"
import colors from "../colors.js"
import { useTranslation } from "react-i18next"
import { themes } from "../Theme"
import { useTheme } from '../ThemeContext'

const extractRelevantProps = (region) => ({
cls: region.cls,
Expand Down Expand Up @@ -63,6 +66,7 @@ export default () => {
const settingsConfig = useSettings()
const [isLoading, setIsLoading] = useState(true)
const { showSnackbar } = useSnackbar()
const { toggleTheme, theme } = useTheme();
const [settings, setSettings] = useState({
taskDescription: "",
taskChoice: "image_classification",
Expand Down Expand Up @@ -306,6 +310,7 @@ export default () => {

return (
<>
<CssBaseline />
{!showLabel ? (
<SetupPage
setConfiguration={setConfiguration}
Expand Down Expand Up @@ -368,6 +373,7 @@ export default () => {
setIsSettingsOpen(!isSettingsOpen)
setShowLabel(false)
}}
rootTheme={themes[theme]}
selectedImageIndex={selectedImageIndex}
/>
</>
Expand Down
2 changes: 1 addition & 1 deletion client/src/Annotation/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
editBar: {
padding: 10,
borderBottom: "1px solid #ccc",
backgroundColor: "#f8f8f8",
// backgroundColor: "#f8f8f8",
display: "flex",
alignItems: "center",
"& .button": { margin: 5 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ jest.mock("../utils/get-data-from-server", () => ({
getLabels: jest.fn(),
}))

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));
// Mocking the useTranslation hook
jest.mock("react-i18next", () => ({
useTranslation: () => ({
Expand Down
57 changes: 33 additions & 24 deletions client/src/ClassDistributionSidebarBox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import React, { useEffect, useState } from "react"
import { createTheme, ThemeProvider } from "@mui/material/styles"
import SidebarBoxContainer from "../SidebarBoxContainer"
import BarChartIcon from "@mui/icons-material/BarChart"
import { grey } from "@mui/material/colors"
import { grey, deepOrange } from "@mui/material/colors"
import { useTranslation } from "react-i18next"
import { BarChart } from "@mui/x-charts/BarChart"
import RefreshIcon from "@mui/icons-material/Refresh"
import IconButton from "@mui/material/IconButton"
import Paper from "@mui/material/Paper"
import { getLabels } from "../utils/get-data-from-server"
import colors from "../colors"

const theme = createTheme()
import { useTheme } from "../ThemeContext"
import { themes } from "../Theme"
export const ClassDistributionSidebarBox = ({ regionClsList, shouldExpand=false }) => {
const { t } = useTranslation()
const { theme } = useTheme()
const newTheme = createTheme({ palette: { mode: theme } });

const [labelsInfo, setLabelsInfo] = useState([])
const assignRandomColors = (responseList, classList) => {
let coloredResponse = []
Expand Down Expand Up @@ -55,13 +58,6 @@ export const ClassDistributionSidebarBox = ({ regionClsList, shouldExpand=false
fetchData()
}

const barChartsParams = {
slotProps: {
legend: {
hidden: true,
},
},
}

const CustomItemTooltipContent = (props) => {
const { itemData, series } = props
Expand All @@ -75,10 +71,23 @@ export const ClassDistributionSidebarBox = ({ regionClsList, shouldExpand=false
</Paper>
)
}
const darkMode = theme === themes.dark;
const barChartsParams = {
slotProps: {
legend: {
hidden: true,
label: {
style: {
color: darkMode ? "#ffffff" : "#000000",
},
},
},
},
};

return (
<ThemeProvider theme={theme}>
<SidebarBoxContainer
<ThemeProvider theme={newTheme}>
<SidebarBoxContainer
title={t("menu.class_distribution")}
icon={<BarChartIcon style={{ color: grey[700] }} />}
noScroll={true}
Expand All @@ -93,24 +102,24 @@ export const ClassDistributionSidebarBox = ({ regionClsList, shouldExpand=false
}}
>
<BarChart
xAxis={[
{
scaleType: "band",
data: [t("menu.classifications")],
labelFontSize: 10,
hideTooltip: true,
},
]}
yAxis={[
{ label: t("menu.class_distribution_count"), labelFontSize: 10 },
]}
xAxis={[
{
scaleType: "band",
data: [t("menu.classifications")],
labelFontSize: 10,
hideTooltip: true,
},
]}
yAxis={[
{ label: t("menu.class_distribution_count"), labelFontSize: 10 },
]}
series={labelsInfo}
width={300}
height={300}
{...barChartsParams}
tooltip={{ trigger: "item", itemContent: CustomItemTooltipContent }}
/>
<IconButton aria-label="refresh" onClick={handleRefreshClick}>
<IconButton aria-label="refresh" onClick={handleRefreshClick} color="inherit">
<RefreshIcon />
</IconButton>
</div>
Expand Down
8 changes: 8 additions & 0 deletions client/src/ClassSelectionMenu/ClassSelectionMenu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ jest.mock("react-i18next", () => ({
}),
}))

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));

describe("ClassSelectionMenu", () => {
it("renders correctly", () => {
const { getByText } = render(
Expand Down
2 changes: 1 addition & 1 deletion client/src/ClassSelectionMenu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const LabelContainer = styled("div")(({ theme }) => ({
alignItems: "center",
cursor: "pointer",
opacity: 0.7,
backgroundColor: "#fff",
// backgroundColor: "#fff",
"&:hover": {
opacity: 1,
},
Expand Down
9 changes: 9 additions & 0 deletions client/src/DebugSidebarBox/DebugSidebarBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { render } from "@testing-library/react"
import "@testing-library/jest-dom"
import DebugSidebarBox from "./index"

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));


describe("DebugSidebarBox", () => {
const mockState = {
images: [
Expand Down
9 changes: 9 additions & 0 deletions client/src/FilesListMenu/FilesListMenu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ jest.mock("react-i18next", () => ({
}),
}))

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));


describe("FilesListMenu", () => {
const state = {
annotationType: "image",
Expand Down
4 changes: 2 additions & 2 deletions client/src/FilesListMenu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const LabelContainer = styled("div")(({ theme }) => ({
alignItems: "center",
cursor: "pointer",
opacity: 0.7,
backgroundColor: "#fff",
// backgroundColor: "#fff",
"&:hover": {
opacity: 1,
},
Expand Down Expand Up @@ -100,7 +100,7 @@ export const FilesListMenu = ({
padding: 0,
"& .MuiSvgIcon-root": {
fontSize: 14, // Set size
color: image.processed ? "green" : "", // Set color conditionally
color: image.processed ? "green" : "#1976d2", // Set color conditionally
},
cursor:
selectedImage !== null && selectedImage !== index
Expand Down
8 changes: 8 additions & 0 deletions client/src/HistorySidebarBox/HistorySidebarBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jest.mock("react-i18next", () => ({
}),
}))

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));

describe("HistorySidebarBox", () => {
const history = [
{ name: "History 1", time: new Date("2022-06-15T12:00:00Z") },
Expand Down
3 changes: 2 additions & 1 deletion client/src/HistorySidebarBox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const theme = createTheme()
const EmptyTextDiv = styled("div")(() => ({
fontSize: 14,
fontWeight: "bold",
color: grey[500],
// color: grey[500],
textAlign: "center",
padding: 20,
}))
Expand All @@ -30,6 +30,7 @@ const listItemTextStyle = {
fontSize: 11,
paddingTop: 0,
paddingBottom: 0,
color: "inherit",
}

export const HistorySidebarBox = ({ history, onRestoreHistory }) => {
Expand Down
3 changes: 2 additions & 1 deletion client/src/ImageUpload/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useState } from "react"
import { useDropzone } from "react-dropzone"
import { createTheme } from "@mui/material/styles"
import { Box, Typography, IconButton } from "@mui/material"
import { CssBaseline, Box, Typography, IconButton } from "@mui/material"
import DeleteIcon from "@mui/icons-material/Delete"
import axios from "axios"
import { useSnackbar } from "../SnackbarContext"
Expand Down Expand Up @@ -157,6 +157,7 @@ const ImageUpload = ({ onImageUpload, settingsImages }) => {

return (
<>
<CssBaseline />
<Box
{...getRootProps()}
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ jest.mock("react-i18next", () => ({
}),
}))

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));

describe("KeyframesSelectorSidebarBox", () => {
const mockOnChangeVideoTime = jest.fn()
const mockOnDeleteKeyframe = jest.fn()
Expand Down
8 changes: 4 additions & 4 deletions client/src/MainLayout/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { grey } from "@mui/material/colors"

export default {
container: {
display: "flex",
flexGrow: 1,
flexDirection: "column",
// display: "flex",
// flexGrow: 1,
// flexDirection: "column",
height: "100%",
maxHeight: "100vh",
backgroundColor: "#fff",

overflow: "hidden",
},
headerTitle: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ jest.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key) => key }),
}))

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));

describe("RegionSelectorSidebarBox", () => {
const mockRegions = [
{
Expand Down
2 changes: 1 addition & 1 deletion client/src/RegionSelectorSidebarBox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ChipSpan = styled("span")(() => styles.chip)
const RowDiv = styled("div")(() => styles.row)
const ContainerDiv = styled("div")(() => styles.container)
const HeaderSep = styled("div")(({ theme }) => ({
borderTop: `1px solid ${grey[200]}`,
// borderTop: `1px solid ${grey[200]}`,
marginTop: 2,
marginBottom: 2,
}))
Expand Down
2 changes: 1 addition & 1 deletion client/src/RegionSelectorSidebarBox/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
padding: 4,
cursor: "pointer",
"&.header:hover": {
backgroundColor: "#fff",
// backgroundColor: "#fff",
},
"&.highlighted": {
backgroundColor: blue[100],
Expand Down
4 changes: 2 additions & 2 deletions client/src/RegionTags/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ export const RegionTags = ({
left: 0,
...(displayOnTop ? { bottom: 0 } : { top: 0 }),
zIndex: 10,
backgroundColor: "#fff",
// backgroundColor: "#fff",
borderRadius: 4,
padding: 2,
paddingBottom: 0,
opacity: 0.5,
pointerEvents: "none",
}}
>
<LockIcon style={{ width: 16, height: 16, color: "#333" }} />
<LockIcon style={{ width: 16, height: 16}} />
</Paper>
</div>
)
Expand Down
8 changes: 8 additions & 0 deletions client/src/SetupPage/SetupPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import "@testing-library/jest-dom"
import { SetupPage } from "./index"
import { useSettings } from "../SettingsProvider"

// Mock the useTheme hook
jest.mock('../ThemeContext', () => ({
useTheme: () => ({
theme: 'light', // Provide mock theme
toggleTheme: jest.fn(), // Mock function
}),
}));

// Mock useTranslation hook
jest.mock("react-i18next", () => ({
useTranslation: () => ({
Expand Down
Loading
Loading