Alex Mikhalev
7 years ago
12 changed files with 136 additions and 114 deletions
@ -1,22 +1,25 @@
@@ -1,22 +1,25 @@
|
||||
import "app/style/app.css"; |
||||
import "font-awesome/css/font-awesome.css"; |
||||
import { observer } from "mobx-react"; |
||||
import DevTools from "mobx-react-devtools"; |
||||
import * as React from "react"; |
||||
|
||||
import "semantic-ui-css/semantic.css"; |
||||
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"; |
||||
|
||||
@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() { |
||||
return <Item.Group divided> |
||||
return ( |
||||
<Item.Group divided> |
||||
<MessagesView uiStore={this.props.uiStore} /> |
||||
<DeviceView device={this.props.device} /> |
||||
<DevTools /> |
||||
</Item.Group>; |
||||
</Item.Group> |
||||
); |
||||
} |
||||
} |
||||
|
@ -1,30 +1,47 @@
@@ -1,30 +1,47 @@
|
||||
import { observer } from "mobx-react"; |
||||
import * as React from "react"; |
||||
import {CSSTransitionGroup} from "react-transition-group"; |
||||
import {Message} from "semantic-ui-react"; |
||||
import { Message, MessageList, TransitionGroup } from "semantic-ui-react"; |
||||
import { Message as UiMessage, UiStore } from "../ui"; |
||||
|
||||
@observer |
||||
export default class MessagesView extends React.PureComponent<{ uiStore: UiStore }, {}> { |
||||
class MessageView extends React.Component<{ |
||||
uiStore: UiStore, |
||||
message: UiMessage, |
||||
index: number, |
||||
}> { |
||||
|
||||
render() { |
||||
return <div className="messages"> |
||||
<CSSTransitionGroup transitionName="message" transitionAppear={true} transitionAppearTimeout={500} |
||||
transitionEnterTimeout={500} transitionLeaveTimeout={500}> |
||||
{this.props.uiStore.messages.map(this.renderMessage)} |
||||
</CSSTransitionGroup> |
||||
</div>; |
||||
const { id, header, content, type } = this.props.message; |
||||
return ( |
||||
<Message |
||||
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} |
||||
/> |
||||
); |
||||
} |
||||
|
||||
private renderMessage = (message: UiMessage, index: number) => { |
||||
const {header, content, type} = message; |
||||
return <Message key={message.id} className="message" |
||||
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 = () => { |
||||
const { uiStore, index } = this.props; |
||||
uiStore.messages.splice(index, 1); |
||||
} |
||||
} |
||||
|
||||
private dismiss(index: number) { |
||||
this.props.uiStore.messages.splice(index, 1); |
||||
@observer |
||||
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