Alex Mikhalev
7 years ago
12 changed files with 136 additions and 114 deletions
@ -1,22 +1,25 @@ |
|||||||
import "app/style/app.css"; |
import { observer } from "mobx-react"; |
||||||
import "font-awesome/css/font-awesome.css"; |
|
||||||
import {observer} from "mobx-react"; |
|
||||||
import DevTools from "mobx-react-devtools"; |
import DevTools from "mobx-react-devtools"; |
||||||
import * as React from "react"; |
import * as React from "react"; |
||||||
|
|
||||||
|
import { Item } from "semantic-ui-react"; |
||||||
|
import { DeviceView, MessagesView } from "."; |
||||||
|
import { SprinklersDevice } from "../sprinklers"; |
||||||
|
import { UiStore } from "../ui"; |
||||||
|
|
||||||
|
import "app/style/app.css"; |
||||||
|
import "font-awesome/css/font-awesome.css"; |
||||||
import "semantic-ui-css/semantic.css"; |
import "semantic-ui-css/semantic.css"; |
||||||
import {Item} from "semantic-ui-react"; |
|
||||||
import {DeviceView, MessagesView} from "."; |
|
||||||
import {SprinklersDevice} from "../sprinklers"; |
|
||||||
import {UiStore} from "../ui"; |
|
||||||
|
|
||||||
@observer |
@observer |
||||||
export default class App extends React.PureComponent<{ device: SprinklersDevice, uiStore: UiStore }, any> { |
export default class App extends React.Component<{ device: SprinklersDevice, uiStore: UiStore }> { |
||||||
render() { |
render() { |
||||||
return <Item.Group divided> |
return ( |
||||||
<MessagesView uiStore={this.props.uiStore}/> |
<Item.Group divided> |
||||||
<DeviceView device={this.props.device}/> |
<MessagesView uiStore={this.props.uiStore} /> |
||||||
<DevTools/> |
<DeviceView device={this.props.device} /> |
||||||
</Item.Group>; |
<DevTools /> |
||||||
|
</Item.Group> |
||||||
|
); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,30 +1,47 @@ |
|||||||
import {observer} from "mobx-react"; |
import { observer } from "mobx-react"; |
||||||
import * as React from "react"; |
import * as React from "react"; |
||||||
import {CSSTransitionGroup} from "react-transition-group"; |
import { Message, MessageList, TransitionGroup } from "semantic-ui-react"; |
||||||
import {Message} from "semantic-ui-react"; |
import { Message as UiMessage, UiStore } from "../ui"; |
||||||
import {Message as UiMessage, UiStore} from "../ui"; |
|
||||||
|
class MessageView extends React.Component<{ |
||||||
|
uiStore: UiStore, |
||||||
|
message: UiMessage, |
||||||
|
index: number, |
||||||
|
}> { |
||||||
|
|
||||||
@observer |
|
||||||
export default class MessagesView extends React.PureComponent<{ uiStore: UiStore }, {}> { |
|
||||||
render() { |
render() { |
||||||
return <div className="messages"> |
const { id, header, content, type } = this.props.message; |
||||||
<CSSTransitionGroup transitionName="message" transitionAppear={true} transitionAppearTimeout={500} |
return ( |
||||||
transitionEnterTimeout={500} transitionLeaveTimeout={500}> |
<Message |
||||||
{this.props.uiStore.messages.map(this.renderMessage)} |
header={header} |
||||||
</CSSTransitionGroup> |
content={content} |
||||||
</div>; |
success={type === UiMessage.Type.Success} |
||||||
|
info={type === UiMessage.Type.Info} |
||||||
|
warning={type === UiMessage.Type.Warning} |
||||||
|
error={type === UiMessage.Type.Error} |
||||||
|
onDismiss={this.dismiss} |
||||||
|
/> |
||||||
|
); |
||||||
} |
} |
||||||
|
|
||||||
private renderMessage = (message: UiMessage, index: number) => { |
private dismiss = () => { |
||||||
const {header, content, type} = message; |
const { uiStore, index } = this.props; |
||||||
return <Message key={message.id} className="message" |
uiStore.messages.splice(index, 1); |
||||||
header={header} content={content} |
|
||||||
success={type === UiMessage.Type.Success} |
|
||||||
info={type === UiMessage.Type.Info} warning={type === UiMessage.Type.Warning} |
|
||||||
error={type === UiMessage.Type.Error} onDismiss={() => this.dismiss(index)}/>; |
|
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
private dismiss(index: number) { |
@observer |
||||||
this.props.uiStore.messages.splice(index, 1); |
export default class MessagesView extends React.Component<{ uiStore: UiStore }> { |
||||||
|
render() { |
||||||
|
const messages = this.props.uiStore.messages.map((message, index) => ( |
||||||
|
<MessageView key={message.id} uiStore={this.props.uiStore} message={message} index={index} /> |
||||||
|
)); |
||||||
|
return ( |
||||||
|
<div className="messages" > |
||||||
|
<TransitionGroup animation="scale" duration={200}> |
||||||
|
{messages} |
||||||
|
</TransitionGroup> |
||||||
|
</div> |
||||||
|
); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue