Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
62eafdb
feat: Add routing features
kand193 Feb 14, 2021
d2c3c34
chore: Add ant.design library
kand193 Feb 15, 2021
34fca99
Merge pull request #3 from mash-up-kr-web/week4-baz-yjp
godjoy Feb 15, 2021
593bfbd
Add crypto-js module
minsour Feb 15, 2021
e6c9fcb
Add serialize and deserialize utils
minsour Feb 15, 2021
44ab695
Extract key as const
minsour Feb 16, 2021
8a2711a
Merge pull request #5 from mash-up-kr-web/week4-baz-minsour
kand193 Feb 16, 2021
adc5304
feat: Implement Game Page without result state
kand193 Feb 16, 2021
b3c462f
fix: Fix import order
kand193 Feb 16, 2021
c9cce45
fix: Add count variable
kand193 Feb 16, 2021
61cb2c1
Add frame of result page
minsour Feb 17, 2021
16873ec
Add logic for creating url
minsour Feb 17, 2021
e12d257
Add url copy logic using clipboard
minsour Feb 17, 2021
c7ed395
fix: Fix title for feedback
kand193 Feb 17, 2021
8fe1ada
Add messages
minsour Feb 17, 2021
5663000
Customize the OceanSelection to remove the cursor attribute from the …
minsour Feb 17, 2021
faab8f1
Merge pull request #8 from mash-up-kr-web/week4-baz-yjp
minsour Feb 17, 2021
9d99352
Merge branch 'week4-baz' into week4-baz-minsour
minsour Feb 17, 2021
d8308b5
Add user's name to messages
minsour Feb 17, 2021
bcee389
add ocean background
godjoy Feb 17, 2021
2798961
Index Name 관련 ContextAPI
godjoy Feb 17, 2021
c8a0a8a
add Index contents
godjoy Feb 17, 2021
6fe8899
prettier 적용
godjoy Feb 18, 2021
6d49b88
Merge pull request #13 from mash-up-kr-web/week4-baz-joy
godjoy Feb 18, 2021
ecfed44
Merge pull request #14 from mash-up-kr-web/week4-baz-minsour
kand193 Feb 18, 2021
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
587 changes: 579 additions & 8 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"antd": "4.12.3",
"axios": "0.21.0",
"classnames": "2.2.6",
"cross-env": "7.0.2",
"crypto-js": "4.0.0",
"fontfaceobserver": "2.1.0",
"husky": "4.3.0",
"lodash": "4.17.20",
"node-plop": "0.26.2",
"node-sass": "4.14.1",
"plop": "2.7.4",
"qs": "6.9.4",
"qs": "6.9.6",
"react": "17.0.1",
"react-app-polyfill": "2.0.0",
"react-dom": "17.0.1",
"react-helmet-async": "1.0.7",
"react-redux": "7.2.2",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.0",
"react-scripts": "4.0.2",
"react-test-renderer": "17.0.1",
"redux": "4.0.5",
"redux-saga": "1.1.3",
Expand All @@ -31,12 +33,14 @@
"stylelint-order": "4.1.0",
"stylelint-scss": "3.18.0",
"ts-node": "9.0.0",
"typescript": "4.0.5"
"typescript": "4.0.5",
"xml-js": "1.6.11"
},
"devDependencies": {
"@testing-library/jest-dom": "5.11.5",
"@testing-library/react": "11.1.0",
"@types/classnames": "2.2.10",
"@types/crypto-js": "4.0.1",
"@types/fontfaceobserver": "0.0.6",
"@types/jest": "26.0.15",
"@types/lodash": "4.14.162",
Expand Down Expand Up @@ -124,5 +128,5 @@
}
}
},
"proxy":"https://openapi.naver.com"
"proxy": "https://openapi.naver.com"
}
20 changes: 19 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
/* External dependencies */
import { IndexContextProvider } from 'components/index/IndexContext';
import IndexPage from 'pages';
import GamePage from 'pages/game';
import ResultPage from 'pages/result';
import React from 'react';
import { Route, BrowserRouter as Router, Switch } from 'react-router-dom';

function App() {
return <div>Hello World!</div>;
return (
<>
<IndexContextProvider>
<Router>
<Switch>
<Route exact path="/game" component={GamePage} />
<Route exact path="/result" component={ResultPage} />
<Route path="/" component={IndexPage} />
Comment on lines +15 to +17
Copy link
Member

Choose a reason for hiding this comment

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

이 부분을 좀 흥미로웠는데요! 제가 로직을 잘 이해못해서 그런지 모르겠지만. 저는 보통 path="/"exact 를 걸어두는데, 이 코드에서는 path="/" 제외한 곳에 exact 가 걸려있더라구요! 근데 이러면 일일이 Route 가 생성될때마다 exact 를 걸어주거나 하는등 유지보수 측면에서 안좋아 보이는데, exact 옵션을 저렇게 주신 이유가 있을까요?

Copy link
Collaborator

@danivelop danivelop Feb 19, 2021

Choose a reason for hiding this comment

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

저도 이렇게 써본적은 없는데 이렇게 '/'에 exact를 안넣고 마지막에 위치시키면 약간 404페이지 느낌으로 아무 route에나 접근해도 IndexPage띄울순 있겠군요! 가끔씩 404페이지 따로 없을때 이렇게 써봐야겠네요ㅎㅎ

</Switch>
</Router>
</IndexContextProvider>

</>
);
}

export default App;
Binary file added src/assets/ocean.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions src/components/OceanSelection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import styled from 'styled-components';

import OceanInfo from 'types/OceanInfo';

interface OceanSelectionProps extends React.HTMLProps<HTMLDivElement> {
ocean: OceanInfo;
isResult?: boolean;
}

// TODO: 선택시 인터렉션 필요
const OceanSelection = ({ ocean, isResult, onClick }: OceanSelectionProps) => (
<Selection isResult={isResult} onClick={onClick}>
<img src={ocean.imageSrc} alt="ocean" />
<Title>{ocean.name}</Title>
<Description>{ocean.description}</Description>
</Selection>
);

export default OceanSelection;

const Selection = styled.div<{ isResult?: boolean }>`
position: relative;
width: 50%;
height: 100%;
background-color: blue;
border: 1px solid black;
cursor: ${props => (props.isResult ? '' : 'pointer')};

> img {
width: 100%;
height: 100%;
}
`;

const Title = styled.div`
position: absolute;
width: 100%;
top: 30px;
color: white;
text-align: center;
font-size: 30px;
font-weight: bold;
`;

const Description = styled.div`
position: absolute;
width: 100%;
bottom: 30px;
color: white;
text-align: center;
font-size: 20px;
font-weight: bold;
`;
54 changes: 54 additions & 0 deletions src/components/index/IndexContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { createContext, Dispatch, useContext, useReducer } from 'react';

export type State = {
name: string;
};

type Action = { type: 'SET_NAME'; name: string };

type IndexDispatch = Dispatch<Action>;

const IndexStateContext = createContext<State | undefined>(undefined);
const IndexDispatchContext = createContext<IndexDispatch | undefined>(
undefined,
);

function reducer(state: State, action: Action): State {
switch (action.type) {
case 'SET_NAME':
return {
name: action.name,
};
default:
throw new Error('Unhandled action');
}
}

export function IndexContextProvider({
children,
}: {
children: React.ReactNode;
}) {
const initialState: State = { name: '' };
const [state, dispatch] = useReducer(reducer, initialState);

return (
<IndexStateContext.Provider value={state}>
<IndexDispatchContext.Provider value={dispatch}>
Comment on lines +36 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 저는 보통 하나의 context에 state와 dispatch를 묶어서 보냈는데 이렇게 분리시키는것도 좋아보이네요

{children}
</IndexDispatchContext.Provider>
</IndexStateContext.Provider>
);
}

export function useIndexState() {
const state = useContext(IndexStateContext);
if (!state) throw new Error('IndexProvider not found');
return state;
}

export function useIndexDispatch() {
const dispatch = useContext(IndexDispatchContext);
if (!dispatch) throw new Error('IndexProvider not found');
return dispatch;
}
54 changes: 54 additions & 0 deletions src/components/index/OceanBackground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import styled from 'styled-components';
import ocean from '../../assets/ocean.jpg';

const OceanBackground = () => (
<>
<svg
width="0"
height="0"
xmlns="http://www.w3.org/2000/svg"
xlinkHref="http://www.w3.org/1999/xlink"
>
<filter id="water">
<feTurbulence
type="fractalNoise"
baseFrequency=".05 .05"
numOctaves="1"
result="noise1"
/>
<feColorMatrix in="noise1" type="hueRotate" values="0" result="noise2">
<animate
attributeName="values"
from="0"
to="360"
dur="1s"
repeatCount="indefinite"
/>
</feColorMatrix>
<feDisplacementMap
xChannelSelector="R"
yChannelSelector="G"
scale="7"
in="SourceGraphic"
in2="noise2"
/>
</filter>
</svg>
<BackgroundImg src={ocean} alt="ocean Image" />
</>
);

export default OceanBackground;

const BackgroundImg = styled.img`
width: 105vw;
height: 105vh;
position: absolute;
top: -5vh;
left: -5vw;
object-fit: cover;
filter: url(#water);
position: absolute;
z-index: -1;
`;
88 changes: 88 additions & 0 deletions src/components/index/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Button, Input } from 'antd';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { useIndexDispatch } from './IndexContext';

interface IndexProps {
isValid: boolean;
name: string;
}

function NameExistComp(props) {
const name = props.name;
return (
<>
<Title>{name} 님의 초대</Title>;
<Link to="/game">
<StartButton>🎮start🎮</StartButton>
</Link>
</>
);
}

function NameNotExistComp() {
const [value, setValue] = useState('');
const dispatch = useIndexDispatch();

const handleSubmit = () => {
dispatch({ type: 'SET_NAME', name: value });
};

return (
<>
<form onSubmit={handleSubmit}>
<StyledInput
value={value}
placeholder="이름을 입력해 주세요."
onChange={e => setValue(e.target.value)}
/>
<br />
<Link to="/game">
<StartButton onClick={handleSubmit}>🎮start🎮</StartButton>
</Link>
</form>
</>
);
}

function Contents({ isValid, name }: IndexProps) {
if (isValid) {
return <NameExistComp name={name} />;
} else {
return <NameNotExistComp />;
}
}

function IndexContents(props: IndexProps) {
const isValid = props.isValid;
const name = props.name;
return (
<>
<Contents isValid={isValid} name={name} />
</>
);
}

export default IndexContents;

const Title = styled.div`
margin-top: 400px;
font-weight: bolder;
font-size: 30pt;
`;

const StyledInput = styled(Input)`
margin-top: 400px;
width: 200px;
height: 50px;
`;

const StartButton = styled(Button)`
margin-top: 20px;
width: 200px;
height: 50px;
font-weight: bolder;
font-size: 20pt;
text-align: center;
`;
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { HelmetProvider } from 'react-helmet-async';
import App from 'App';
import * as serviceWorker from 'serviceWorker';
import 'sanitize.css/sanitize.css';
import 'antd/dist/antd.css';

ReactDOM.render(
<HelmetProvider>
Expand Down
Loading