Skip to content

Commit 979adbe

Browse files
committed
fix(web): code scalability and abstractions
1 parent 3a3745a commit 979adbe

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

web/src/pages/Home/Header.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
import { useTheme } from "styled-components";
3+
import { useMeasure } from "react-use";
4+
import { BREAKPOINT_SMALL_SCREEN } from "styles/smallScreenStyle";
5+
import HeaderLightMobile from "tsx:svgs/header/header-lightmode-mobile.svg";
6+
import HeaderDarkMobile from "tsx:svgs/header/header-darkmode-mobile.svg";
7+
import HeaderLightDesktop from "tsx:svgs/header/header-lightmode-desktop.svg";
8+
import HeaderDarkDesktop from "tsx:svgs/header/header-darkmode-desktop.svg";
9+
10+
const Header = () => {
11+
const [ref, { width }] = useMeasure();
12+
const theme = useTheme();
13+
const themeIsLight = theme.name === "light";
14+
const breakpointIsBig = width > BREAKPOINT_SMALL_SCREEN;
15+
return (
16+
<div ref={ref}>
17+
{breakpointIsBig ? <HeaderDesktop themeIsLight={themeIsLight} /> : <HeaderMobile themeIsLight={themeIsLight} />}
18+
</div>
19+
);
20+
};
21+
22+
const HeaderDesktop: React.FC<{ themeIsLight: boolean }> = ({ themeIsLight }) => {
23+
return themeIsLight ? <HeaderLightDesktop /> : <HeaderDarkDesktop />;
24+
};
25+
26+
const HeaderMobile: React.FC<{ themeIsLight: boolean }> = ({ themeIsLight }) => {
27+
return themeIsLight ? <HeaderLightMobile /> : <HeaderDarkMobile />;
28+
};
29+
30+
export default Header;

web/src/pages/Home/index.tsx

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import React from "react";
2-
import styled, { useTheme } from "styled-components";
3-
import { useMeasure } from "react-use";
2+
import styled from "styled-components";
43
import CourtOverview from "./CourtOverview";
54
import LatestCases from "./LatestCases";
65
import Community from "./Community";
6+
import Header from "./Header";
77
import { HomePageProvider } from "hooks/useHomePageContext";
88
import { getOneYearAgoTimestamp } from "utils/date";
9-
import { BREAKPOINT_SMALL_SCREEN } from "styles/smallScreenStyle";
10-
import HeaderLightMobile from "tsx:svgs/header/header-lightmode-mobile.svg";
11-
import HeaderDarkMobile from "tsx:svgs/header/header-darkmode-mobile.svg";
12-
import HeaderLightDesktop from "tsx:svgs/header/header-lightmode-desktop.svg";
13-
import HeaderDarkDesktop from "tsx:svgs/header/header-darkmode-desktop.svg";
149

1510
const Container = styled.div`
1611
width: 100%;
@@ -19,26 +14,6 @@ const Container = styled.div`
1914
padding: 32px;
2015
`;
2116

22-
const Header = () => {
23-
const [ref, { width }] = useMeasure();
24-
const theme = useTheme();
25-
const themeIsLight = theme.name === "light";
26-
const breakpointIsBig = width > BREAKPOINT_SMALL_SCREEN;
27-
return (
28-
<div ref={ref}>
29-
{breakpointIsBig ? <HeaderDesktop themeIsLight={themeIsLight} /> : <HeaderMobile themeIsLight={themeIsLight} />}
30-
</div>
31-
);
32-
};
33-
34-
const HeaderDesktop: React.FC<{ themeIsLight: boolean }> = ({ themeIsLight }) => {
35-
return themeIsLight ? <HeaderLightDesktop /> : <HeaderDarkDesktop />;
36-
};
37-
38-
const HeaderMobile: React.FC<{ themeIsLight: boolean }> = ({ themeIsLight }) => {
39-
return themeIsLight ? <HeaderLightMobile /> : <HeaderDarkMobile />;
40-
};
41-
4217
const Home: React.FC = () => {
4318
return (
4419
<HomePageProvider timeframe={getOneYearAgoTimestamp()}>

0 commit comments

Comments
 (0)