Skip to content

Commit

Permalink
Merge branch 'client-web/master' of https://github.com/connect-founda…
Browse files Browse the repository at this point in the history
…tion/2019-20 into client-web/search-view
  • Loading branch information
kgpyo committed Dec 12, 2019
2 parents 00463ee + 20415ba commit 209f682
Show file tree
Hide file tree
Showing 43 changed files with 2,386 additions and 57 deletions.
8 changes: 5 additions & 3 deletions web-apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.7.1",
"@material-ui/core": "^4.7.0",
"@material-ui/icons": "^4.5.1",
"axios": "^0.19.0",
"clsx": "^1.0.4",
"immer": "^5.0.0",
"intersection-observer": "^0.7.0",
"prop-types": "^15.7.2",
"query-string": "^6.9.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-redux": "^7.1.3",
Expand All @@ -18,7 +19,8 @@
"redux-actions": "^2.6.5",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"socket.io-client": "^2.3.0"
},
"lint-staged": {
"*/*.js": [
Expand Down
46 changes: 33 additions & 13 deletions web-apps/client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import './App.css';

import { Grid } from '@material-ui/core';
// pages
import { ThemeProvider, makeStyles } from '@material-ui/core/styles';
import { Grid } from '@material-ui/core';
import TmpChat from './pages/TmpChat';
import ChatRoom from './pages/ChatRoom';
import Home from './pages/main';
import Filters from './pages/filters';
import Location from './pages/area';
import NewProduct from './pages/newProduct';

import { FilterProvider } from './contexts/filters';
import { SnackbarProvider } from './contexts/snackbar';

import Navigator from './pages/navigator';
import NoticeBar from './pages/notice';
import Router from './router';

import muiTheme from './theme/muiTheme';
import theme from './theme';

import './style.css';

const useStyles = makeStyles({
Expand All @@ -21,20 +30,31 @@ const useStyles = makeStyles({
});

export default () => {
const classes = useStyles();
const classes = useStyles({});
return (
<BrowserRouter>
<SnackbarProvider>
<FilterProvider>
<ThemeProvider theme={theme}>
<SnackbarProvider>
<FilterProvider>
<Router>
<Switch>
<Grid container className={classes.root}>
<Router />
<Navigator />
<ThemeProvider theme={theme}>
<Route exact path='/' component={Home} />
<Route exact path='/category' component={Filters} />
<Route exact path='/location' component={Location} />
</ThemeProvider>
<ThemeProvider theme={muiTheme}>
<Route exact path='/chat' component={TmpChat} />
<Route path='/chat/room/:id' Component={ChatRoom} />
</ThemeProvider>
<Route exact path='/write' component={NewProduct} />
</Grid>
</Switch>
<ThemeProvider theme={theme}>
<Navigator />
<NoticeBar />
</ThemeProvider>
</FilterProvider>
</SnackbarProvider>
</BrowserRouter>
</Router>
</FilterProvider>
</SnackbarProvider>
);
};
4 changes: 4 additions & 0 deletions web-apps/client/src/assets/uris.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const imageHandleURI = 'http://localhost:5000/products/picture';
const productHandleURI = 'http://localhost:5000/products';
const loginStatusHandleURI = 'http://localhost:5001/myInfo';
export {imageHandleURI, productHandleURI, loginStatusHandleURI};
83 changes: 83 additions & 0 deletions web-apps/client/src/components/ChatBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import {bool, string} from 'prop-types';

// material ui
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
import Avatar from '@material-ui/core/Avatar';
import Typography from '@material-ui/core/Typography';
import {makeStyles} from '@material-ui/core/styles';

// utils
import {getKoKRFormatDayOfWeek, getISOCurrentDate} from '../utils';

// material ui style
const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
overflow: 'hidden',
padding: theme.spacing(0, 3),
},
paper: {
maxWidth: 400,
margin: `${theme.spacing(1)}px`,
padding: theme.spacing(1),
fontWeight: 'bold',
},
colorPaper: {
backgroundColor: 'grey',
color: 'white',
},
}));

