Skip to content

Commit

Permalink
More consistent CSS styling, remove unnecessary code (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
chennisden authored Jun 18, 2024
1 parent 62f6b44 commit 92bd77c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 79 deletions.
34 changes: 34 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,37 @@ p.card-text {
display: -webkit-box;
-webkit-box-orient: vertical;
}

.btn-primary {
background-color: white;
color: #0d6efd;
border-color: #0d6efd;
}

body.dark-mode .btn-primary {
background-color: black;
color: #8ab9fe;
border-color: #8ab9fe;
}

body.dark-mode .btn-primary:hover {
background-color: #8ab9fe;
color: #201a42;
}

.btn-danger {
background-color: white;
color: #dc3545;
border-color: #dc3545;
}

body.dark-mode .btn-danger {
background-color: black;
color: #f0cbce;
border-color: #f0cbce;
}

body.dark-mode .btn-danger:hover {
background-color: #f0cbce;
color: #201a42;
}
9 changes: 8 additions & 1 deletion frontend/src/components/PartForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Image } from "hooks/api";
import { Theme } from "hooks/theme";
import { ChangeEvent, Dispatch, FormEvent, SetStateAction } from "react";
import { Button, Col, Form, Row } from "react-bootstrap";
import ImageUploadComponent from "./files/UploadImage";

