From 30940f24091eff9fcb52ce097ad9decc7e94d6cf Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Fri, 15 May 2026 19:15:03 +0300 Subject: [PATCH] add banner to roomCard --- src/app/components/room-card/RoomCard.tsx | 248 ++++++++++++---------- src/app/components/room-card/style.css.ts | 33 ++- src/app/features/room/MembersDrawer.tsx | 2 - src/app/pages/client/space/Space.tsx | 5 +- 4 files changed, 171 insertions(+), 117 deletions(-) diff --git a/src/app/components/room-card/RoomCard.tsx b/src/app/components/room-card/RoomCard.tsx index ed905872e..b7afb0111 100644 --- a/src/app/components/room-card/RoomCard.tsx +++ b/src/app/components/room-card/RoomCard.tsx @@ -18,6 +18,7 @@ import { as, color, config, + toRem, } from 'folds'; import classNames from 'classnames'; import FocusTrap from 'focus-trap-react'; @@ -36,6 +37,9 @@ import { KnockRoomPrompt } from '$components/knock-room-prompt'; import { RoomAvatar } from '$components/room-avatar'; import { formatCompactNumber } from '$utils/formatCompactNumber'; import * as css from './style.css'; +import type { RoomBannerContent } from '$types/matrix-sdk-events'; +import { CustomStateEvent } from '$types/matrix/room'; +import colorMXID from '$utils/colorMXID'; type GridColumnCount = '1' | '2' | '3'; const getGridColumnCount = (gridWidth: number): GridColumnCount => { @@ -66,7 +70,6 @@ export function RoomCardGrid({ children }: { children: ReactNode }) { export const RoomCardBase = as<'div'>(({ className, ...props }, ref) => ( ( ? getRoomAvatarUrl(mx, joinedRoom, 96, useAuthentication) : avatarUrl && mxcUrlToHttp(mx, avatarUrl, useAuthentication, 96, 96, 'crop'); + const bannerState = joinedRoom + ? getStateEvent(joinedRoom, CustomStateEvent.RoomBanner) + : undefined; + const bannerMXC = bannerState?.getContent()?.url; + const bannerURI = mxcUrlToHttp(mx, bannerMXC ?? '', true); const roomName = joinedRoom?.name || name || fallbackName; const roomTopic = (topicEvent?.getContent().topic as string) || undefined || topic || fallbackTopic; @@ -215,11 +223,28 @@ export const RoomCard = as<'div', RoomCardProps>( const [viewTopic, setViewTopic] = useState(false); const closeTopic = () => setViewTopic(false); const openTopic = () => setViewTopic(true); - + if (!bannerURI && !avatar) + // oxlint-disable-next-line no-console + console.log(bannerURI, avatar, roomIdOrAlias); return ( - - + + {!bannerURI && !avatar ? ( + + ) : ( + {`${name} + )} + ( )} /> - {(roomType === RoomType.Space || joinedRoom?.isSpaceRoom()) && ( - - Space - - )} - - {roomName} - - {roomTopic} - - - }> - - - {renderTopicViewer(roomName, roomTopic, closeTopic)} - - - - - {typeof joinedMemberCount === 'number' && ( - - - {`${formatCompactNumber(joinedMemberCount)} Members`} - - )} - {typeof joinedRoomId === 'string' && ( - - )} - {typeof joinedRoomId !== 'string' && - joinState.status !== AsyncStatus.Error && - (joinRule === JoinRule.Knock ? ( - <> - - - {knocking && ( - setKnocking(false)} - onCancel={() => setKnocking(false)} - /> - )} - - ) : ( - - ))} - {typeof joinedRoomId !== 'string' && joinState.status === AsyncStatus.Error && ( - - - - {(openError) => ( - + )} + {typeof joinedRoomId !== 'string' && + joinState.status !== AsyncStatus.Error && + (joinRule === JoinRule.Knock ? ( + <> + - )} - - - )} + + {knocking && ( + setKnocking(false)} + onCancel={() => setKnocking(false)} + /> + )} + + ) : ( + + ))} + {typeof joinedRoomId !== 'string' && joinState.status === AsyncStatus.Error && ( + + + + {(openError) => ( + + )} + + + )} + ); } diff --git a/src/app/components/room-card/style.css.ts b/src/app/components/room-card/style.css.ts index 8afe6704b..98f8fe042 100644 --- a/src/app/components/room-card/style.css.ts +++ b/src/app/components/room-card/style.css.ts @@ -1,6 +1,7 @@ import { style } from '@vanilla-extract/css'; -import { DefaultReset, config } from 'folds'; +import { DefaultReset, color, config, toRem } from 'folds'; import { ContainerColor } from '$styles/ContainerColor.css'; +import { recipe } from '@vanilla-extract/recipes'; export const CardGrid = style({ display: 'grid', @@ -12,11 +13,15 @@ export const RoomCardBase = style([ DefaultReset, ContainerColor({ variant: 'SurfaceVariant' }), { - padding: config.space.S500, borderRadius: config.radii.R500, + overflow: 'hidden', }, ]); +export const RoomCardItems = style({ + padding: config.space.S500, + backgroundColor: color.SurfaceVariant.Container, +}); export const RoomCardTopic = style({ minHeight: `calc(3 * ${config.lineHeight.T200})`, display: '-webkit-box', @@ -34,3 +39,27 @@ export const ActionButton = style({ flex: '1 1 0', minWidth: 1, }); + +export const RoomCardBanner = recipe({ + base: { + height: toRem(96), + minHeight: toRem(96), + width: '100%', + objectFit: 'cover', + objectPosition: 'center center', + }, + variants: { + trueBanner: { + true: {}, + false: { + filter: 'blur(40px)', + }, + }, + }, +}); +export const RoomCardAvatar = style({ + position: 'sticky', + transform: 'translateY(-50%)', + marginLeft: config.space.S500, + outline: `${config.borderWidth.B600} solid ${color.Surface.Container}`, +}); diff --git a/src/app/features/room/MembersDrawer.tsx b/src/app/features/room/MembersDrawer.tsx index 2641899d4..3aeb18c15 100644 --- a/src/app/features/room/MembersDrawer.tsx +++ b/src/app/features/room/MembersDrawer.tsx @@ -296,8 +296,6 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) { ); const handleMemberClick: MouseEventHandler = (evt) => { - // oxlint-disable-next-line no-console - console.log(evt); const btn = evt.currentTarget as HTMLButtonElement; const userId = btn.getAttribute('data-user-id'); if (!userId) return; diff --git a/src/app/pages/client/space/Space.tsx b/src/app/pages/client/space/Space.tsx index e82d5b921..8dbcfc417 100644 --- a/src/app/pages/client/space/Space.tsx +++ b/src/app/pages/client/space/Space.tsx @@ -526,9 +526,8 @@ export function Space() { const [showRoomIconGeneral] = useSetting(settingsAtom, 'showRoomIcon'); const [showRoomIconArray] = useSetting(settingsAtom, 'perRoomShowRoomIcon'); - const showRoomIcon = showRoomIconArray.find(item => item.roomId === space.roomId )?.display ?? showRoomIconGeneral; - // oxlint-disable-next-line no-console - console.log(showRoomIconArray, space.roomId); + const showRoomIcon = + showRoomIconArray.find((item) => item.roomId === space.roomId)?.display ?? showRoomIconGeneral; const showIcons = () => { if (showRoomIcon === ShowRoomIcon.Always) return true; if (showRoomIcon === ShowRoomIcon.Never) return false;