// component
const ChatBox = ({content, isMyChat, timestamp}) => {
const classes = useStyles({});

return (
<div className={classes.root}>
<Grid container alignItems='center'>
{!isMyChat && (
<Grid item>
<Avatar>상대방</Avatar>
</Grid>
)}
<Grid item>
<Grid
container
direction={!isMyChat ? 'row' : 'row-reverse'}
alignItems='flex-end'
>
<Grid item>
<Paper
className={`${classes.paper} ${!isMyChat &&
classes.colorPaper}`}
>
<Typography>{content}</Typography>
</Paper>
</Grid>
<Grid item>
<Typography variant='caption'>
{getKoKRFormatDayOfWeek(timestamp)}
</Typography>
</Grid>
</Grid>
</Grid>
</Grid>
</div>
);
};

ChatBox.propTypes = {
content: string,
isMyChat: bool,
timestamp: string,
};

ChatBox.defaultProps = {
content: '',
isMyChat: false,
timestamp: getISOCurrentDate(),
};

export default ChatBox;
69 changes: 69 additions & 0 deletions web-apps/client/src/components/ChatInputField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';
import {func} from 'prop-types';

// material ui
import {makeStyles} from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import InputBase from '@material-ui/core/InputBase';
import IconButton from '@material-ui/core/IconButton';
import SendIcon from '@material-ui/icons/Send';

// types
import {refType} from '../types';

// material ui style
const useStyles = makeStyles((theme) => ({
root: {
padding: '2px 4px',
display: 'flex',
alignItems: 'center',
width: '100%',
position: 'fixed',
bottom: '0',
right: '0',
zIndex: 100,
backgroundColor: 'lightgreen',
},
input: {
marginLeft: theme.spacing(1),
flex: 1,
},
iconButton: {
padding: 10,
color: 'white',
},
}));

// component
const ChatInputField = ({onMessageSubmit, chatInputRef}) => {
const classes = useStyles({});

return (
<Paper component='form' className={classes.root} onSubmit={onMessageSubmit}>
<InputBase
className={classes.input}
placeholder='메세지를 입력하세요.'
inputRef={chatInputRef}
/>
<IconButton
type='submit'
className={classes.iconButton}
aria-label='search'
>
<SendIcon />
</IconButton>
</Paper>
);
};

ChatInputField.propTypes = {
onMessageSubmit: func,
chatInputRef: refType,
};

ChatInputField.defaultProps = {
onMessageSubmit: () => {},
chatInputRef: null,
};

export default ChatInputField;
55 changes: 55 additions & 0 deletions web-apps/client/src/components/ChatList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import {arrayOf} from 'prop-types';

// material ui
import {makeStyles} from '@material-ui/core/styles';

// components
import ChatRow from './ChatRow';

// types
import {uIdType, messageShape} from '../types';

// utils
import {getISOCurrentDate} from '../utils';

// material ui style
const useStyles = makeStyles(() => ({
ul: {
backgroundColor: 'inherit',
padding: 0,
},
}));

// component
export default function ChatList({messages, currentUser}) {
const classes = useStyles({});

return (
<ul className={classes.ul}>
{messages.map((message) => (
<ChatRow
key={`item-${message.timestamp}`}
message={message}
currentUser={currentUser}
/>
))}
</ul>
);
}

ChatList.propTypes = {
messages: arrayOf(messageShape),
currentUser: uIdType,
};

ChatList.defaultProps = {
messages: [
{
timestamp: getISOCurrentDate(),
content: '',
userId: null,
},
],
currentUser: null,
};
50 changes: 50 additions & 0 deletions web-apps/client/src/components/ChatRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';

// material ui
import ListItem from '@material-ui/core/ListItem';
import Grid from '@material-ui/core/Grid';

// components
import ChatBox from './ChatBox';

// utils
import {getISOCurrentDate} from '../utils';

// types
import {uIdType, messageShape} from '../types';

// component
const ChatRow = ({message: {userId, content, timestamp}, currentUser}) => (
<ListItem>
<Grid
container
direction='row'
justify={currentUser === userId ? 'flex-end' : 'flex-start'}
alignItems='center'
>
<Grid item>
<ChatBox
content={content}
timestamp={timestamp}
isMyChat={currentUser === userId}
/>
</Grid>
</Grid>
</ListItem>
);

ChatRow.propTypes = {
message: messageShape,
currentUser: uIdType,
};

ChatRow.defaultProps = {
message: {
timestamp: getISOCurrentDate(),
content: '',
userId: null,
},
currentUser: null,
};

export default ChatRow;
Loading

0 comments on commit 209f682

Please sign in to comment.