interface PartFormProps {
theme: Theme;
title: string;
message: string;
part_name: string;
Expand All @@ -16,6 +18,7 @@ interface PartFormProps {
}

const PartForm: React.FC<PartFormProps> = ({
theme,
title,
message,
part_name,
Expand Down Expand Up @@ -108,7 +111,11 @@ const PartForm: React.FC<PartFormProps> = ({
</Row>
))}
<Col>
<Button className="mb-3" variant="secondary" onClick={handleAddImage}>
<Button
className="mb-3"
variant={theme === "dark" ? "outline-light" : "outline-dark"}
onClick={handleAddImage}
>
Add Image
</Button>
</Col>
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/components/RobotForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Bom, Image, Part } from "hooks/api";
import { Theme } from "hooks/theme";
import { ChangeEvent, Dispatch, FormEvent, SetStateAction } from "react";
import { Button, Col, Form, Row } from "react-bootstrap";
import ImageUploadComponent from "./files/UploadImage";

interface RobotFormProps {
theme: Theme;
title: string;
message: string;
robot_name: string;
Expand All @@ -25,6 +27,7 @@ interface RobotFormProps {
}

const RobotForm: React.FC<RobotFormProps> = ({
theme,
title,
message,
robot_name,
Expand Down Expand Up @@ -183,7 +186,11 @@ const RobotForm: React.FC<RobotFormProps> = ({
</Row>
))}
<Col>
<Button className="mb-3" variant="secondary" onClick={handleAddImage}>
<Button
className="mb-3"
variant={theme === "dark" ? "outline-light" : "outline-dark"}
onClick={handleAddImage}
>
Add Image
</Button>
</Col>
Expand Down Expand Up @@ -233,7 +240,11 @@ const RobotForm: React.FC<RobotFormProps> = ({
</Row>
))}
<Col>
<Button className="mb-3" variant="secondary" onClick={handleAddBom}>
<Button
className="mb-3"
variant={theme === "dark" ? "outline-light" : "outline-dark"}
onClick={handleAddBom}
>
Add Part
</Button>
</Col>
Expand Down
49 changes: 3 additions & 46 deletions frontend/src/hooks/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
import {
createContext,
ReactNode,
useContext,
useEffect,
useState,
} from "react";
import { createContext, ReactNode, useContext, useState } from "react";

type Theme = "light" | "dark";
export type Theme = "light" | "dark";

const THEME_KEY = "__THEME";

interface ThemeColors {
backgroundColor: string;
color: string;
buttonBorder: string;
buttonHover: string;
text_color: string;
}

const COLORS: { [key in Theme]: ThemeColors } = {
light: {
backgroundColor: "#ffffff",
color: "#201a42",
buttonBorder: "#0D6EFD",
buttonHover: "#0D6EFD",
text_color: "#f5f2ef",
},
dark: {
backgroundColor: "#000000",
color: "#f5f2ef",
buttonBorder: "#8AB9FE",
buttonHover: "#0D6EFD",
text_color: "#201a42",
},
};

const getThemeFromLocalStorage = (): Theme => {
const theme = localStorage.getItem(THEME_KEY);
if (theme === null) {
Expand All @@ -50,7 +19,6 @@ const setThemeWithLocalStorage = (theme: Theme) => {
interface ThemeContextProps {
theme: Theme;
setTheme: (theme: Theme) => void;
colors: ThemeColors;
}

const ThemeContext = createContext<ThemeContextProps | undefined>(undefined);
Expand All @@ -68,19 +36,8 @@ export const ThemeProvider = (props: ThemeProviderProps) => {
setTheme(theme);
setThemeWithLocalStorage(theme);
};

useEffect(() => {
document.body.setAttribute("data-bs-theme", theme);
document.body.classList.toggle("dark-mode", theme === "dark");
document.body.classList.toggle("light-mode", theme === "light");
document.body.style.backgroundColor = COLORS[theme].backgroundColor;
document.body.style.color = COLORS[theme].color;
}, [theme, COLORS]);

return (
<ThemeContext.Provider
value={{ theme, setTheme: setThemeWrapper, colors: COLORS[theme] }}
>
<ThemeContext.Provider value={{ theme, setTheme: setThemeWrapper }}>
{children}
</ThemeContext.Provider>
);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/EditPartForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { humanReadableError } from "constants/backend";
import { useAlertQueue } from "hooks/alerts";
import { api, Image, Part } from "hooks/api";
import { useAuthentication } from "hooks/auth";
import { useTheme } from "hooks/theme";
import React, { FormEvent, useEffect, useState } from "react";
import { useNavigate, useParams } from "react-router-dom";

const EditPartForm: React.FC = () => {
const { theme } = useTheme();
const auth = useAuthentication();
const auth_api = new api(auth.api);

Expand Down Expand Up @@ -62,6 +64,7 @@ const EditPartForm: React.FC = () => {

return (
<PartForm
theme={theme}
title="Edit Part"
message={message}
part_name={Part_name}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/EditRobotForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { humanReadableError } from "constants/backend";
import { useAlertQueue } from "hooks/alerts";
import { api, Bom, Image, Part, Robot } from "hooks/api";
import { useAuthentication } from "hooks/auth";
import { useTheme } from "hooks/theme";
import React, { FormEvent, useEffect, useState } from "react";
import { useNavigate, useParams } from "react-router-dom";

const EditRobotForm: React.FC = () => {
const { theme } = useTheme();
const auth = useAuthentication();
const auth_api = new api(auth.api);

Expand Down Expand Up @@ -88,6 +90,7 @@ const EditRobotForm: React.FC = () => {

return (
<RobotForm
theme={theme}
title="Edit Robot"
robot_name={robot_name}
setName={setName}
Expand Down
32 changes: 2 additions & 30 deletions frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { useAuthentication } from "hooks/auth";
import { useTheme } from "hooks/theme";
import React, { useState } from "react";
import React from "react";
import { Button, Card, Col, Row } from "react-bootstrap";
import { useNavigate } from "react-router-dom";

const Home: React.FC = () => {
const { theme, colors } = useTheme();
const { theme } = useTheme();
const navigate = useNavigate();
const { isAuthenticated } = useAuthentication();

const [isHoveredR, setIsHoveredR] = useState(false);

const handleMouseEnterR = () => setIsHoveredR(true);
const handleMouseLeaveR = () => setIsHoveredR(false);

const [isHoveredL, setIsHoveredL] = useState(false);

const handleMouseEnterL = () => setIsHoveredL(true);
const handleMouseLeaveL = () => setIsHoveredL(false);

return (
<div className="flex-column pt-5 gap-4" style={{ display: "flex" }}>
<Row className="mb-4">
Expand Down Expand Up @@ -51,9 +41,6 @@ const Home: React.FC = () => {
variant={theme === "dark" ? "outline-light" : "outline-dark"}
size="lg"
style={{
backgroundColor: "light-purple",
borderColor: "secondary",
padding: "10px",
width: "100%",
}}
onClick={() => {
Expand All @@ -68,9 +55,6 @@ const Home: React.FC = () => {
variant={theme === "dark" ? "outline-light" : "outline-dark"}
size="lg"
style={{
backgroundColor: "dark-purple",
borderColor: "secondary",
padding: "10px",
width: "100%",
}}
onClick={() => {
Expand All @@ -87,14 +71,8 @@ const Home: React.FC = () => {
variant="outline-primary"
size="lg"
style={{
color: isHoveredR ? colors.text_color : colors.buttonBorder,
backgroundColor: isHoveredR ? colors.buttonBorder : "",
borderColor: colors.buttonBorder,
padding: "10px",
width: "100%",
}}
onMouseEnter={handleMouseEnterR}
onMouseLeave={handleMouseLeaveR}
onClick={() => {
navigate("/robots/add");
}}
Expand All @@ -107,14 +85,8 @@ const Home: React.FC = () => {
variant="outline-primary"
size="lg"
style={{
color: isHoveredL ? colors.text_color : colors.buttonBorder,
backgroundColor: isHoveredL ? colors.buttonBorder : "",
borderColor: colors.buttonBorder,
padding: "10px",
width: "100%",
}}
onMouseEnter={handleMouseEnterL}
onMouseLeave={handleMouseLeaveL}
onClick={() => {
navigate("/parts/add");
}}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/NewPart.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import PartForm from "components/PartForm";
import { api, Image, Part } from "hooks/api";
import { useAuthentication } from "hooks/auth";
import { useTheme } from "hooks/theme";
import React, { FormEvent, useState } from "react";
import { useNavigate } from "react-router-dom";

const NewPart: React.FC = () => {
const { theme } = useTheme();
const auth = useAuthentication();
const auth_api = new api(auth.api);
const [message, setMessage] = useState<string>("");
Expand Down Expand Up @@ -37,6 +39,7 @@ const NewPart: React.FC = () => {

return (
<PartForm
theme={theme}
title="Add a New Part"
message={message}
part_name={part_name}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/NewRobot.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import RobotForm from "components/RobotForm";
import { api, Bom, Image, Part, Robot } from "hooks/api";
import { useAuthentication } from "hooks/auth";
import { useTheme } from "hooks/theme";
import React, { FormEvent, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

const NewRobot: React.FC = () => {
const { theme } = useTheme();
const auth = useAuthentication();
const auth_api = new api(auth.api);
const [message, setMessage] = useState<string>("");
Expand Down Expand Up @@ -58,6 +60,7 @@ const NewRobot: React.FC = () => {

return (
<RobotForm
theme={theme}
title="Add a New Robot"
robot_name={robot_name}
setName={setName}
Expand Down

0 comments on commit 92bd77c

Please sign in to comment.