1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-22 02:12:38 +01:00

timestamps

This commit is contained in:
Puyodead1 2023-09-22 16:48:13 -04:00
parent 577b25fede
commit 8872de4ad0
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
4 changed files with 69 additions and 10 deletions

View File

@ -9,12 +9,12 @@ const Container = styled.div`
transition: background-color 0.1s ease;
&:hover {
background-color: hsl(var(--background-tertiary-hsl) / 0.5);
background-color: hsl(var(--background-tertiary-hsl) / 0.3);
cursor: pointer;
}
&.visible {
background-color: hsl(var(--background-tertiary-hsl) / 0.5);
background-color: hsl(var(--background-tertiary-hsl) / 0.3);
cursor: pointer;
// target child span
@ -30,17 +30,17 @@ const Text = styled.span`
`;
interface Props {
content: string;
children: React.ReactNode;
}
function Spoiler({ content }: Props) {
function Spoiler({ children }: Props) {
const [shown, setShown] = React.useState(false);
const show = () => setShown(true);
return (
<Container className={shown ? "visible" : undefined}>
<Text onClick={show}>{content}</Text>
<Text onClick={show}>{children}</Text>
</Container>
);
}

View File

@ -8,6 +8,7 @@ import CodeBlock from "../Codeblock";
import Link from "../Link";
import Spoiler from "../Spoiler";
import { MarkdownProps } from "./Markdown";
import Timestamp from "./Timestamp";
const Container = styled.div`
// remove the excessive left padding, and margin in lists
@ -129,11 +130,13 @@ const customRenderer: Partial<ReactRenderer> = {
if (spoilerRe.test(text)) {
// get content inside spoiler tags
const spoilerContent = text.match(spoilerRe)![0].slice(2, -2);
return <Spoiler content={spoilerContent} />;
return <Spoiler children={spoilerContent} />;
}
if (FormattingPatterns.Timestamp.test(text)) {
return "timestamp baaaaby";
const match = text.match(FormattingPatterns.Timestamp);
if (match) {
const { timestamp, style } = match.groups || {};
return <Timestamp timestamp={timestamp} style={style} />;
}
return text;

View File

@ -0,0 +1,53 @@
import dayjs from "dayjs";
import { memo } from "react";
import styled from "styled-components";
import Tooltip from "../Tooltip";
const Container = styled.div`
background-color: hsl(var(--background-tertiary-hsl) / 0.3);
padding: 2px;
border-radius: 4px;
width: fit-content;
`;
interface Props {
timestamp: string;
style: string;
}
function Timestamp({ timestamp, style }: Props) {
const date = dayjs.unix(Number(timestamp));
let value = "";
switch (style) {
case "t":
value = date.format("hh:mm");
break;
case "T":
value = date.format("hh:mm:ss");
break;
case "R":
value = date.fromNow();
break;
case "D":
value = date.format("DD MMMM YYYY");
break;
case "F":
value = date.format("dddd, DD MMMM YYYY hh:mm");
break;
case "f":
default:
value = date.format("DD MMMM YYYY hh:mm");
break;
}
return (
<Container>
<Tooltip title={date.format("dddd, MMMM MM, h:mm A")} placement="top">
<span>{value}</span>
</Tooltip>
</Container>
);
}
export default memo(Timestamp);

View File

@ -94,13 +94,16 @@ export const MessageDetails = observer(({ message, position }: { message: Messag
if (message instanceof Message && message.edited_timestamp) {
return (
<div className="messageTimestampWrapper">
<Tooltip title={dayjs(message.timestamp).format("dddd, MMMM MM, h:mm A")}>
<Tooltip title={dayjs(message.timestamp).format("dddd, MMMM MM, h:mm A")} placement="top">
<time className="copyTime" dateTime={message.edited_timestamp.toISOString()}>
{dayjs(message.edited_timestamp).format("h:mm A")}
</time>
</Tooltip>
<span className="edited">
<Tooltip title={dayjs(message.edited_timestamp).format("dddd, MMMM MM, h:mm A")}>
<Tooltip
title={dayjs(message.edited_timestamp).format("dddd, MMMM MM, h:mm A")}
placement="top"
>
<span>(edited)</span>
</Tooltip>
</span>