This repository was archived by the owner on Mar 3, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +76
-9
lines changed Expand file tree Collapse file tree 5 files changed +76
-9
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import './SeriesEditor.scss';
10
10
11
11
type Props = {
12
12
series : SeriesData ,
13
+ onCancel : ( ) => void ,
14
+ onUpdate : ( data : { name : string , posts : any [ ] } ) => Promise < any > ,
13
15
} ;
14
16
15
17
type State = {
@@ -43,6 +45,17 @@ class SeriesEditor extends Component<Props, State> {
43
45
} ) ;
44
46
} ;
45
47
48
+ onSave = ( ) => {
49
+ const converted = this . state . tempPosts . map ( ( tp , i ) => ( {
50
+ id : tp . id ,
51
+ index : i + 1 ,
52
+ } ) ) ;
53
+ this . props . onUpdate ( {
54
+ name : this . state . name ,
55
+ posts : converted ,
56
+ } ) ;
57
+ } ;
58
+
46
59
reorder = ( oldIndex : number , newIndex : number ) => {
47
60
const nextPosts = [ ...this . state . tempPosts ] ;
48
61
const temp = nextPosts [ oldIndex ] ;
@@ -71,7 +84,7 @@ class SeriesEditor extends Component<Props, State> {
71
84
}
72
85
73
86
render ( ) {
74
- const { series } = this . props ;
87
+ const { onCancel } = this . props ;
75
88
return (
76
89
< div className = "SeriesEditor" >
77
90
< TextareaAutosize
@@ -81,8 +94,10 @@ class SeriesEditor extends Component<Props, State> {
81
94
onKeyPress = { this . onKeyPress }
82
95
/>
83
96
< div className = "buttons-wrapper" >
84
- < Button cancel > 취소</ Button >
85
- < Button > 적용</ Button >
97
+ < Button cancel onClick = { onCancel } >
98
+ 취소
99
+ </ Button >
100
+ < Button onClick = { this . onSave } > 적용</ Button >
86
101
</ div >
87
102
< div className = "list" ref = { this . list } >
88
103
{ this . state . tempPosts . map ( post => (
Original file line number Diff line number Diff line change 1
1
@import ' utils' ;
2
2
.SeriesTemplate {
3
3
margin-top : 4rem ;
4
+ margin-bottom : 4rem ;
4
5
color : $oc-gray-9 ;
5
6
@include media (' <medium' ) {
6
7
margin-top : 0 ;
Original file line number Diff line number Diff line change @@ -15,18 +15,48 @@ type Props = {
15
15
} & ContextRouter ;
16
16
17
17
class SeriesContainer extends Component < Props > {
18
- initialize = ( ) => {
18
+ initialize = async ( ) => {
19
19
const { username, urlSlug } = this . props . match . params ;
20
20
if ( ! username || ! urlSlug ) return ;
21
- SeriesActions . getSeries ( {
22
- username,
23
- urlSlug,
24
- } ) ;
21
+ try {
22
+ await SeriesActions . getSeries ( {
23
+ username,
24
+ urlSlug,
25
+ } ) ;
26
+ } catch ( e ) {
27
+ console . log ( e ) ;
28
+ }
25
29
} ;
26
30
27
31
enableEditing = ( ) = > {
28
32
SeriesActions . enableEditing ( ) ;
29
33
} ;
34
+
35
+ cancelEditing = ( ) => {
36
+ SeriesActions . disableEditing ( ) ;
37
+ } ;
38
+
39
+ updateSeries = async ( data : { name : string , posts : any [ ] } ) => {
40
+ const { username, urlSlug } = this . props . match . params ;
41
+ if ( ! username || ! urlSlug ) return ;
42
+ try {
43
+ await SeriesActions . updateSeries ( {
44
+ username,
45
+ urlSlug,
46
+ data : {
47
+ ...data ,
48
+ description : '' ,
49
+ thumbnail : null ,
50
+ url_slug : urlSlug ,
51
+ } ,
52
+ } ) ;
53
+ await this . initialize ( ) ;
54
+ SeriesActions . disableEditing ( ) ;
55
+ } catch ( e ) {
56
+ console . log ( e ) ;
57
+ }
58
+ } ;
59
+
30
60
componentDidMount ( ) {
31
61
this . initialize ( ) ;
32
62
}
@@ -38,7 +68,11 @@ class SeriesContainer extends Component<Props> {
38
68
return (
39
69
< SeriesTemplate user = { series . user } >
40
70
{ editing ? (
41
- < SeriesEditor series = { series } />
71
+ < SeriesEditor
72
+ series = { series }
73
+ onCancel = { this . cancelEditing }
74
+ onUpdate = { this . updateSeries }
75
+ />
42
76
) : (
43
77
< SeriesViewer series = { series } onEnableEditing = { this . enableEditing } />
44
78
) }
Original file line number Diff line number Diff line change @@ -19,3 +19,12 @@ export type GetSeriesParams = {
19
19
} ;
20
20
export const getSeries = ( { username, urlSlug } : GetSeriesParams ) =>
21
21
axios . get ( `/series/${ username } /${ urlSlug } ` ) ;
22
+
23
+ export type UpdateSeriesPayload = {
24
+ urlSlug : string ,
25
+ username : string ,
26
+ data : CreateSeriesPayload ,
27
+ } ;
28
+
29
+ export const updateSeries = ( payload : UpdateSeriesPayload ) =>
30
+ axios . patch ( `/series/${ payload . username } /${ payload . urlSlug } ` , payload . data ) ;
Original file line number Diff line number Diff line change @@ -7,11 +7,15 @@ import * as SeriesAPI from 'lib/api/series';
7
7
const GET_SERIES = 'series/GET_SERIES' ;
8
8
const INITIALIZE = 'series/INITIALIZE' ;
9
9
const ENABLE_EDITING = 'series/ENABLE_EDITING' ;
10
+ const DISABLE_EDITING = 'series/DISABLE_EDITING' ;
11
+ const UPDATE_SERIES = 'series/UPDATE_SERIES' ;
10
12
11
13
export const actionCreators = {
12
14
getSeries : createAction ( GET_SERIES , SeriesAPI . getSeries ) ,
13
15
initialize : createAction ( INITIALIZE ) ,
14
16
enableEditing : createAction ( ENABLE_EDITING ) ,
17
+ disableEditing : createAction ( DISABLE_EDITING ) ,
18
+ updateSeries : createAction ( UPDATE_SERIES , SeriesAPI . updateSeries ) ,
15
19
} ;
16
20
17
21
export type SeriesPostData = {
@@ -62,6 +66,10 @@ const reducer = handleActions(
62
66
...state ,
63
67
editing : true ,
64
68
} ) ,
69
+ [ DISABLE_EDITING ] : state => ( {
70
+ ...state ,
71
+ editing : false ,
72
+ } ) ,
65
73
} ,
66
74
initialState ,
67
75
) ;
You can’t perform that action at this time.
0 commit comments