Skip to content

Commit b48f351

Browse files
author
Vlad Sternbach
committed
added edit/save/discard functionality
1 parent 7d19f3d commit b48f351

File tree

3 files changed

+103
-9
lines changed

3 files changed

+103
-9
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"dependencies": {
2121
"angular": "^1.5.3",
2222
"angular-sanitize": "^1.5.3",
23-
"angular-ui-router": "^0.2.18",
24-
"bootstrap-sass": "^3.3.6"
23+
"angular-ui-router": "^0.2.18"
2524
},
2625
"scripts": {
2726
"prestart": "npm install",

src/components/comment/comment.component.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import './comment.scss';
1010
<div class="comment" ng-class="{'comment-edit': $ctrl.editMode}">
1111
<div class="comment-header">
1212
<div class="comment-actions">
13-
<button type="button" class="comment-edit-button" title="Edit comment" ng-click="$ctrl.editMode = true">
13+
<button type="button" class="comment-edit-button" title="Edit comment" ng-click="$ctrl.edit()">
1414
<svg aria-hidden="true" class="octicon octicon-pencil" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M0 12v3h3l8-8-3-3L0 12z m3 2H1V12h1v1h1v1z m10.3-9.3l-1.3 1.3-3-3 1.3-1.3c0.39-0.39 1.02-0.39 1.41 0l1.59 1.59c0.39 0.39 0.39 1.02 0 1.41z"></path></svg>
1515
</button>
1616
</div>
17-
<div class="comment-tag"></div>
17+
<div class="comment-tag" ng-repeat="tag in $ctrl.comment.tags">{{tag}}</div>
1818
<div class="comment-header-text">{{$ctrl.comment.title}}</div>
1919
<div class="comment-edit-title">
2020
<input ng-model="$ctrl.comment.title" autofocus="autofocus" class="comment-header-input" placeholder="Title" required="required" size="30" type="text">
@@ -28,9 +28,13 @@ import './comment.scss';
2828
</nav>
2929
</div>
3030
<div class="write-content">
31-
<textarea placeholder="Leave a comment" class="comment-textarea" ng-bind-html="$ctrl.comment.text"></textarea>
31+
<textarea placeholder="Leave a comment" class="comment-textarea" ng-model="$ctrl.comment.text"></textarea>
3232
</div>
33-
<!--<div class="comment-body" ng-bind-html="$ctrl.comment.text"></div>-->
33+
<div class="comment-body" ng-bind-html="$ctrl.comment.text"></div>
34+
</div>
35+
<div class="form-actions">
36+
<button ng-click="$ctrl.save()" class="btn btn-primary" tabindex="2">Comment</button>
37+
<button ng-click="$ctrl.discard()" class="btn" tabindex="3">Discard</button>
3438
</div>
3539
</div>
3640
</div>`,
@@ -39,7 +43,25 @@ import './comment.scss';
3943
}
4044
})
4145
class CommentController {
46+
editMode: boolean;
47+
comment: any;
48+
commentCopy: any;
49+
4250
constructor() {
43-
console.log('yep');
51+
this.editMode = false;
52+
}
53+
54+
edit() {
55+
this.editMode = true;
56+
this.commentCopy = angular.copy(this.comment);
57+
}
58+
59+
save() {
60+
this.editMode = false;
61+
}
62+
63+
discard() {
64+
this.editMode = false;
65+
this.comment = this.commentCopy;
4466
}
4567
}

src/components/comment/comment.scss

+75-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@
3131
font-size: 12px;
3232
border: 1px solid rgba(0,0,0,0.1);
3333
border-radius: 3px;
34+
.comment-edit & {
35+
display: none;
36+
}
3437
}
3538

3639
.comment-header-text {
3740
max-width: 78%;
3841
padding-top: 10px;
3942
padding-bottom: 10px;
43+
.comment-edit & {
44+
display: none;
45+
}
4046
}
4147

4248
.comment-header-input {
@@ -60,6 +66,9 @@
6066
float: right;
6167
margin-right: -5px;
6268
margin-left: 10px;
69+
.comment-edit & {
70+
display: none;
71+
}
6372
}
6473

6574
.comment-edit-button {
@@ -76,8 +85,12 @@
7685

7786

7887
.comment-edit-title {
79-
max-width: 78%;
88+
display: none;
89+
width: 100%;
8090
padding: 10px 0;
91+
.comment-edit & {
92+
display: block;
93+
}
8194
}
8295

8396
.comment-body {
@@ -87,11 +100,18 @@
87100
font-size: 14px;
88101
line-height: 1.6;
89102
word-wrap: break-word;
103+
.comment-edit & {
104+
display: none;
105+
}
90106
}
91107

92108
.write-content {
93109
padding: 0 0 10px;
94110
margin: 0 10px;
111+
display: none;
112+
.comment-edit & {
113+
display: block;
114+
}
95115
}
96116

97117
.comment-textarea {
@@ -118,13 +138,17 @@
118138
}
119139

120140
.comment-tabnav {
121-
background-color: #fff;
141+
background: #f7f7f7;
122142
padding: 6px 10px 0;
123143
border-radius: 3px 3px 0 0;
124144
margin: 0 0 10px;
125145
position: relative;
126146
margin-bottom: 15px;
127147
border-bottom: 1px solid #ddd;
148+
display: none;
149+
.comment-edit & {
150+
display: block;
151+
}
128152
}
129153

130154
.tabnav-tabs {
@@ -143,6 +167,7 @@
143167
border-bottom: 0;
144168
&:hover {
145169
text-decoration: none;
170+
cursor: pointer;
146171
}
147172
&.selected {
148173
color: #333;
@@ -151,3 +176,51 @@
151176
border-radius: 3px 3px 0 0;
152177
}
153178
}
179+
180+
181+
.form-actions {
182+
display: none;
183+
padding: 0 10px 10px;
184+
&:before {
185+
display: table;
186+
content: "";
187+
}
188+
&:after {
189+
display: table;
190+
clear: both;
191+
content: "";
192+
}
193+
.comment-edit & {
194+
display: block;
195+
}
196+
.btn {
197+
margin-left: 10px;
198+
}
199+
}
200+
201+
.btn {
202+
float: right;
203+
position: relative;
204+
display: inline-block;
205+
padding: 6px 12px;
206+
font-size: 13px;
207+
font-weight: bold;
208+
line-height: 20px;
209+
color: #333;
210+
white-space: nowrap;
211+
vertical-align: middle;
212+
cursor: pointer;
213+
user-select: none;
214+
background-color: #eee;
215+
background-image: linear-gradient(#fcfcfc, #eee);
216+
border: 1px solid #d5d5d5;
217+
border-radius: 3px;
218+
-webkit-appearance: none;
219+
&.btn-primary {
220+
color: #fff;
221+
text-shadow: 0 -1px 0 rgba(0,0,0,0.15);
222+
background-color: #60b044;
223+
background-image: linear-gradient(#8add6d, #60b044);
224+
border-color: #5ca941;
225+
}
226+
}

0 commit comments

Comments
 (0)