rollback reply to old style
This commit is contained in:
parent
521c9d5817
commit
ce0a3b90fe
7 changed files with 94 additions and 204 deletions
|
|
@ -1,15 +0,0 @@
|
|||
import { style } from '@vanilla-extract/css';
|
||||
import { color, config, toRem } from 'folds';
|
||||
|
||||
export const ReplyBar = style({
|
||||
position: 'relative',
|
||||
top: toRem(8),
|
||||
marginLeft: 'auto',
|
||||
|
||||
width: toRem(19),
|
||||
height: `calc(100% - ${toRem(4)})`,
|
||||
|
||||
borderLeft: `${config.borderWidth.B500} solid ${color.Surface.ContainerLine}`,
|
||||
borderTop: `${config.borderWidth.B500} solid ${color.Surface.ContainerLine}`,
|
||||
borderTopLeftRadius: config.radii.R400,
|
||||
});
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
import { Box, Text, color, config, toRem } from 'folds';
|
||||
import { Box, Icon, Icons, Text, color, config, toRem } from 'folds';
|
||||
import React, { MouseEventHandler, ReactNode, useCallback, useMemo } from 'react';
|
||||
import { ClientEventWithoutRoomId } from 'neurone/lib/api/types';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import { LinePlaceholder } from './placeholder';
|
||||
import { randomNumberBetween } from '../../utils/common';
|
||||
import * as css from './Reply.css';
|
||||
import { MessageFailedContent } from './content';
|
||||
import { useRoomEvent } from '../../hooks/useRoomEvent';
|
||||
import colorMXID from '../../../util/colorMXID';
|
||||
|
|
@ -14,9 +13,6 @@ import { GetRoomMemberNameCallback } from '../../hooks/useRoomMembers';
|
|||
import { rContent, rUnsigned } from '../../../client/reader';
|
||||
import { TimelineView } from '../../../client/room';
|
||||
import { RenderReplyContent } from '../RenderReplyContent';
|
||||
import { Time } from './Time';
|
||||
import { BubbleLayout, CompactLayout, MessageBase, ModernLayout } from './layout';
|
||||
import { MessageLayout, MessageSpacing } from '../../state/settings';
|
||||
import { RedactedContent } from './MsgTypeRenderers';
|
||||
import { HoverUnderline } from '../../styles/Text.css';
|
||||
import { useObservableValueOptionally } from '../../hooks/useObservableValue';
|
||||
|
|
@ -26,20 +22,11 @@ import { useClient } from '../../hooks/useClient';
|
|||
|
||||
type ReplyMessageProps = {
|
||||
username?: ReactNode;
|
||||
time?: ReactNode;
|
||||
messageLayout: MessageLayout;
|
||||
usernameColor?: string;
|
||||
children: ReactNode;
|
||||
onClick?: () => void;
|
||||
};
|
||||
export function ReplyMessage({
|
||||
username,
|
||||
time,
|
||||
messageLayout,
|
||||
onClick,
|
||||
children,
|
||||
}: ReplyMessageProps) {
|
||||
const msgBarJSX = <div className={css.ReplyBar} />;
|
||||
|
||||
export function ReplyMessage({ username, usernameColor, onClick, children }: ReplyMessageProps) {
|
||||
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
if (!onClick) return;
|
||||
|
||||
|
|
@ -71,52 +58,14 @@ export function ReplyMessage({
|
|||
}
|
||||
: {};
|
||||
|
||||
if (messageLayout === MessageLayout.Compact) {
|
||||
return (
|
||||
<CompactLayout before={msgBarJSX}>
|
||||
<Box grow="Yes" direction="Column">
|
||||
<Box alignItems="Baseline" shrink="No" gap="200">
|
||||
<Box shrink="No" style={{ maxWidth: toRem(100) }}>
|
||||
{username}
|
||||
</Box>
|
||||
<Box shrink="Yes" {...commonProps}>
|
||||
{children}
|
||||
</Box>
|
||||
{time}
|
||||
</Box>
|
||||
</Box>
|
||||
</CompactLayout>
|
||||
);
|
||||
}
|
||||
|
||||
if (messageLayout === MessageLayout.Bubble) {
|
||||
return (
|
||||
<BubbleLayout hideBubble before={msgBarJSX}>
|
||||
<Box alignItems="Baseline" shrink="No" gap="200">
|
||||
<Box shrink="No" style={{ maxWidth: toRem(100) }}>
|
||||
{username}
|
||||
</Box>
|
||||
<Box shrink="Yes" {...commonProps}>
|
||||
{children}
|
||||
</Box>
|
||||
{time}
|
||||
</Box>
|
||||
</BubbleLayout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ModernLayout before={msgBarJSX}>
|
||||
<Box alignItems="Baseline" shrink="No" gap="200">
|
||||
<Box shrink="No" style={{ maxWidth: toRem(100) }}>
|
||||
{username}
|
||||
</Box>
|
||||
<Box shrink="Yes" {...commonProps}>
|
||||
{children}
|
||||
</Box>
|
||||
{time}
|
||||
<Box alignItems="Center" gap="100">
|
||||
<Box shrink="No" gap="0" alignItems="Center" style={{ maxWidth: toRem(120) }}>
|
||||
<Icon style={{ color: usernameColor }} size="100" src={Icons.ReplyArrow} filled />
|
||||
{username}
|
||||
</Box>
|
||||
</ModernLayout>
|
||||
<Box {...commonProps}>{children}</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +74,6 @@ type ReplyProps = {
|
|||
eventId: string;
|
||||
onClick?: (replyId: string) => void;
|
||||
onUserClick?: MouseEventHandler<HTMLButtonElement>;
|
||||
onUsernameClick?: MouseEventHandler<HTMLButtonElement>;
|
||||
getMemberPowerTag?: GetMemberPowerTag;
|
||||
accessibleTagColors?: Map<string, string>;
|
||||
legacyUsernameColor?: boolean;
|
||||
|
|
@ -133,10 +81,6 @@ type ReplyProps = {
|
|||
timeline?: TimelineView;
|
||||
htmlReactParserOptions: HTMLReactParserOptions;
|
||||
linkifyOpts: Opts;
|
||||
hour24Clock: boolean;
|
||||
messageLayout: MessageLayout;
|
||||
dateFormatString: string;
|
||||
messageSpacing: MessageSpacing;
|
||||
};
|
||||
|
||||
export function Reply({
|
||||
|
|
@ -144,7 +88,6 @@ export function Reply({
|
|||
eventId,
|
||||
onClick,
|
||||
onUserClick,
|
||||
onUsernameClick,
|
||||
getMemberPowerTag,
|
||||
accessibleTagColors,
|
||||
legacyUsernameColor,
|
||||
|
|
@ -152,10 +95,6 @@ export function Reply({
|
|||
timeline,
|
||||
htmlReactParserOptions,
|
||||
linkifyOpts,
|
||||
hour24Clock,
|
||||
dateFormatString,
|
||||
messageLayout,
|
||||
messageSpacing,
|
||||
}: ReplyProps) {
|
||||
const ct = useClient();
|
||||
const placeholderWidth = useMemo(() => randomNumberBetween(40, 400), []);
|
||||
|
|
@ -211,58 +150,47 @@ export function Reply({
|
|||
);
|
||||
};
|
||||
|
||||
const replyClick = onClick ? () => onClick(eventId) : undefined;
|
||||
|
||||
return (
|
||||
<MessageBase space={messageSpacing}>
|
||||
<ReplyMessage
|
||||
onClick={onClick ? () => onClick(eventId) : undefined}
|
||||
messageLayout={messageLayout}
|
||||
username={
|
||||
sender && (
|
||||
<Text
|
||||
as="button"
|
||||
onClick={onUsernameClick}
|
||||
onContextMenu={onUserClick}
|
||||
className={HoverUnderline}
|
||||
style={{ color: usernameColor, cursor: 'pointer' }}
|
||||
data-user-id={sender}
|
||||
size="T300"
|
||||
truncate
|
||||
>
|
||||
<b>{getMemberName(sender)}</b>
|
||||
</Text>
|
||||
)
|
||||
}
|
||||
time={
|
||||
replyEvent && (
|
||||
<Time
|
||||
as="button"
|
||||
className={HoverUnderline}
|
||||
onClick={onClick ? () => onClick(eventId) : undefined}
|
||||
ts={replyEvent.origin_server_ts}
|
||||
dateFormatString={dateFormatString}
|
||||
hour24Clock={hour24Clock}
|
||||
/>
|
||||
)
|
||||
}
|
||||
data-event-id={eventId}
|
||||
>
|
||||
{replyEvent && renderEventContent(replyEvent)}
|
||||
{replyEvent === null && (
|
||||
<Text size="T300">
|
||||
<MessageFailedContent />
|
||||
<ReplyMessage
|
||||
onClick={replyClick}
|
||||
usernameColor={usernameColor}
|
||||
username={
|
||||
sender && (
|
||||
<Text
|
||||
as="button"
|
||||
onClick={replyClick}
|
||||
onContextMenu={onUserClick}
|
||||
className={HoverUnderline}
|
||||
style={{ color: usernameColor, cursor: 'pointer' }}
|
||||
data-user-id={sender}
|
||||
size="T300"
|
||||
truncate
|
||||
>
|
||||
<b>{getMemberName(sender)}</b>
|
||||
</Text>
|
||||
)}
|
||||
{replyEvent === undefined && (
|
||||
<LinePlaceholder
|
||||
style={{
|
||||
backgroundColor: color.SurfaceVariant.ContainerActive,
|
||||
width: toRem(placeholderWidth),
|
||||
maxWidth: '100%',
|
||||
height: config.lineHeight.T300,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</ReplyMessage>
|
||||
</MessageBase>
|
||||
)
|
||||
}
|
||||
data-event-id={eventId}
|
||||
>
|
||||
{replyEvent && renderEventContent(replyEvent)}
|
||||
{replyEvent === null && (
|
||||
<Text size="T300">
|
||||
<MessageFailedContent />
|
||||
</Text>
|
||||
)}
|
||||
{replyEvent === undefined && (
|
||||
<LinePlaceholder
|
||||
style={{
|
||||
backgroundColor: color.SurfaceVariant.ContainerActive,
|
||||
width: toRem(placeholderWidth),
|
||||
maxWidth: '100%',
|
||||
margin: `${toRem(2)} 0`,
|
||||
height: `calc(${config.lineHeight.T300} - ${toRem(4)})`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</ReplyMessage>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,8 +224,6 @@ export function OutboxView({
|
|||
onUsernameClick,
|
||||
mediaAutoLoad,
|
||||
urlPreview,
|
||||
hour24Clock,
|
||||
dateFormatString,
|
||||
onReplyClick,
|
||||
htmlReactParserOptions,
|
||||
linkifyOpts,
|
||||
|
|
@ -242,8 +240,6 @@ export function OutboxView({
|
|||
onUsernameClick: MouseEventHandler<HTMLButtonElement>;
|
||||
mediaAutoLoad?: boolean;
|
||||
urlPreview?: boolean;
|
||||
hour24Clock: boolean;
|
||||
dateFormatString: string;
|
||||
onReplyClick?: () => void;
|
||||
htmlReactParserOptions: HTMLReactParserOptions;
|
||||
linkifyOpts: Opts;
|
||||
|
|
@ -287,6 +283,7 @@ export function OutboxView({
|
|||
roomId={roomId}
|
||||
eventId={replyEventId}
|
||||
onClick={onReplyClick}
|
||||
onUserClick={onUserClick}
|
||||
getMemberPowerTag={getMemberPowerTag}
|
||||
accessibleTagColors={accessibleTagColors}
|
||||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
|
|
@ -294,10 +291,6 @@ export function OutboxView({
|
|||
timeline={timeline}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
messageLayout={messageLayout}
|
||||
messageSpacing={messageSpacing}
|
||||
/>
|
||||
);
|
||||
|
||||
|
|
@ -306,7 +299,6 @@ export function OutboxView({
|
|||
{dayDivider && (
|
||||
<ComboDivider ts={sender.localEvent.ts} messageSpacing={messageSpacing} />
|
||||
)}
|
||||
{replyJSX}
|
||||
<MessageSending
|
||||
key={sender.localEvent.txnId}
|
||||
outbox={timeline.outbox}
|
||||
|
|
@ -322,6 +314,7 @@ export function OutboxView({
|
|||
accessibleTagColors={accessibleTagColors}
|
||||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
>
|
||||
{replyJSX}
|
||||
<RenderMessageContent
|
||||
displayName={membersAPI.getName(ct.session.userId)}
|
||||
eventType={sender.localEvent.original.type}
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
|||
</IconButton>
|
||||
<Box grow="Yes" direction="Row" gap="200" alignItems="Center">
|
||||
<Text size="T300" truncate>
|
||||
Quote{' '}
|
||||
Reply{' '}
|
||||
<strong style={{ color: replyUsernameColor }}>
|
||||
@{memberAPI.getName(replyDraft.userId)}
|
||||
</strong>
|
||||
|
|
|
|||
|
|
@ -389,6 +389,25 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
|
|||
);
|
||||
}
|
||||
|
||||
const replyEventId = getReplyId(event.content);
|
||||
|
||||
const replyJSX =
|
||||
!getThreadId(event) && replyEventId ? (
|
||||
<Reply
|
||||
roomId={roomId}
|
||||
eventId={replyEventId}
|
||||
onClick={handleOpenReply}
|
||||
onUserClick={handleUserClick}
|
||||
getMemberPowerTag={getMemberPowerTag}
|
||||
accessibleTagColors={accessiblePowerTagColors}
|
||||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
getMemberName={membersAPI.getName}
|
||||
timeline={timeline}
|
||||
htmlReactParserOptions={htmlReactParserInlineOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
const threadTimeline = threads.get(event.event_id);
|
||||
|
||||
return (
|
||||
|
|
@ -426,6 +445,7 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
|
|||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
>
|
||||
{replyJSX}
|
||||
{redacted.has(event.event_id) ? (
|
||||
<RedactedContent />
|
||||
) : (
|
||||
|
|
@ -519,34 +539,9 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
|
|||
if (newDivider && dividerJSX) clearNewDivider();
|
||||
if (dayDivider && dividerJSX) clearDayDivider();
|
||||
|
||||
const replyEventId = getReplyId(event.content);
|
||||
|
||||
const replyJSX =
|
||||
!getThreadId(event) && replyEventId ? (
|
||||
<Reply
|
||||
roomId={roomId}
|
||||
eventId={replyEventId}
|
||||
onClick={handleOpenReply}
|
||||
onUserClick={handleUserClick}
|
||||
onUsernameClick={handleUsernameClick}
|
||||
getMemberPowerTag={getMemberPowerTag}
|
||||
accessibleTagColors={accessiblePowerTagColors}
|
||||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
getMemberName={membersAPI.getName}
|
||||
timeline={timeline}
|
||||
htmlReactParserOptions={htmlReactParserInlineOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
messageLayout={messageLayout}
|
||||
messageSpacing={messageSpacing}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<React.Fragment key={event.event_id}>
|
||||
{dividerJSX}
|
||||
{replyJSX}
|
||||
{eventJSX}
|
||||
</React.Fragment>
|
||||
);
|
||||
|
|
@ -612,8 +607,6 @@ export function RoomTimeline({ eventId, roomInputRef, editor, timeline }: RoomTi
|
|||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
mediaAutoLoad={mediaAutoLoad}
|
||||
urlPreview={showUrlPreview}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -937,8 +937,6 @@ export const Message = as<'div', MessageProps>(
|
|||
}, 100);
|
||||
};
|
||||
|
||||
// hide margin-top space between message and reply
|
||||
const hasReply = !!getReplyId(event.content) && !fallbackReply(event.content);
|
||||
return (
|
||||
<MessageBase
|
||||
className={classNames(css.MessageBase, className, {
|
||||
|
|
@ -946,7 +944,7 @@ export const Message = as<'div', MessageProps>(
|
|||
})}
|
||||
tabIndex={0}
|
||||
space={messageSpacing}
|
||||
collapse={collapse || hasReply}
|
||||
collapse={collapse}
|
||||
highlight={highlight}
|
||||
selected={!!selected || !!menuAnchor || !!emojiBoardAnchor}
|
||||
{...props}
|
||||
|
|
@ -1002,7 +1000,7 @@ export const Message = as<'div', MessageProps>(
|
|||
size="300"
|
||||
radii="300"
|
||||
>
|
||||
<Icon src={Icons.BlockQuote} size="100" />
|
||||
<Icon src={Icons.ReplyArrow} size="100" />
|
||||
</IconButton>
|
||||
{canThread && (
|
||||
<IconButton
|
||||
|
|
@ -1076,7 +1074,7 @@ export const Message = as<'div', MessageProps>(
|
|||
)}
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.BlockQuote} />}
|
||||
after={<Icon size="100" src={Icons.ReplyArrow} />}
|
||||
radii="300"
|
||||
data-event-id={event.event_id}
|
||||
data-sender-id={event.sender}
|
||||
|
|
@ -1091,7 +1089,7 @@ export const Message = as<'div', MessageProps>(
|
|||
size="T300"
|
||||
truncate
|
||||
>
|
||||
Quote
|
||||
Reply
|
||||
</Text>
|
||||
</MenuItem>
|
||||
{canThread && (
|
||||
|
|
|
|||
|
|
@ -289,6 +289,23 @@ export function TimelineView({ threadTimeline, threadInputRef }: TimelineViewPro
|
|||
const editedEvent = getLatestEditEvent(event, editEvents, redacted);
|
||||
const highlighted = focusItem?.index === item && focusItem.highlight;
|
||||
|
||||
const replyEventId = fallbackReply(event.content) ? undefined : getReplyId(event.content);
|
||||
const replyJSX = replyEventId ? (
|
||||
<Reply
|
||||
roomId={roomId}
|
||||
eventId={replyEventId}
|
||||
onClick={handleOpenReply}
|
||||
onUserClick={handleUserClick}
|
||||
getMemberPowerTag={getMemberPowerTag}
|
||||
accessibleTagColors={accessiblePowerTagColors}
|
||||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
getMemberName={membersAPI.getName}
|
||||
timeline={threadTimeline}
|
||||
htmlReactParserOptions={htmlReactParserInlineOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
const reactionJSX = reactionEvents && reactionEvents?.length > 0 && (
|
||||
<Reactions
|
||||
style={{ marginTop: config.space.S200 }}
|
||||
|
|
@ -332,6 +349,7 @@ export function TimelineView({ threadTimeline, threadInputRef }: TimelineViewPro
|
|||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
>
|
||||
{replyJSX}
|
||||
{redacted.has(event.event_id) ? (
|
||||
<RedactedContent />
|
||||
) : (
|
||||
|
|
@ -411,32 +429,9 @@ export function TimelineView({ threadTimeline, threadInputRef }: TimelineViewPro
|
|||
if (newDivider && dividerJSX) clearNewDivider();
|
||||
if (dayDivider && dividerJSX) clearDayDivider();
|
||||
|
||||
const replyEventId = fallbackReply(event.content) ? undefined : getReplyId(event.content);
|
||||
const replyJSX = replyEventId ? (
|
||||
<Reply
|
||||
roomId={roomId}
|
||||
eventId={replyEventId}
|
||||
onClick={handleOpenReply}
|
||||
onUserClick={handleUserClick}
|
||||
onUsernameClick={handleUsernameClick}
|
||||
getMemberPowerTag={getMemberPowerTag}
|
||||
accessibleTagColors={accessiblePowerTagColors}
|
||||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
getMemberName={membersAPI.getName}
|
||||
timeline={threadTimeline}
|
||||
htmlReactParserOptions={htmlReactParserInlineOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
messageLayout={messageLayout}
|
||||
messageSpacing={messageSpacing}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<React.Fragment key={event.event_id}>
|
||||
{dividerJSX}
|
||||
{replyJSX}
|
||||
{eventJSX}
|
||||
</React.Fragment>
|
||||
);
|
||||
|
|
@ -522,8 +517,6 @@ export function TimelineView({ threadTimeline, threadInputRef }: TimelineViewPro
|
|||
legacyUsernameColor={legacyUsernameColor || direct}
|
||||
mediaAutoLoad={mediaAutoLoad}
|
||||
urlPreview={showUrlPreview}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue