Skip to content

Commit 08046af

Browse files
committed
RealWorld app: Profile => edit profile button (when viewing your own profile) #128
1 parent 752f4ba commit 08046af

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

apps/realworld/views/user/ProfileComponent.mjs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ProfileComponent extends Component {
7979
flag: 'bio'
8080
}, {
8181
tag : 'button',
82-
cls : ['btn', 'btn-sm', 'btn-outline-secondary', 'action-btn'],
82+
cls : ['btn', 'btn-sm', 'btn-outline-secondary', 'action-btn', 'follow-button'],
8383
flag: 'following',
8484
cn : [{
8585
tag: 'i',
@@ -89,6 +89,19 @@ class ProfileComponent extends Component {
8989
}, {
9090
vtype: 'text'
9191
}]
92+
}, {
93+
tag : 'a',
94+
cls : ['btn', 'btn-sm', 'btn-outline-secondary', 'action-btn'],
95+
flag : 'edit-profile',
96+
href : '#/settings',
97+
removeDom: true,
98+
cn: [{
99+
tag: 'i',
100+
cls: ['ion-gear-a']
101+
}, {
102+
vtype: 'text',
103+
html : ' Edit Profile Settings'
104+
}]
92105
}]
93106
}]
94107
}]
@@ -151,7 +164,7 @@ class ProfileComponent extends Component {
151164
domListeners.push({
152165
click: {
153166
fn : me.onFollowButtonClick,
154-
delegate: '.action-btn',
167+
delegate: '.follow-button',
155168
scope : me
156169
}
157170
}, {
@@ -163,6 +176,11 @@ class ProfileComponent extends Component {
163176
});
164177

165178
me.domListeners = domListeners;
179+
180+
me.getController().on({
181+
afterSetCurrentUser: me.onCurrentUserChange,
182+
scope : me
183+
});
166184
}
167185

168186
/**
@@ -265,11 +283,12 @@ class ProfileComponent extends Component {
265283
* @param {Boolean} oldValue
266284
* @private
267285
*/
268-
afterSetMyProfile(value, oldValue) {
269-
if (Neo.isBoolean(value)) {
286+
afterSetMyProfile(value, oldValue) {console.log('afterSetMyProfile', value);
287+
if (Neo.isBoolean(oldValue)) {
270288
let vdom = this.vdom;
271289

272-
VDomUtil.getByFlag(vdom, 'following').removeDom = value;
290+
VDomUtil.getByFlag(vdom, 'edit-profile').removeDom = !value;
291+
VDomUtil.getByFlag(vdom, 'following') .removeDom = value;
273292
this.vdom = vdom;
274293
}
275294
}
@@ -298,6 +317,14 @@ class ProfileComponent extends Component {
298317
});
299318
}
300319

320+
/**
321+
*
322+
* @param {Object} value
323+
*/
324+
onCurrentUserChange(value) {console.log('onCurrentUserChange', value);
325+
this.myProfile = this.username === value && value.username;
326+
}
327+
301328
/**
302329
*
303330
* @param {Object} data

0 commit comments

Comments
 (0)