2021-07-09 04:58:38 -04:00
|
|
|
import styled, { css, keyframes } from "styled-components";
|
2021-06-20 12:31:53 -04:00
|
|
|
import { decodeTime } from "ulid";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
import { Text } from "preact-i18n";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-06 14:29:27 -04:00
|
|
|
import { useDictionary } from "../../../lib/i18n";
|
|
|
|
|
|
|
|
import { dayjs } from "../../../context/Locale";
|
2021-06-20 12:31:53 -04:00
|
|
|
import { MessageObject } from "../../../context/revoltjs/util";
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import Tooltip from "../Tooltip";
|
|
|
|
|
2021-06-20 12:31:53 -04:00
|
|
|
export interface BaseMessageProps {
|
2021-07-05 06:25:20 -04:00
|
|
|
head?: boolean;
|
|
|
|
failed?: boolean;
|
|
|
|
mention?: boolean;
|
|
|
|
blocked?: boolean;
|
|
|
|
sending?: boolean;
|
|
|
|
contrast?: boolean;
|
2021-07-09 04:58:38 -04:00
|
|
|
highlight?: boolean;
|
2021-06-20 12:31:53 -04:00
|
|
|
}
|
|
|
|
|
2021-07-09 04:58:38 -04:00
|
|
|
const highlight = keyframes`
|
|
|
|
0% { background: var(--mention); }
|
|
|
|
66% { background: var(--mention); }
|
|
|
|
100% { background: transparent; }
|
|
|
|
`;
|
|
|
|
|
2021-06-20 12:31:53 -04:00
|
|
|
export default styled.div<BaseMessageProps>`
|
2021-07-05 06:25:20 -04:00
|
|
|
display: flex;
|
2021-07-08 15:16:50 -04:00
|
|
|
overflow: none;
|
2021-07-05 06:25:20 -04:00
|
|
|
padding: 0.125rem;
|
|
|
|
flex-direction: row;
|
|
|
|
padding-right: 16px;
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.contrast &&
|
|
|
|
css`
|
|
|
|
padding: 0.3rem;
|
|
|
|
background: var(--hover);
|
2021-07-10 10:42:13 -04:00
|
|
|
border-radius: var(--border-radius);
|
2021-07-05 06:25:20 -04:00
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.head &&
|
|
|
|
css`
|
|
|
|
margin-top: 12px;
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
${(props) =>
|
|
|
|
props.mention &&
|
|
|
|
css`
|
|
|
|
background: var(--mention);
|
|
|
|
`}
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.blocked &&
|
|
|
|
css`
|
|
|
|
filter: blur(4px);
|
|
|
|
transition: 0.2s ease filter;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
filter: none;
|
|
|
|
}
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.sending &&
|
|
|
|
css`
|
|
|
|
opacity: 0.8;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.failed &&
|
|
|
|
css`
|
|
|
|
color: var(--error);
|
|
|
|
`}
|
2021-06-21 16:11:53 -04:00
|
|
|
|
2021-07-09 04:58:38 -04:00
|
|
|
${(props) =>
|
|
|
|
props.highlight &&
|
|
|
|
css`
|
|
|
|
animation-name: ${highlight};
|
|
|
|
animation-timing-function: ease;
|
|
|
|
animation-duration: 3s;
|
|
|
|
`}
|
|
|
|
|
2021-06-24 11:43:37 -04:00
|
|
|
.detail {
|
2021-07-05 06:25:20 -04:00
|
|
|
gap: 8px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.author {
|
|
|
|
cursor: pointer;
|
|
|
|
font-weight: 600 !important;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.copy {
|
|
|
|
display: block;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--hover);
|
|
|
|
|
|
|
|
time {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
export const MessageInfo = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
width: 62px;
|
|
|
|
display: flex;
|
|
|
|
flex-shrink: 0;
|
|
|
|
padding-top: 2px;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
.copyBracket {
|
|
|
|
opacity: 0;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
.copyTime {
|
|
|
|
opacity: 0;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
svg {
|
|
|
|
user-select: none;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
transform: translateY(1px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
time {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
time,
|
|
|
|
.edited {
|
|
|
|
margin-top: 1px;
|
|
|
|
cursor: default;
|
|
|
|
display: inline;
|
|
|
|
font-size: 10px;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
|
|
|
|
|
|
|
time,
|
|
|
|
.edited > div {
|
|
|
|
&::selection {
|
|
|
|
background-color: transparent;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 17:44:15 -04:00
|
|
|
|
|
|
|
.header {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
export const MessageContent = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
min-width: 0;
|
|
|
|
flex-grow: 1;
|
|
|
|
display: flex;
|
|
|
|
// overflow: hidden;
|
2021-07-06 06:04:51 -04:00
|
|
|
font-size: var(--text-size);
|
2021-07-05 06:25:20 -04:00
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
2021-06-20 12:31:53 -04:00
|
|
|
`;
|
|
|
|
|
2021-06-21 16:11:53 -04:00
|
|
|
export const DetailBase = styled.div`
|
2021-07-05 06:25:20 -04:00
|
|
|
gap: 4px;
|
|
|
|
font-size: 10px;
|
|
|
|
display: inline-flex;
|
|
|
|
color: var(--tertiary-foreground);
|
2021-07-09 17:44:15 -04:00
|
|
|
|
|
|
|
.edited {
|
|
|
|
cursor: default;
|
|
|
|
&::selection {
|
|
|
|
background-color: transparent;
|
|
|
|
color: var(--tertiary-foreground);
|
|
|
|
}
|
|
|
|
}
|
2021-06-21 16:11:53 -04:00
|
|
|
`;
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
export function MessageDetail({
|
2021-07-05 06:25:20 -04:00
|
|
|
message,
|
|
|
|
position,
|
2021-07-05 06:23:23 -04:00
|
|
|
}: {
|
2021-07-05 06:25:20 -04:00
|
|
|
message: MessageObject;
|
|
|
|
position: "left" | "top";
|
2021-07-05 06:23:23 -04:00
|
|
|
}) {
|
2021-07-06 14:29:09 -04:00
|
|
|
const dict = useDictionary();
|
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
if (position === "left") {
|
|
|
|
if (message.edited) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<time className="copyTime">
|
|
|
|
<i className="copyBracket">[</i>
|
2021-07-06 14:29:27 -04:00
|
|
|
{dayjs(decodeTime(message._id)).format(
|
|
|
|
dict.dayjs.timeFormat,
|
|
|
|
)}
|
2021-07-05 06:25:20 -04:00
|
|
|
<i className="copyBracket">]</i>
|
|
|
|
</time>
|
|
|
|
<span className="edited">
|
|
|
|
<Tooltip content={dayjs(message.edited).format("LLLL")}>
|
|
|
|
<Text id="app.main.channel.edited" />
|
|
|
|
</Tooltip>
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<time>
|
|
|
|
<i className="copyBracket">[</i>
|
2021-07-06 14:29:27 -04:00
|
|
|
{dayjs(decodeTime(message._id)).format(
|
|
|
|
dict.dayjs.timeFormat,
|
|
|
|
)}
|
2021-07-05 06:25:20 -04:00
|
|
|
<i className="copyBracket">]</i>
|
|
|
|
</time>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DetailBase>
|
|
|
|
<time>{dayjs(decodeTime(message._id)).calendar()}</time>
|
|
|
|
{message.edited && (
|
|
|
|
<Tooltip content={dayjs(message.edited).format("LLLL")}>
|
2021-07-09 17:44:15 -04:00
|
|
|
<span className="edited"><Text id="app.main.channel.edited" /></span>
|
2021-07-05 06:25:20 -04:00
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
</DetailBase>
|
|
|
|
);
|
2021-06-20 12:31:53 -04:00
|
|
|
}
|