mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
Merge pull request #232 from nushea/sable-ux-things
Fix: Improve the UI of file descriptions
This commit is contained in:
10 files changed
+422
-146
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
sable: patch
|
||||
---
|
||||
|
||||
Improved the UI of file descriptions
|
||||
@@ -2,10 +2,10 @@ import { memo, useMemo, useCallback } from 'react';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { testMatrixTo } from '$plugins/matrix-to';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { settingsAtom, CaptionPosition } from '$state/settings';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import { config } from 'folds';
|
||||
import { Box, config } from 'folds';
|
||||
import {
|
||||
AudioContent,
|
||||
DownloadFile,
|
||||
@@ -74,6 +74,13 @@ function RenderMessageContentInternal({
|
||||
const content = useMemo(() => getContent<any>(), [getContent]);
|
||||
|
||||
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
|
||||
const [captionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
const captionPositionMap = {
|
||||
[CaptionPosition.Above]: 'column-reverse',
|
||||
[CaptionPosition.Below]: 'column',
|
||||
[CaptionPosition.Inline]: 'row',
|
||||
[CaptionPosition.Hidden]: 'row',
|
||||
} satisfies Record<CaptionPosition, React.CSSProperties['flexDirection']>;
|
||||
|
||||
const renderBody = useCallback(
|
||||
(props: any) => (
|
||||
@@ -112,54 +119,89 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
|
||||
const renderCaption = () => {
|
||||
if (captionPosition === CaptionPosition.Hidden) return null;
|
||||
if (content.filename && content.filename !== content.body) {
|
||||
if (captionPosition !== CaptionPosition.Inline)
|
||||
return (
|
||||
<MText
|
||||
style={CAPTION_STYLE}
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<MText
|
||||
style={CAPTION_STYLE}
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
<Box
|
||||
style={{
|
||||
padding: config.space.S200,
|
||||
wordBreak: 'break-word',
|
||||
maxWidth: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
flexShrink: 1,
|
||||
}}
|
||||
>
|
||||
<MText
|
||||
edited={edited}
|
||||
content={content}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const renderFile = () => (
|
||||
<>
|
||||
<MFile
|
||||
content={content}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
renderAsPdfFile={() => (
|
||||
<ReadPdfFile
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MFile
|
||||
content={content}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
renderAsPdfFile={() => (
|
||||
<ReadPdfFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <PdfViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
renderAsTextFile={() => (
|
||||
<ReadTextFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <TextViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<DownloadFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <PdfViewer {...p} />}
|
||||
info={info}
|
||||
/>
|
||||
)}
|
||||
renderAsTextFile={() => (
|
||||
<ReadTextFile
|
||||
body={body}
|
||||
mimeType={mimeType}
|
||||
url={url}
|
||||
encInfo={encInfo}
|
||||
renderViewer={(p) => <TextViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<DownloadFile body={body} mimeType={mimeType} url={url} encInfo={encInfo} info={info} />
|
||||
</FileContent>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</FileContent>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (msgType === MsgType.Text) {
|
||||
@@ -205,79 +247,100 @@ function RenderMessageContentInternal({
|
||||
(typeof content.url === 'string' && content.url.toLowerCase().includes('gif'));
|
||||
|
||||
return (
|
||||
<>
|
||||
<MImage
|
||||
content={content}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...imageProps}
|
||||
autoPlay={mediaAutoLoad}
|
||||
renderImage={(p) => {
|
||||
if (isGif && !autoplayGifs && p.src) {
|
||||
return (
|
||||
<ClientSideHoverFreeze src={p.src}>
|
||||
<Image {...p} loading="lazy" />
|
||||
</ClientSideHoverFreeze>
|
||||
);
|
||||
}
|
||||
return <Image {...p} loading="lazy" />;
|
||||
}}
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MImage
|
||||
content={content}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...imageProps}
|
||||
autoPlay={mediaAutoLoad}
|
||||
renderImage={(p) => {
|
||||
if (isGif && !autoplayGifs && p.src) {
|
||||
return (
|
||||
<ClientSideHoverFreeze src={p.src}>
|
||||
<Image {...p} loading="lazy" />
|
||||
</ClientSideHoverFreeze>
|
||||
);
|
||||
}
|
||||
return <Image {...p} loading="lazy" />;
|
||||
}}
|
||||
renderViewer={(p) => <ImageViewer {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Video) {
|
||||
return (
|
||||
<>
|
||||
<MVideo
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
body={body}
|
||||
info={info}
|
||||
{...videoProps}
|
||||
renderThumbnail={
|
||||
mediaAutoLoad
|
||||
? () => (
|
||||
<ThumbnailContent
|
||||
info={info}
|
||||
renderImage={(src) => (
|
||||
<Image alt={body} title={body} src={src} loading="lazy" />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
renderVideo={(p) => <Video {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MVideo
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
body={body}
|
||||
info={info}
|
||||
{...videoProps}
|
||||
renderThumbnail={
|
||||
mediaAutoLoad
|
||||
? () => (
|
||||
<ThumbnailContent
|
||||
info={info}
|
||||
renderImage={(src) => (
|
||||
<Image alt={body} title={body} src={src} loading="lazy" />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
renderVideo={(p) => <Video {...p} />}
|
||||
/>
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Audio) {
|
||||
return (
|
||||
<>
|
||||
<MAudio
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: captionPositionMap[captionPosition],
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<MAudio
|
||||
content={content}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
)}
|
||||
outlined={outlineAttachment}
|
||||
/>
|
||||
</div>
|
||||
{renderCaption()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,14 +231,20 @@ export function MImage({ content, renderImageContent, outlined }: MImageProps) {
|
||||
const height = scaleYDimension(imgInfo?.w || 400, 400, imgInfo?.h || 400);
|
||||
|
||||
return (
|
||||
<Attachment outlined={outlined}>
|
||||
<Attachment
|
||||
style={{
|
||||
flexGrow: 1,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
outlined={outlined}
|
||||
>
|
||||
<AttachmentBox
|
||||
style={{
|
||||
height: toRem(height < 48 ? 48 : height),
|
||||
}}
|
||||
>
|
||||
{renderImageContent({
|
||||
body: content.body || 'Image',
|
||||
body: content.filename || 'Image',
|
||||
info: imgInfo,
|
||||
mimeType: imgInfo?.mimetype,
|
||||
url: mxcUrl,
|
||||
@@ -283,7 +289,13 @@ export function MVideo({ content, renderAsFile, renderVideoContent, outlined }:
|
||||
const filename = content.filename ?? content.body ?? 'Video';
|
||||
|
||||
return (
|
||||
<Attachment outlined={outlined}>
|
||||
<Attachment
|
||||
style={{
|
||||
flexGrow: 1,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
outlined={outlined}
|
||||
>
|
||||
<AttachmentHeader>
|
||||
<FileHeader
|
||||
body={filename}
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
import { ReactNode, useEffect, useState } from 'react';
|
||||
import { Box, Chip, Icon, IconButton, Icons, Text, Tooltip, color, config, toRem } from 'folds';
|
||||
import { ReactNode, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Chip,
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
Scroll,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipProvider,
|
||||
color,
|
||||
config,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { getReactCustomHtmlParser, LINKIFY_OPTS } from '$plugins/react-custom-html-parser';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { RenderBody } from '$components/message';
|
||||
import { UploadStatus, UploadSuccess, useBindUploadAtom } from '$state/upload';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { TUploadContent } from '$utils/matrix';
|
||||
@@ -102,6 +121,7 @@ type UploadCardRendererProps = {
|
||||
setDesc: (fileItem: TUploadItem, body: string, formatted_body: string) => void;
|
||||
onRemove: (file: TUploadContent) => void;
|
||||
onComplete?: (upload: UploadSuccess) => void;
|
||||
roomId: string;
|
||||
};
|
||||
export function UploadCardRenderer({
|
||||
isEncrypted,
|
||||
@@ -110,6 +130,7 @@ export function UploadCardRenderer({
|
||||
setDesc,
|
||||
onRemove,
|
||||
onComplete,
|
||||
roomId,
|
||||
}: UploadCardRendererProps) {
|
||||
const mx = useMatrixClient();
|
||||
const mediaConfig = useMediaConfig();
|
||||
@@ -141,6 +162,20 @@ export function UploadCardRenderer({
|
||||
onComplete?.(upload);
|
||||
}
|
||||
}, [upload, onComplete]);
|
||||
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(() => ({ ...LINKIFY_OPTS }), []);
|
||||
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, roomId, {
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
}),
|
||||
[linkifyOpts, mx, roomId, spoilerClickHandler, useAuthentication]
|
||||
);
|
||||
return (
|
||||
<UploadCard
|
||||
radii="300"
|
||||
@@ -159,17 +194,35 @@ export function UploadCardRenderer({
|
||||
<Text size="B300">Retry</Text>
|
||||
</Chip>
|
||||
)}
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setIsDescribed(!isDescribed);
|
||||
}}
|
||||
aria-label="Add Upload Description"
|
||||
variant="SurfaceVariant"
|
||||
radii="Pill"
|
||||
size="300"
|
||||
>
|
||||
<Icon src={isDescribed ? Icons.ChevronBottom : Icons.ChevronTop} size="50" />
|
||||
</IconButton>
|
||||
{!isDescribed && (
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setIsDescribed(true);
|
||||
}}
|
||||
aria-label="Add Upload Description"
|
||||
variant="SurfaceVariant"
|
||||
radii="Pill"
|
||||
size="300"
|
||||
>
|
||||
<Icon src={Icons.Pencil} size="50" />
|
||||
</IconButton>
|
||||
)}
|
||||
{isDescribed && (
|
||||
<TooltipProvider
|
||||
delay={400}
|
||||
position="Top"
|
||||
style={{ textAlign: 'center' }}
|
||||
tooltip={
|
||||
<Tooltip>
|
||||
<Text size="H5">
|
||||
Don't forget to save your description before sending the message!
|
||||
</Text>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
{(triggerRef) => <Icon ref={triggerRef} src={Icons.Info} size="50" />}
|
||||
</TooltipProvider>
|
||||
)}
|
||||
|
||||
<IconButton
|
||||
onClick={removeUpload}
|
||||
@@ -214,6 +267,7 @@ export function UploadCardRenderer({
|
||||
</Text>
|
||||
</UploadCardError>
|
||||
)}
|
||||
|
||||
{isDescribed && (
|
||||
<DescriptionEditor
|
||||
value={fileItem.formatted_body || fileItem.body}
|
||||
@@ -221,25 +275,34 @@ export function UploadCardRenderer({
|
||||
setDesc(fileItem, plainText, htmlContent);
|
||||
setIsDescribed(false);
|
||||
}}
|
||||
onCancel={() => setIsDescribed(false)}
|
||||
/>
|
||||
)}
|
||||
{!isDescribed && fileItem.body && fileItem.body.length > 0 && (
|
||||
<Tooltip
|
||||
<Scroll
|
||||
direction="Vertical"
|
||||
variant="SurfaceVariant"
|
||||
visibility="Always"
|
||||
size="300"
|
||||
style={{
|
||||
maxHeight: toRem(105),
|
||||
overflow: 'scroll',
|
||||
backgroundColor: 'var(--sable-bg-container)',
|
||||
borderRadius: config.radii.R400,
|
||||
maxHeight: '180px',
|
||||
marginTop: config.space.S0,
|
||||
overflowY: 'auto',
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
size="T200"
|
||||
style={{
|
||||
height: '100%',
|
||||
wordBreak: 'break-word',
|
||||
}}
|
||||
>
|
||||
{fileItem.body}
|
||||
</Text>
|
||||
</Tooltip>
|
||||
<Box style={{ padding: config.space.S200, wordBreak: 'break-word' }}>
|
||||
<Text size="T200" priority="400" as="div">
|
||||
<RenderBody
|
||||
body={fileItem.body}
|
||||
customBody={fileItem.formatted_body}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
/>
|
||||
</Text>
|
||||
</Box>
|
||||
</Scroll>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ type DescriptionEditorProps = {
|
||||
isSaving?: boolean;
|
||||
imagePackRooms?: any[];
|
||||
onSave: (plaintext: string, htmlContent: string) => void;
|
||||
onCancel: () => void;
|
||||
};
|
||||
|
||||
export function DescriptionEditor({
|
||||
@@ -51,6 +52,7 @@ export function DescriptionEditor({
|
||||
isSaving,
|
||||
imagePackRooms,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: DescriptionEditorProps) {
|
||||
const editor = useEditor();
|
||||
const [enterForNewline] = useSetting(settingsAtom, 'enterForNewline');
|
||||
@@ -129,6 +131,7 @@ export function DescriptionEditor({
|
||||
(evt) => {
|
||||
if (isKeyHotkey('escape', evt)) {
|
||||
evt.preventDefault();
|
||||
onCancel();
|
||||
return;
|
||||
}
|
||||
const prevWordRange = getPrevWorldRange(editor);
|
||||
@@ -137,7 +140,7 @@ export function DescriptionEditor({
|
||||
: undefined;
|
||||
setAutocompleteQuery(query);
|
||||
},
|
||||
[editor]
|
||||
[editor, onCancel]
|
||||
);
|
||||
|
||||
const handleCloseAutocomplete = useCallback(() => {
|
||||
@@ -180,18 +183,33 @@ export function DescriptionEditor({
|
||||
justifyContent="SpaceBetween"
|
||||
gap="100"
|
||||
>
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Chip
|
||||
onClick={handleSave}
|
||||
variant="Primary"
|
||||
radii="Pill"
|
||||
outlined
|
||||
before={
|
||||
isSaving ? <Spinner variant="Primary" fill="Soft" size="100" /> : undefined
|
||||
}
|
||||
>
|
||||
<Text size="B300">{isSaving ? 'Saving' : 'Save'}</Text>
|
||||
</Chip>
|
||||
<Box gap="200">
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Chip
|
||||
onClick={handleSave}
|
||||
variant="Primary"
|
||||
radii="Pill"
|
||||
outlined
|
||||
before={
|
||||
isSaving ? <Spinner variant="Primary" fill="Soft" size="100" /> : undefined
|
||||
}
|
||||
>
|
||||
<Text size="B300">{isSaving ? 'Saving' : 'Save'}</Text>
|
||||
</Chip>
|
||||
</Box>
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Chip
|
||||
onClick={onCancel}
|
||||
variant="Warning"
|
||||
radii="Pill"
|
||||
outlined
|
||||
before={
|
||||
isSaving ? <Spinner variant="Primary" fill="Soft" size="100" /> : undefined
|
||||
}
|
||||
>
|
||||
<Text size="B300">Cancel</Text>
|
||||
</Chip>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box gap="Inherit">
|
||||
<IconButton
|
||||
|
||||
@@ -717,6 +717,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
setMetadata={handleFileMetadata}
|
||||
onRemove={handleRemoveUpload}
|
||||
setDesc={setDesc}
|
||||
roomId={roomId}
|
||||
/>
|
||||
))}
|
||||
</UploadBoardContent>
|
||||
|
||||
@@ -172,7 +172,6 @@ function IdentityCosmetics() {
|
||||
const [renderRoomColors, setRenderRoomColors] = useSetting(settingsAtom, 'renderRoomColors');
|
||||
const [renderRoomFonts, setRenderRoomFonts] = useSetting(settingsAtom, 'renderRoomFonts');
|
||||
const [uniformIcons, setUniformIcons] = useSetting(settingsAtom, 'uniformIcons');
|
||||
const [rightBubbles, setRightBubbles] = useSetting(settingsAtom, 'useRightBubbles');
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
@@ -229,13 +228,6 @@ function IdentityCosmetics() {
|
||||
after={<Switch variant="Primary" value={uniformIcons} onChange={setUniformIcons} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Right Aligned Bubbles"
|
||||
description="When using bubble layout, have your bubbles right aligned."
|
||||
after={<Switch variant="Primary" value={rightBubbles} onChange={setRightBubbles} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
MessageLayout,
|
||||
MessageSpacing,
|
||||
RightSwipeAction,
|
||||
CaptionPosition,
|
||||
settingsAtom,
|
||||
} from '$state/settings';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
@@ -42,6 +43,7 @@ import { KeySymbol } from '$utils/key-symbol';
|
||||
import { isMacOS, mobileOrTablet } from '$utils/user-agent';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useMessageLayoutItems } from '$hooks/useMessageLayout';
|
||||
import { useCaptionPositionItems } from '$hooks/useCaptionPosition';
|
||||
import { useMessageSpacingItems } from '$hooks/useMessageSpacing';
|
||||
import { useDateFormatItems } from '$hooks/useDateFormat';
|
||||
import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
@@ -523,6 +525,74 @@ function SelectMessageLayout() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
function SelectCaptionPosition() {
|
||||
const [menuCords, setMenuCords] = useState<RectCords>();
|
||||
const [captionPosition, setCaptionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
const captionPositionItems = useCaptionPositionItems();
|
||||
|
||||
const handleMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setMenuCords(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
|
||||
const handleSelect = (position: CaptionPosition) => {
|
||||
setCaptionPosition(position);
|
||||
setMenuCords(undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
outlined
|
||||
fill="Soft"
|
||||
radii="300"
|
||||
after={<Icon size="300" src={Icons.ChevronBottom} />}
|
||||
onClick={handleMenu}
|
||||
>
|
||||
<Text size="T300">
|
||||
{captionPositionItems.find((i) => i.layout === captionPosition)?.name ?? captionPosition}
|
||||
</Text>
|
||||
</Button>
|
||||
<PopOut
|
||||
anchor={menuCords}
|
||||
offset={5}
|
||||
position="Bottom"
|
||||
align="End"
|
||||
content={
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
initialFocus: false,
|
||||
onDeactivate: () => setMenuCords(undefined),
|
||||
clickOutsideDeactivates: true,
|
||||
isKeyForward: (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowDown' || evt.key === 'ArrowRight',
|
||||
isKeyBackward: (evt: KeyboardEvent) =>
|
||||
evt.key === 'ArrowUp' || evt.key === 'ArrowLeft',
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Menu>
|
||||
<Box direction="Column" gap="100" style={{ padding: config.space.S100 }}>
|
||||
{captionPositionItems.map((item) => (
|
||||
<MenuItem
|
||||
key={item.layout}
|
||||
size="300"
|
||||
variant={captionPosition === item.layout ? 'Primary' : 'Surface'}
|
||||
radii="300"
|
||||
onClick={() => handleSelect(item.layout)}
|
||||
>
|
||||
<Text size="T300">{item.name}</Text>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Box>
|
||||
</Menu>
|
||||
</FocusTrap>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectMessageSpacing() {
|
||||
const [menuCords, setMenuCords] = useState<RectCords>();
|
||||
@@ -753,6 +823,8 @@ function Messages() {
|
||||
'hideMembershipInReadOnly'
|
||||
);
|
||||
|
||||
const [messageLayout] = useSetting(settingsAtom, 'messageLayout');
|
||||
const [rightBubbles, setRightBubbles] = useSetting(settingsAtom, 'useRightBubbles');
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Messages</Text>
|
||||
@@ -762,12 +834,24 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Message Spacing" after={<SelectMessageSpacing />} />
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="File description placement" after={<SelectCaptionPosition />} />
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Emoji Selector Character Threshold"
|
||||
after={<EmojiSelectorThresholdInput />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
{messageLayout === MessageLayout.Bubble && (
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Right Aligned Bubbles"
|
||||
description="While using bubble layout, have your bubbles right aligned."
|
||||
after={<Switch variant="Primary" value={rightBubbles} onChange={setRightBubbles} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
)}
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Membership Change"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useMemo } from 'react';
|
||||
import { CaptionPosition } from '$state/settings';
|
||||
|
||||
export type MessageLayoutItem = {
|
||||
name: string;
|
||||
layout: CaptionPosition;
|
||||
};
|
||||
|
||||
export const useCaptionPositionItems = (): MessageLayoutItem[] =>
|
||||
useMemo(
|
||||
() => [
|
||||
{
|
||||
layout: CaptionPosition.Above,
|
||||
name: 'Above',
|
||||
},
|
||||
{
|
||||
layout: CaptionPosition.Inline,
|
||||
name: 'Inline',
|
||||
},
|
||||
{
|
||||
layout: CaptionPosition.Hidden,
|
||||
name: 'Hidden',
|
||||
},
|
||||
{
|
||||
layout: CaptionPosition.Below,
|
||||
name: 'Below',
|
||||
},
|
||||
],
|
||||
[]
|
||||
);
|
||||
@@ -15,6 +15,12 @@ export enum RightSwipeAction {
|
||||
Reply = 'reply',
|
||||
}
|
||||
|
||||
export enum CaptionPosition {
|
||||
Above = 'above',
|
||||
Inline = 'inline',
|
||||
Hidden = 'hidden',
|
||||
Below = 'below',
|
||||
}
|
||||
export type JumboEmojiSize = 'none' | 'extraSmall' | 'small' | 'normal' | 'large' | 'extraLarge';
|
||||
|
||||
export interface Settings {
|
||||
@@ -69,6 +75,7 @@ export interface Settings {
|
||||
filterPronounsLanguages?: string[];
|
||||
renderRoomColors: boolean;
|
||||
renderRoomFonts: boolean;
|
||||
captionPosition: CaptionPosition;
|
||||
|
||||
// Sable features!
|
||||
mobileGestures: boolean;
|
||||
@@ -143,6 +150,7 @@ const defaultSettings: Settings = {
|
||||
renderGlobalNameColors: true,
|
||||
renderRoomColors: true,
|
||||
renderRoomFonts: true,
|
||||
captionPosition: CaptionPosition.Below,
|
||||
|
||||
// Sable features!
|
||||
mobileGestures: true,
|
||||
|
||||
Reference in new issue
Block a user