|
1 | | -import React from 'react'; |
| 1 | +import React, { Component } from 'react'; |
2 | 2 | import { createCanal } from 'react-gondola'; |
3 | 3 | import { FirstName } from './FirstName'; |
4 | 4 | import { LastName } from './LastName'; |
5 | 5 | import { Confirm } from './Confirm'; |
6 | | -import { Observer } from 'mobx-react/native'; |
7 | | -import { fromStream } from 'mobx-utils'; |
8 | | -import { interval } from 'rxjs'; |
9 | | -import { map } from 'rxjs/operators'; |
10 | 6 |
|
11 | | -// @ts-ignore |
12 | | -const SignInCanal = createCanal([ |
13 | | - { name: 'firstName', Component: FirstName }, |
14 | | - { name: 'lastName', Component: LastName }, |
15 | | - { name: 'confirm', Component: Confirm, isFullScreen: true } |
16 | | -]); |
| 7 | +export class SignIn extends Component { |
| 8 | + state = { |
| 9 | + confirm: false, |
| 10 | + lastName: false |
| 11 | + }; |
17 | 12 |
|
18 | | -export const SignIn = () => { |
19 | | - const lastNameAuth = fromStream( |
20 | | - interval(1000).pipe(map(tick => tick % 4 === 0 || (tick + 1) % 4 === 0)) |
21 | | - ); |
22 | | - const confirmAuth = fromStream( |
23 | | - interval(1000).pipe(map(tick => tick % 2 === 0)) |
24 | | - ); |
25 | | - return ( |
26 | | - <Observer> |
27 | | - {() => ( |
28 | | - <SignInCanal |
29 | | - firstName |
30 | | - lastName={lastNameAuth.current} |
31 | | - confirm={confirmAuth.current} |
32 | | - /> |
33 | | - )} |
34 | | - </Observer> |
35 | | - ); |
36 | | -}; |
| 13 | + goForward = () => { |
| 14 | + if (!this.state.lastName) { |
| 15 | + return this.setState({ lastName: true }); |
| 16 | + } |
| 17 | + return this.setState({ confirm: true }); |
| 18 | + }; |
| 19 | + |
| 20 | + goBackward = () => { |
| 21 | + if (this.state.confirm) { |
| 22 | + return this.setState({ confirm: false }); |
| 23 | + } |
| 24 | + return this.setState({ lastName: false }); |
| 25 | + }; |
| 26 | + |
| 27 | + SignInCanal = createCanal([ |
| 28 | + { |
| 29 | + Component: FirstName, |
| 30 | + name: 'firstName', |
| 31 | + props: { onNext: this.goForward } |
| 32 | + }, |
| 33 | + { |
| 34 | + Component: LastName, |
| 35 | + name: 'lastName', |
| 36 | + onBack: this.goBackward, |
| 37 | + props: { onNext: this.goForward } |
| 38 | + }, |
| 39 | + { name: 'confirm', Component: Confirm, onBack: this.goBackward } |
| 40 | + ]); |
| 41 | + |
| 42 | + render() { |
| 43 | + const { SignInCanal } = this; |
| 44 | + |
| 45 | + return ( |
| 46 | + <SignInCanal |
| 47 | + firstName |
| 48 | + lastName={this.state.lastName} |
| 49 | + confirm={this.state.confirm} |
| 50 | + /> |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
0 commit comments