-
Notifications
You must be signed in to change notification settings - Fork 649
Add flash message with info after login #1952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6bd0143
93d8dbb
93105e7
d7ac6d7
e6403a9
d006ee9
56ed394
220e90f
ce44d31
9117b74
9656756
b9c2856
6e0936f
4eb0e95
ff50263
46ab6ee
ba7db55
a64fc2a
b8c9d25
938393f
d7b5a54
dbe7ed4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p local-class="welcome-message {{if this.showMessage "shown info"}}" ...attributes data-test-welcome-message> | ||
Welcome to crates.io! Visit <a href='me'>account settings</a> to {{this.text}} | ||
</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Component from '@ember/component'; | ||
import { inject as service } from '@ember/service'; | ||
import { computed } from '@ember/object'; | ||
import { notEmpty } from '@ember/object/computed'; | ||
|
||
export default Component.extend({ | ||
session: service(), | ||
|
||
text: computed('session.currentUser.{email_verified,has_tokens}', function() { | ||
const user = this.get('session.currentUser'); | ||
if (!user || (user.email_verified && user.has_tokens)) return ''; | ||
|
||
const textArray = [ | ||
!user.email_verified && 'verify your email address', | ||
!user.email_verified && !user.has_tokens && ' and ', | ||
!user.has_tokens && 'create an API token', | ||
'!', | ||
].filter(e => !!e); | ||
|
||
return textArray.join(''); | ||
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would prefer it if we moved that code into the index controller and not instantiate the component at all if we don't have anything to display There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic has nothing in common with the index controller. This is common arch mistake in all MVC frameworks. Trying to move business logic inside of controllers fail by design. |
||
|
||
showMessage: notEmpty('text').readOnly(), | ||
|
||
tagName: '', | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.welcome-message { | ||
display: none; | ||
font-weight: bold; | ||
font-size: 110%; | ||
text-align: center; | ||
margin: 0 0 10px 0; | ||
padding: 10px; | ||
border-radius: 5px; | ||
|
||
&.shown { | ||
display: block; | ||
} | ||
|
||
&.info { | ||
background-color: $main-bg-dark; | ||
border: 2px solid #62865f; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import { Factory } from 'ember-cli-mirage'; | ||
import { dasherize } from '@ember/string'; | ||
import { Factory, trait } from 'ember-cli-mirage'; | ||
import faker from 'faker'; | ||
|
||
export default Factory.extend({ | ||
name: i => `User ${i + 1}`, | ||
|
||
email_verified: false, | ||
email_verification_sent: true, | ||
name() { | ||
return faker.name.findName(); | ||
}, | ||
login() { | ||
return dasherize(this.name); | ||
return faker.internet.userName(); | ||
}, | ||
avatar() { | ||
return faker.image.imageUrl(); | ||
}, | ||
|
||
url() { | ||
return `https://github.com/${this.login}`; | ||
return faker.internet.url(); | ||
}, | ||
kind: 'user', | ||
has_tokens: false, | ||
|
||
withVerifiedEmail: trait({ | ||
email_verified: true, | ||
}), | ||
|
||
avatar: 'https://avatars1.githubusercontent.com/u/14631425?v=4', | ||
withTokens: trait({ | ||
has_tokens: true, | ||
}), | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Component | flesh-message', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function(assert) { | ||
assert.expect(2); | ||
|
||
await render(hbs`<FlashMessage @message="test text" />`); | ||
|
||
assert.dom('[data-test-flash-message]').hasText('test text'); | ||
assert.dom('[data-test-flash-message]').isVisible(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code logic here seems a bit hard to read. do you think it could be simplified in some way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried some variants before come to this. For example, a variant with ternary operators looks more ugly:
Moving this calculation logic to template is not right.
I'm open to any ideas on how to improve this code.