-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { Component } from 'react'; | ||
|
||
const types = { | ||
"debug": "notify", | ||
"info": "success", | ||
"warn": "warning", | ||
"error": "error", | ||
"fatal": "error", | ||
} | ||
|
||
const known = { | ||
"media": m => { | ||
if (m.year) { | ||
return `${m.name} (${m.year})` | ||
} | ||
if (m.season && m.episode) { | ||
return `${m.name} S${m.season}E${m.episode}` | ||
} | ||
} | ||
} | ||
|
||
function capitalizeFirstLetter(string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
|
||
class ActivityLog extends Component { | ||
constructor() { | ||
super() | ||
} | ||
|
||
renderTags(data) { | ||
let tags = [] | ||
for (var key in data) { | ||
let value = data[key] | ||
|
||
if (!data.hasOwnProperty(key)) { | ||
continue | ||
} | ||
|
||
if (known[key]) { | ||
value = known[key](value) | ||
} | ||
|
||
if (typeof value !== "string" || !value.length) continue | ||
|
||
tags.push(( | ||
<span key={key}> | ||
<span className="tag pad">{key}</span>{value} | ||
</span> | ||
)) | ||
} | ||
return tags | ||
} | ||
|
||
render() { | ||
if (!this.props.log || !this.props.log.length) { | ||
return <h3 className="center meta">No logs to show :(</h3> | ||
} | ||
|
||
let logs = this.props.log.map((s) => { | ||
return ( | ||
<li className={types[s.level] || "error"} key={s.wsid}> | ||
<span className="title"> | ||
{capitalizeFirstLetter(s.level)} | ||
</span> | ||
<span className="message">{s.message}</span> | ||
{this.renderTags(s.data)} | ||
</li> | ||
) | ||
}) | ||
|
||
return ( | ||
<ul className="snackbar log"> | ||
{logs} | ||
</ul> | ||
) | ||
} | ||
} | ||
|
||
export default ActivityLog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.snackbar.log { | ||
position: static; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
@import "variables"; | ||
@import "lists"; | ||
@import "flags"; | ||
@import "log"; |