Skip to content

Conversation

@esbb48
Copy link
Owner

@esbb48 esbb48 commented Dec 28, 2016

  • Add Login Form
  • Add redux-devtools
  • Finish Basic Login Flow (暱稱登入,其實類似匿名登入,不會特別開一筆 user 資料存入)

This change is Reviewable

@esbb48 esbb48 force-pushed the feature/3_ali_loginPage branch from 83bc803 to 1f6046c Compare December 31, 2016 05:26
"react-router-redux": "^4.0.5",
"redux": "^3.5.2",
"redux-action": "^1.0.0",
"redux-actions": "^1.2.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use both redux-action and redux-actions?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only redux-actions

"redux": "^3.5.2",
"redux-action": "^1.0.0",
"redux-actions": "^1.2.0",
"redux-devtools-extension": "^1.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to move to redux-devtools-extension to devDependencies?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it not ...

"redux-saga": "^0.13.0"
},
"devDependencies": {
"ava": "^0.17.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test runner is interesting. How did you know it?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I saw it on Evan's repo

this.onFormLogin = this.onFormLogin.bind(this);
}

onChangeUsername(event) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChangeUsername({ target: { value: username } = {}} = {})?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it seems to be a good idea to introduce redux-form to get rid of handling controlled elements by ourself. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChangeUsername? onUsernameChange?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. okay,
  2. redux-form, I survey it. If I want to use redux-form and grommet, I should customize the component.
  3. onUsernameChange, because another one is onFormLogin, it's not onLoginForm

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onUsernameChange, because another one is onFormLogin, it's not onLoginForm

Why do you mention this?


onFormLogin() {
const { username } = this.props;
if (username.length === 0) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (this.props.username.length === 0)?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

type: 'CHANGE_USERNAME',
payload: { username },
},
));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need another test to prove that changeUsername is not returning a hard-coded string that happens to be Ali.

Copy link
Owner Author

@esbb48 esbb48 Jan 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, add the other test for bill

type: 'LOGIN_REQUEST',
payload: {},
},
));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need another test to prove that it always returns an empty object as the payload.

Copy link
Owner Author

@esbb48 esbb48 Jan 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm 不懂意思 0 _ 0

Copy link
Owner Author

@esbb48 esbb48 Jan 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者該說,這是這樣的單元測試能夠呈現出來的嗎 ="=?

你後面提的需求

  1. 確保每次都回傳空的 object(意思是要傳值進去,出來的結果還是 object嗎?)
  2. username 是不是串接而成(感覺這要兩次測試確保是不是兩次結果的 contact)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping?

{ username: '' },
changeUsername({ username }),
{ username },
));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need another test to prove that its not doing string concat of username

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping?

gen.next().value,
select(),
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need another test to prove that it does get authModule from the store and use authModule.username to update localStorage

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

想一下...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping?

import { LOGIN_REQUEST } from '../../src/Auth/authModule';
import loginFlow from '../../src/Auth/authSaga';

