Skip to content

Commit cc38776

Browse files
committed
Fixes background bug
1 parent c3408b1 commit cc38776

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NotFoundPage from './pages/NotFoundPage';
1313
import { Helmet } from 'react-helmet-async';
1414
import HomePage from './pages/home/HomePage';
1515
import MainPageTemplate from './components/main/MainPageTemplate';
16+
import ConditionalBackground from './components/base/ConditionalBackground';
1617

1718
const loadableConfig = {
1819
fallback: <PageTemplate />,
@@ -62,6 +63,7 @@ const App: React.FC<AppProps> = (props) => {
6263
<meta property="fb:app_id" content="203040656938507" />
6364
<meta property="og:image" content="https://images.velog.io/velog.png" />
6465
</Helmet>
66+
<ConditionalBackground />
6567
<ErrorBoundary>
6668
<Switch>
6769
<Route path="/" component={HomePage} exact />

src/GlobalStyles.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ body {
1010
-moz-osx-font-smoothing: grayscale;
1111
color: ${themedPalette.text1};
1212
box-sizing: border-box;
13-
background: ${themedPalette.bg_page2};
13+
1414
}
1515
1616
* {
@@ -31,7 +31,6 @@ html, body, #root {
3131
}
3232
3333
body {
34-
background: ${themedPalette.bg_page2};
3534
${themes.light}
3635
}
3736
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { useMemo } from 'react';
3+
import { matchPath, useLocation } from 'react-router-dom';
4+
import { createGlobalStyle } from 'styled-components';
5+
import { themedPalette } from '../../lib/styles/themes';
6+
7+
interface Props {}
8+
9+
const GrayBackground = createGlobalStyle`
10+
body {
11+
background: ${themedPalette.bg_page1};
12+
}
13+
`;
14+
15+
const WhiteBackground = createGlobalStyle`
16+
body {
17+
background: ${themedPalette.bg_page2};
18+
}
19+
`;
20+
21+
/**
22+
* Bacgkround should be gray on following paths
23+
* - /
24+
* - /recent
25+
* - /lists
26+
*/
27+
function ConditionalBackground(props: Props) {
28+
const location = useLocation();
29+
30+
const isGray = useMemo(
31+
() =>
32+
[{ path: '/', exact: true }, '/recent', '/lists'].some((path) =>
33+
matchPath(location.pathname, path),
34+
),
35+
[location],
36+
);
37+
38+
return isGray ? <GrayBackground /> : <WhiteBackground />;
39+
}
40+
41+
export default ConditionalBackground;

src/components/main/MainTemplate.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import React from 'react';
2-
import styled, { createGlobalStyle } from 'styled-components';
3-
import { themedPalette } from '../../lib/styles/themes';
4-
5-
const BackgroundStyle = createGlobalStyle`
6-
body {
7-
background: ${themedPalette.bg_page1}!important;
8-
}
9-
`;
2+
import styled from 'styled-components';
103

114
export type MainTemplateProps = {
125
children: React.ReactNode;
@@ -15,7 +8,6 @@ export type MainTemplateProps = {
158
function MainTemplate({ children }: MainTemplateProps) {
169
return (
1710
<>
18-
<BackgroundStyle />
1911
<Block>{children}</Block>
2012
</>
2113
);

0 commit comments

Comments
 (0)