Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 84025e0

Browse files
committed
Prepares Series Editor component
1 parent 355f44d commit 84025e0

File tree

14 files changed

+197
-41
lines changed

14 files changed

+197
-41
lines changed

velog-backend/src/lib/redisClient.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class RedisClient {
1515
}
1616
connect() {
1717
const p = new Promise((resolve, reject) => {
18-
const { REDIS_HOST, REDIS_PASS } = process.env;
1918
const client = redis.createClient({
2019
host: process.env.REDIS_HOST || '',
2120
password: process.env.REDIS_PASS || '',
2.81 KB
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// @flow
2+
import React, { Component } from 'react';
3+
import { type SeriesData } from 'store/modules/series';
4+
import TextareaAutosize from 'react-autosize-textarea';
5+
import './SeriesEditor.scss';
6+
7+
type Props = {
8+
series: SeriesData,
9+
};
10+
11+
type State = {
12+
name: string,
13+
};
14+
class SeriesEditor extends Component<Props, State> {
15+
state = {
16+
name: '',
17+
};
18+
19+
constructor(props: Props) {
20+
super(props);
21+
this.state.name = props.series.name;
22+
}
23+
24+
onKeyPress = (e: KeyboardEvent) => {
25+
if (e.key === 'Enter') {
26+
e.preventDefault();
27+
}
28+
};
29+
30+
onChangeTitle = (e: SyntheticInputEvent<HTMLInputElement>) => {
31+
this.setState({
32+
name: e.target.value,
33+
});
34+
};
35+
36+
render() {
37+
return (
38+
<div className="SeriesEditor">
39+
<TextareaAutosize
40+
className="title"
41+
onChange={this.onChangeTitle}
42+
value={this.state.name}
43+
onKeyPress={this.onKeyPress}
44+
/>
45+
</div>
46+
);
47+
}
48+
}
49+
50+
export default SeriesEditor;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@import 'utils';
2+
3+
.SeriesEditor {
4+
.title {
5+
resize: none !important;
6+
width: 100%;
7+
margin-top: 1.5rem;
8+
color: $oc-gray-9;
9+
font-size: 2.5rem;
10+
font-weight: 800;
11+
border-bottom: 1px solid $oc-gray-2;
12+
margin-bottom: 0;
13+
padding: 0.5rem;
14+
border: 1px solid $oc-gray-3;
15+
outline: none;
16+
font-family: inherit;
17+
}
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './SeriesEditor';

velog-frontend/src/components/series/SeriesPostItem/SeriesPostItem.scss

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@import 'utils';
22

33
.SeriesPostItem {
4-
padding-top: 2rem;
5-
padding-bottom: 2rem;
64
h2 {
75
margin: 0;
86
font-size: 1.75rem;
@@ -17,7 +15,7 @@
1715
.date {
1816
font-size: 0.875rem;
1917
color: $oc-gray-6;
20-
margin-bottom: 2rem;
18+
margin-bottom: 1rem;
2119
}
2220
p {
2321
font-size: 1.125rem;
@@ -27,6 +25,6 @@
2725
margin-top: 0;
2826
}
2927
& + & {
30-
border-top: 1px solid $oc-gray-2;
28+
margin-top: 4rem;
3129
}
3230
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @flow
2+
import React, { type Node } from 'react';
3+
import BookIcon from 'react-icons/lib/md/book';
4+
import './SeriesTemplate.scss';
5+
import HorizontalUserInfo from '../../common/HorizontalUserInfo/HorizontalUserInfo';
6+
7+
type Props = {
8+
user: {
9+
username: string,
10+
id: string,
11+
thumbnail: ?string,
12+
short_bio: ?string,
13+
},
14+
children: Node,
15+
};
16+
17+
const SeriesTemplate = ({ user, children }: Props) => {
18+
return (
19+
<div className="SeriesTemplate">
20+
<HorizontalUserInfo user={user} />
21+
<div className="series-label">
22+
<BookIcon />
23+
<span>SERIES</span>
24+
</div>
25+
{children}
26+
</div>
27+
);
28+
};
29+
30+
export default SeriesTemplate;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@import 'utils';
2+
.SeriesTemplate {
3+
margin-top: 4rem;
4+
color: $oc-gray-9;
5+
@include media('<medium') {
6+
margin-top: 0;
7+
width: 100%;
8+
}
9+
.series-label {
10+
background: $oc-violet-4;
11+
color: white;
12+
width: 7.5rem;
13+
height: 3rem;
14+
font-size: 1.5rem;
15+
display: flex;
16+
align-items: center;
17+
justify-content: center;
18+
font-weight: 800;
19+
span {
20+
margin-left: 0.25rem;
21+
}
22+
@include media('<medium') {
23+
width: 5rem;
24+
height: 2rem;
25+
font-size: 1rem;
26+
span {
27+
margin-left: 0.125rem;
28+
}
29+
}
30+
}
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './SeriesTemplate';

velog-frontend/src/components/series/SeriesViewer/SeriesViewer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// @flow
22
import React from 'react';
3-
import BookIcon from 'react-icons/lib/md/book';
43
import { type SeriesData } from 'store/modules/series';
54
import './SeriesViewer.scss';
6-
import HorizontalUserInfo from '../../common/HorizontalUserInfo/HorizontalUserInfo';
75
import SeriesPostItem from '../SeriesPostItem/SeriesPostItem';
86

97
type Props = {
108
series: SeriesData,
9+
onEnableEditing: () => void,
1110
};
12-
const SeriesViewer = ({ series }: Props) => {
11+
const SeriesViewer = ({ series, onEnableEditing }: Props) => {
1312
return (
1413
<div className="SeriesViewer">
15-
<HorizontalUserInfo user={series.user} />
16-
<div className="series-label">
17-
<BookIcon />
18-
<span>SERIES</span>
19-
</div>
2014
<h1>{series.name}</h1>
15+
<div className="manage">
16+
<button className="text-btn" onClick={onEnableEditing}>
17+
수정
18+
</button>
19+
<button className="text-btn">삭제</button>
20+
</div>
2121
<div className="list">
2222
{series.posts.map(p => (
2323
<SeriesPostItem key={p.id} post={p} username={series.user.username} />
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
@import 'utils';
22
.SeriesViewer {
3-
margin-top: 4rem;
4-
color: $oc-gray-9;
5-
@include media('<medium') {
6-
margin-top: 0;
7-
}
8-
9-
.series-label {
10-
background: $oc-violet-4;
11-
color: white;
12-
width: 7.5rem;
13-
height: 3rem;
14-
font-size: 1.5rem;
15-
display: flex;
16-
align-items: center;
17-
justify-content: center;
18-
font-weight: 800;
19-
span {
20-
margin-left: 0.25rem;
21-
}
22-
}
23-
243
h1 {
254
margin-top: 1.5rem;
265
color: $oc-gray-9;
276
font-size: 2.5rem;
287
line-height: 1.5;
29-
margin-bottom: 1rem;
308
font-weight: 800;
9+
border-bottom: 1px solid $oc-gray-2;
10+
margin-bottom: 0;
11+
padding-bottom: 0.5rem;
12+
}
13+
.manage {
14+
display: flex;
15+
justify-content: flex-end;
16+
margin-top: 0.5rem;
17+
color: $oc-gray-6;
18+
font-size: 0.875rem;
19+
margin-bottom: -1.5625rem;
20+
.text-btn {
21+
cursor: pointer;
22+
padding: 0.5rem;
23+
padding-top: 0.25rem;
24+
padding-bottom: 0.25rem;
25+
border-radius: 4px;
26+
&:hover {
27+
background: $oc-gray-0;
28+
color: $oc-violet-6;
29+
}
30+
}
31+
}
32+
.list {
33+
margin-top: 5rem;
3134
}
3235
}

velog-frontend/src/containers/series/SeriesViewerContainer.js renamed to velog-frontend/src/containers/series/SeriesContainer.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import { connect } from 'react-redux';
66
import { type State } from 'store';
77
import { type SeriesData } from 'store/modules/series';
88
import SeriesViewer from '../../components/series/SeriesViewer/SeriesViewer';
9+
import SeriesEditor from '../../components/series/SeriesEditor/SeriesEditor';
10+
import SeriesTemplate from '../../components/series/SeriesTemplate/SeriesTemplate';
911

1012
type Props = {
1113
series: ?SeriesData,
14+
editing: boolean,
1215
} & ContextRouter;
1316

14-
class SeriesViewerContainer extends Component<Props> {
17+
class SeriesContainer extends Component<Props> {
1518
initialize = () => {
1619
const { username, urlSlug } = this.props.match.params;
1720
if (!username || !urlSlug) return;
@@ -20,19 +23,33 @@ class SeriesViewerContainer extends Component<Props> {
2023
urlSlug,
2124
});
2225
};
26+
27+
enableEditing = () => {
28+
SeriesActions.enableEditing();
29+
};
2330
componentDidMount() {
2431
this.initialize();
2532
}
2633

2734
render() {
28-
const { series } = this.props;
35+
const { series, editing } = this.props;
2936
if (!series) return null;
30-
return <SeriesViewer series={series} />;
37+
38+
return (
39+
<SeriesTemplate user={series.user}>
40+
{editing ? (
41+
<SeriesEditor series={series} />
42+
) : (
43+
<SeriesViewer series={series} onEnableEditing={this.enableEditing} />
44+
)}
45+
</SeriesTemplate>
46+
);
3147
}
3248
}
3349

3450
export default withRouter(
3551
connect((state: State) => ({
3652
series: state.series.series,
37-
}))(SeriesViewerContainer),
53+
editing: state.series.editing,
54+
}))(SeriesContainer),
3855
);

velog-frontend/src/pages/Series.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { type Match } from 'react-router-dom';
44
import ViewerHead from 'components/base/ViewerHead';
55
import PlainTemplate from '../components/common/PlainTemplate';
6-
import SeriesViewerContainer from '../containers/series/SeriesViewerContainer';
6+
import SeriesContainer from '../containers/series/SeriesContainer';
77

88
type Props = {
99
match: Match,
@@ -12,7 +12,7 @@ type Props = {
1212
const Series = ({ match }: Props) => {
1313
return (
1414
<PlainTemplate header={<ViewerHead />}>
15-
<SeriesViewerContainer />
15+
<SeriesContainer />
1616
</PlainTemplate>
1717
);
1818
};

velog-frontend/src/store/modules/series.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import * as SeriesAPI from 'lib/api/series';
66

77
const GET_SERIES = 'series/GET_SERIES';
88
const INITIALIZE = 'series/INITIALIZE';
9+
const ENABLE_EDITING = 'series/ENABLE_EDITING';
910

1011
export const actionCreators = {
1112
getSeries: createAction(GET_SERIES, SeriesAPI.getSeries),
1213
initialize: createAction(INITIALIZE),
14+
enableEditing: createAction(ENABLE_EDITING),
1315
};
1416

1517
export type SeriesPostData = {
@@ -45,15 +47,21 @@ type GetSeriesResponseAction = GenericResponseAction<SeriesData>;
4547

4648
export type SeriesState = {
4749
series: ?SeriesData,
50+
editing: boolean,
4851
};
4952

5053
const initialState: SeriesState = {
5154
series: null,
55+
editing: false,
5256
};
5357

5458
const reducer = handleActions(
5559
{
5660
[INITIALIZE]: () => initialState,
61+
[ENABLE_EDITING]: state => ({
62+
...state,
63+
editing: true,
64+
}),
5765
},
5866
initialState,
5967
);

0 commit comments

Comments
 (0)