test('loginFlow', (t) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t is not descriptive at all. Is it a convention to use t when you use ava?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm . just follow the document sample @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. It is a convention to use ava then.

@sharils
Copy link
Collaborator

sharils commented Jan 1, 2017

Also this PR is super complex. I suggest do one thing in one PR.


onChangeUsername(event) {
const username = event.target.value.trim();
onUsernameChange({ target: { value: username } = {} } = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more .trim()?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping?

.babelrc Outdated
@@ -1,5 +1,5 @@
{
"presets": ["react", "es2015"],
"presets": ["react", "es2015", "stage-2"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "presets": ["react", "es2015", "transform-object-rest-spread"], for now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever way it is, package.json should be updated right?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

import localStoragePackage from 'localStorage';

let localStorage = localStoragePackage; // eslint-disable-line
// eslint-disable-next-line import/no-mutable-exports
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In stead of disabling eslint, do you think it's better to just do:

const localStorage = process.env.NODE_ENV === 'test' ? localStoragePackage ? global.window.localStorage;

?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping?

@esbb48
Copy link
Owner Author

esbb48 commented Jan 22, 2017

NOT YET

  • find a middleware to sync the redux store and localStorage

  • How about create a class to encapsulate the logic of authentication?

  • How about get the initialState from localStorage on store create?

  • About Test

    • test/Auth/authModule.js

      • You need another test to prove that it always returns an empty object as the payload.
      • You need another test to prove that its not doing string concat of username
    • test/Auth/authSaga.js

      • You need another test to prove that it does get authModule from the store and use authModule.username to update localStorage

} else if (!isAuthenticated && pathname !== '/login') {
replace('/login');
} else if (isAuthenticated) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realise why this looks strange to me. Basically, /login is a public page. However, you nest /login beneath private page root. Thus you are working around your own auth check code.

const theOtherUsername = 'Bill';

test('Action: changeUsername', actionTest(
test('Action: changeUsername: Alice', actionTest(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test description doesn't really help in terms of understanding what's the purpose of this test. Same as the next test.

@sharils
Copy link
Collaborator

sharils commented Jan 22, 2017

argh.... It seems that I review your work in progress ...........

@sharils
Copy link
Collaborator

sharils commented Jan 22, 2017

I guess we need a protocol. how about when you are done, ping me on fb?

@sharils
Copy link
Collaborator

sharils commented Jan 22, 2017

Do you want to give https://reviewable.io/ a try? I can set it up.

@esbb48
Copy link
Owner Author

esbb48 commented Feb 7, 2017

Review status: 0 of 20 files reviewed at latest revision, 37 unresolved discussions.


src/Auth/LoginContainer.js, line 20 at r1 (raw file):

Previously, sharils (sharils) wrote…

onUsernameChange, because another one is onFormLogin, it's not onLoginForm

Why do you mention this?

I just want to tell you that I use onUsernameChange .

Because it's same rule with onFormLogin.


src/Auth/LoginContainer.js, line 39 at r1 (raw file):

Previously, sharils (sharils) wrote…

Because I have not done it yet, I just put the button for the true position.

From this, you should get a feedback that the scope of your issue is too big.

okay


src/Auth/LoginContainer.js, line 48 at r1 (raw file):

Previously, sharils (sharils) wrote…

required is a standard HTML5 attribute. If you can't use it with grommet. There is a bigger problem... https://www.w3.org/TR/html5/forms.html#the-required-attribute

I think the pull request is too big.

If I real want to change the template, I will open the other issue to resolve this problem.


src/Auth/LoginContainer.js, line 50 at r1 (raw file):

Previously, sharils (sharils) wrote…

OK, it seems that footer can apply to section. http://stackoverflow.com/questions/11067186/is-using-footer-inside-form-semantically-fine

got it , 3Q!


src/Auth/LoginContainer.js, line 20 at r3 (raw file):

Previously, sharils (sharils) wrote…

ping?

why you ping this?
It's already done. @@


src/store/localStorage.js, line 3 at r5 (raw file):

Previously, sharils (sharils) wrote…

ping?

done


test/Auth/authModule.js, line 10 at r1 (raw file):

Previously, sharils (sharils) wrote…

This is actually related to don't be cute with your test data in 97things....

uh oh ...


test/Auth/authSaga.js, line 6 at r1 (raw file):

Previously, sharils (sharils) wrote…

ok. It is a convention to use ava then.

hmm


Comments from Reviewable

@esbb48
Copy link
Owner Author

esbb48 commented Feb 7, 2017

ok


Review status: 0 of 20 files reviewed at latest revision, 37 unresolved discussions.


Comments from Reviewable

@esbb48
Copy link
Owner Author

esbb48 commented Feb 8, 2017

Review status: 0 of 20 files reviewed at latest revision, 37 unresolved discussions.


src/Root/routes.js, line 16 at r8 (raw file):

Previously, sharils (sharils) wrote…

I just realise why this looks strange to me. Basically, /login is a public page. However, you nest /login beneath private page root. Thus you are working around your own auth check code.

摁,如果你把 checkAuth 當作是判斷 private 和 public 的依據來看就會很奇怪。

可是如果他只是會依據權限而有所不同的角度看就不會,另外一種就是在全拆分成這樣:

  • public
  • public(會因為有沒有權限而不同)
  • privae(有權限才可以)

test/Auth/authModule.js, line 15 at r9 (raw file):

Previously, sharils (sharils) wrote…

This test description doesn't really help in terms of understanding what's the purpose of this test. Same as the next test.

got it


Comments from Reviewable

@sharils
Copy link
Collaborator

sharils commented Feb 12, 2017

Reviewed 3 of 18 files at r1, 5 of 5 files at r7.
Review status: 8 of 20 files reviewed at latest revision, 29 unresolved discussions.


src/Auth/authModule.js, line 11 at r1 (raw file):

如果放在 configureStore 時,當參數越多,這邊相對的也就越長?

You have to choose whether you scatter all these localStorage code across the whole code base or in one place. I guess the answer is obvious.

And that's why I said it's a good reason to look for a middleware to sync the store and localStorage.

如果放在 module 當把一個服務切出去的時候就可以比較乾淨的移出去。

aye


Comments from Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants