FluentReader/src/components/log-menu.tsx

86 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-05-31 10:24:52 +02:00
import * as React from "react"
2020-06-29 08:01:21 +02:00
import intl from "react-intl-universal"
2021-08-21 23:49:56 +02:00
import {
Callout,
ActivityItem,
Icon,
DirectionalHint,
Link,
} from "@fluentui/react"
2020-05-31 10:24:52 +02:00
import { AppLog, AppLogType } from "../scripts/models/app"
2020-06-01 04:14:19 +02:00
import Time from "./utils/time"
2020-05-31 10:24:52 +02:00
2020-06-05 07:48:06 +02:00
type LogMenuProps = {
2020-07-09 11:59:25 +02:00
display: boolean
2020-05-31 10:24:52 +02:00
logs: AppLog[]
2020-07-09 11:59:25 +02:00
close: () => void
2020-09-01 05:29:08 +02:00
showItem: (iid: number) => void
2020-07-09 11:59:25 +02:00
}
function getLogIcon(log: AppLog) {
switch (log.type) {
2021-08-21 23:49:56 +02:00
case AppLogType.Info:
return "Info"
case AppLogType.Article:
return "KnowledgeArticle"
default:
return "Warning"
2020-07-09 11:59:25 +02:00
}
2020-05-31 10:24:52 +02:00
}
class LogMenu extends React.Component<LogMenuProps> {
2021-08-21 23:49:56 +02:00
activityItems = () =>
this.props.logs
.map((l, i) => ({
key: i,
activityDescription: l.iid ? (
<b>
<Link onClick={() => this.handleArticleClick(l)}>
{l.title}
</Link>
</b>
) : (
<b>{l.title}</b>
),
comments: l.details,
activityIcon: <Icon iconName={getLogIcon(l)} />,
timeStamp: <Time date={l.time} />,
}))
.reverse()
2020-05-31 10:24:52 +02:00
2020-07-09 11:59:25 +02:00
handleArticleClick = (log: AppLog) => {
this.props.close()
this.props.showItem(log.iid)
}
2021-08-21 23:49:56 +02:00
render() {
return (
this.props.display && (
<Callout
target="#log-toggle"
role="log-menu"
directionalHint={DirectionalHint.bottomCenter}
calloutWidth={320}
calloutMaxHeight={240}
onDismiss={this.props.close}>
{this.props.logs.length == 0 ? (
<p style={{ textAlign: "center" }}>
{intl.get("log.empty")}
</p>
) : (
this.activityItems().map(item => (
<ActivityItem
{...item}
key={item.key}
style={{ margin: 12 }}
/>
))
)}
</Callout>
)
2020-05-31 10:24:52 +02:00
)
}
}
2021-08-21 23:49:56 +02:00
export default LogMenu