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