diff --git a/src/app/components/message/layout/layout.css.ts b/src/app/components/message/layout/layout.css.ts index 50fd4417..6c7b97f3 100644 --- a/src/app/components/message/layout/layout.css.ts +++ b/src/app/components/message/layout/layout.css.ts @@ -156,6 +156,8 @@ export const BubbleContentArrowLeft = style({ // beside its bubble on wide screens; on phones it floats inside the bubble, overhanging the top // edge, and the text wraps around its silhouette (shape-outside on the alpha channel). const PHONE = 'screen and (max-width: 700px)'; +const PHONE_PORTRAIT = 'min(38vw, 160px)'; +const PHONE_TEXT_FLOOR = toRem(170); const PORTRAIT = toRem(124); const POSE_GUTTER = toRem(14); const BUBBLE_CORNER = toRem(6); @@ -209,6 +211,10 @@ export const BubbleHeaderPose = style({ border: `1px solid ${color.Secondary.ContainerLine}`, borderRadius: toRem(999), whiteSpace: 'nowrap', + // Never wider than the bubble minus the portrait, so it cannot reach the portrait's face. + maxWidth: `calc(100% - ${PHONE_PORTRAIT} - ${toRem(30)})`, + overflow: 'hidden', + textOverflow: 'ellipsis', }, }, }); @@ -232,6 +238,9 @@ export const BubbleContentPose = style({ '@media': { [PHONE]: { display: 'flow-root', + // A bubble with a portrait is at least portrait + a readable column wide, or the text + // beside the portrait collapses to a strip. + minWidth: `min(100%, calc(${PHONE_PORTRAIT} + ${PHONE_TEXT_FLOOR}))`, borderTopLeftRadius: config.radii.R500, padding: `${toRem(24)} ${toRem(14)} ${toRem(14)}`, }, @@ -262,7 +271,7 @@ export const PoseButton = style({ [PHONE]: { position: 'static', float: 'left', - width: 'min(38vw, 160px)', + width: PHONE_PORTRAIT, height: 'auto', margin: `${toRem(-82)} ${toRem(8)} 0 ${toRem(-12)}`, shapeMargin: toRem(7), diff --git a/src/app/components/message/pose/poses.test.ts b/src/app/components/message/pose/poses.test.ts index ed503abe..81c2f0c6 100644 --- a/src/app/components/message/pose/poses.test.ts +++ b/src/app/components/message/pose/poses.test.ts @@ -1,6 +1,13 @@ import { describe, expect, it } from 'vitest'; import catalogue from './catalogue.json'; -import { mindOfSender, poseSrc, poseStatusLine, poseStatuses, resolvePose } from './poses'; +import { + mindOfSender, + poseSrc, + poseStatusLine, + poseStatuses, + resolvePose, + splitNewestStatus, +} from './poses'; describe('resolvePose', () => { it('keeps shared and own-signature labels from the catalogue', () => { @@ -81,3 +88,17 @@ describe('poseStatusLine', () => { ); }); }); + +describe('splitNewestStatus', () => { + const s = (mind: string, since: number) => ({ mind, pose: 'happy', since }); + + it('picks the status that changed last and keeps the others in their order', () => { + const { newest, rest } = splitNewestStatus([s('eureka', 100), s('void', 300), s('nibu', 200)]); + expect(newest?.mind).toBe('void'); + expect(rest.map((r) => r.mind)).toEqual(['eureka', 'nibu']); + }); + + it('has no newest for an empty list', () => { + expect(splitNewestStatus([])).toEqual({ newest: undefined, rest: [] }); + }); +}); diff --git a/src/app/components/message/pose/poses.ts b/src/app/components/message/pose/poses.ts index a5b705c3..7175196a 100644 --- a/src/app/components/message/pose/poses.ts +++ b/src/app/components/message/pose/poses.ts @@ -68,6 +68,17 @@ export const poseStatuses = (events: PoseEvent[]): PoseStatus[] => { }); }; +// The status that changed last, and the rest in their given order (phones show only the first). +export const splitNewestStatus = ( + statuses: PoseStatus[] +): { newest: PoseStatus | undefined; rest: PoseStatus[] } => { + let newest: PoseStatus | undefined; + statuses.forEach((st) => { + if (!newest || st.since > newest.since) newest = st; + }); + return { newest, rest: statuses.filter((st) => st !== newest) }; +}; + const two = (n: number) => String(n).padStart(2, '0'); // Client-status text. Rendered locally only; it is never sent to a room. diff --git a/src/app/features/room/RoomViewFollowing.css.ts b/src/app/features/room/RoomViewFollowing.css.ts index 18b53ac9..ad7fd12b 100644 --- a/src/app/features/room/RoomViewFollowing.css.ts +++ b/src/app/features/room/RoomViewFollowing.css.ts @@ -2,10 +2,19 @@ import { style } from '@vanilla-extract/css'; import { recipe } from '@vanilla-extract/recipes'; import { DefaultReset, color, config, toRem } from 'folds'; +// Phones: the read-receipt line is hidden; its slot shrinks to a margin under the composer. +const NARROW_HIDDEN = { + height: toRem(8), + minHeight: 0, + overflow: 'hidden', + visibility: 'hidden', +} as const; + export const RoomViewFollowingPlaceholder = style([ DefaultReset, { height: toRem(28), + '@media': { 'screen and (max-width: 480px)': NARROW_HIDDEN }, }, ]); @@ -19,6 +28,7 @@ export const RoomViewFollowing = recipe({ backgroundColor: color.Surface.Container, color: color.Surface.OnContainer, outline: 'none', + '@media': { 'screen and (max-width: 480px)': NARROW_HIDDEN }, }, ], variants: { diff --git a/src/app/features/room/RoomViewPoseStatus.css.ts b/src/app/features/room/RoomViewPoseStatus.css.ts new file mode 100644 index 00000000..d8319d0d --- /dev/null +++ b/src/app/features/room/RoomViewPoseStatus.css.ts @@ -0,0 +1,40 @@ +import { style } from '@vanilla-extract/css'; +import { DefaultReset, color, config, toRem } from 'folds'; + +const NARROW = 'screen and (max-width: 480px)'; + +export const StatusBlock = style([ + DefaultReset, + { + display: 'flex', + flexDirection: 'column', + flexShrink: 0, + padding: `0 ${toRem(16)}`, + // Phones: the newest mood and its "+N more" share one line. + '@media': { [NARROW]: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center' } }, + }, +]); + +// On phones only the newest mood shows until the strip is tapped; wide screens show every line. +export const StatusRow = style({ + '@media': { + [NARROW]: { + selectors: { + '&[data-newest="false"]': { display: 'none' }, + [`${StatusBlock}[data-open="true"] &`]: { display: 'block', flexBasis: '100%' }, + }, + }, + }, +}); + +export const StatusToggle = style([ + DefaultReset, + { + display: 'none', + minHeight: toRem(24), + padding: `0 ${config.space.S100}`, + color: color.Primary.Main, + cursor: 'pointer', + '@media': { [NARROW]: { display: 'block' } }, + }, +]); diff --git a/src/app/features/room/RoomViewPoseStatus.tsx b/src/app/features/room/RoomViewPoseStatus.tsx index d4a52c93..e62f81c0 100644 --- a/src/app/features/room/RoomViewPoseStatus.tsx +++ b/src/app/features/room/RoomViewPoseStatus.tsx @@ -1,17 +1,24 @@ import React, { useEffect, useState } from 'react'; -import { Box, Text } from 'folds'; +import { Text } from 'folds'; import { Room, RoomEvent } from 'matrix-js-sdk'; import { settingsAtom } from '../../state/settings'; import { useSetting } from '../../state/hooks/settings'; import { getMxIdLocalPart } from '../../utils/matrix'; import { getMemberDisplayName } from '../../utils/room'; -import { POSE_KEY, poseStatusLine, poseStatuses } from '../../components/message/pose/poses'; +import { + POSE_KEY, + poseStatusLine, + poseStatuses, + splitNewestStatus, +} from '../../components/message/pose/poses'; +import * as css from './RoomViewPoseStatus.css'; // Client-status lines about each Mind's current pose. They are drawn from the // timeline already in memory and are never sent as anyone's message. export function RoomViewPoseStatus({ room }: { room: Room }) { const [poseBubbles] = useSetting(settingsAtom, 'poseBubbles'); const [, bump] = useState(0); + const [open, setOpen] = useState(false); useEffect(() => { const onTimeline = () => bump((n) => n + 1); @@ -41,13 +48,33 @@ export function RoomViewPoseStatus({ room }: { room: Room }) { ); if (statuses.length === 0) return null; + const { newest, rest } = splitNewestStatus(statuses); + return ( - - {statuses.map((s) => ( - - {poseStatusLine(s)} +
+ {statuses.map((st) => ( + + {poseStatusLine(st)} ))} - + {rest.length > 0 && ( + + )} +
); }