You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
7 years ago
|
import * as classNames from "classnames";
|
||
7 years ago
|
import { observer } from "mobx-react";
|
||
8 years ago
|
import * as React from "react";
|
||
7 years ago
|
import { Message, MessageProps, TransitionGroup } from "semantic-ui-react";
|
||
7 years ago
|
|
||
7 years ago
|
import { AppState, injectState, UiMessage, UiStore } from "@client/state/";
|
||
7 years ago
|
|
||
7 years ago
|
import "@client/styles/MessagesView";
|
||
7 years ago
|
|
||
7 years ago
|
@observer
|
||
7 years ago
|
class MessageView extends React.Component<{
|
||
|
uiStore: UiStore,
|
||
|
message: UiMessage,
|
||
7 years ago
|
className?: string,
|
||
7 years ago
|
}> {
|
||
8 years ago
|
|
||
|
render() {
|
||
7 years ago
|
const { id, ...messageProps } = this.props.message;
|
||
7 years ago
|
const className = classNames(messageProps.className, this.props.className);
|
||
7 years ago
|
return (
|
||
|
<Message
|
||
7 years ago
|
{...messageProps}
|
||
7 years ago
|
className={className}
|
||
7 years ago
|
onDismiss={this.dismiss}
|
||
|
/>
|
||
|
);
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
private dismiss: MessageProps["onDismiss"] = (event, data) => {
|
||
7 years ago
|
const { uiStore, message } = this.props;
|
||
|
if (message.onDismiss) {
|
||
|
message.onDismiss(event, data);
|
||
7 years ago
|
}
|
||
7 years ago
|
uiStore.messages.remove(message);
|
||
8 years ago
|
}
|
||
7 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
class MessagesView extends React.Component<{ appState: AppState }> {
|
||
7 years ago
|
render() {
|
||
7 years ago
|
const { uiStore } = this.props.appState;
|
||
7 years ago
|
const messages = uiStore.messages.map((message) => (
|
||
|
<MessageView key={message.id} uiStore={uiStore} message={message} />
|
||
7 years ago
|
));
|
||
7 years ago
|
messages.reverse();
|
||
7 years ago
|
return (
|
||
7 years ago
|
<TransitionGroup as={Message.List} className="messages" animation="scale" duration={200}>
|
||
7 years ago
|
{messages}
|
||
|
</TransitionGroup>
|
||
7 years ago
|
);
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
7 years ago
|
|
||
|
export default injectState(observer(MessagesView));
|