-
Notifications
You must be signed in to change notification settings - Fork 37
/
TwitchChatLogLine.tsx
78 lines (66 loc) · 2.41 KB
/
TwitchChatLogLine.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import dayjs from "dayjs";
import React, { useContext } from "react";
import styled from "styled-components";
import { useThirdPartyEmotes } from "../hooks/useThirdPartyEmotes";
import { store } from "../store";
import { LogMessage } from "../types/log";
import { Message } from "./Message";
import { User } from "./User";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.tz.guess()
const TwitchChatLogLineContainer = styled.li`
align-items: flex-start;
margin-bottom: 1px;
padding: 5px 20px;
.timestamp {
color: var(--text-dark);
user-select: none;
font-family: monospace;
white-space: nowrap;
margin-right: 5px;
line-height: 1.1rem;
}
.user {
display: inline-block;
margin-right: 5px;
user-select: none;
font-weight: bold;
line-height: 1.1rem;
}
.message {
display: inline;
line-height: 20px;
a {
word-wrap: break-word;
}
.emote {
max-height: 28px;
margin: 0 2px;
margin-bottom: -10px;
width: auto;
}
}
`;
export function TwitchChatLogLine({ message }: { message: LogMessage }) {
const { state } = useContext(store);
if (state.settings.showEmotes.value) {
return <LogLineWithEmotes message={message} />;
}
return <TwitchChatLogLineContainer className="logLine">
{state.settings.showTimestamp.value && <span className="timestamp">{dayjs(message.timestamp).format("YYYY-MM-DD HH:mm:ss")}</span>}
{state.settings.showName.value && <User displayName={message.displayName} color={message.tags["color"]} />}
<Message message={message} thirdPartyEmotes={[]} />
</TwitchChatLogLineContainer>
}
function LogLineWithEmotes({ message }: { message: LogMessage }) {
const thirdPartyEmotes = useThirdPartyEmotes(message.tags["room-id"])
const { state } = useContext(store);
return <TwitchChatLogLineContainer className="logLine">
{state.settings.showTimestamp.value && <span className="timestamp">{dayjs(message.timestamp).format("YYYY-MM-DD HH:mm:ss")}</span>}
{state.settings.showName.value && <User displayName={message.displayName} color={message.tags["color"]} />}
<Message message={message} thirdPartyEmotes={thirdPartyEmotes} />
</TwitchChatLogLineContainer>
}