Compare commits

...

1 commit

Author SHA1 Message Date
e75fef6ba3
Add room topic 2023-03-31 18:16:02 -05:00
4 changed files with 118 additions and 58 deletions

View file

@ -3,9 +3,8 @@
@use "../../partials/screen";
.room-header__btn {
min-width: 0;
@extend .cp-fx__row--s-c;
@include dir.side(margin, 0, auto);
@include dir.side(margin, 0, var(--sp-extra-tight));
border-radius: var(--bo-radius);
cursor: pointer;
@ -27,21 +26,54 @@
}
}
.room-header__topic {
min-width: 0;
display: flex;
align-items: center;
@include dir.side(margin, 0, auto);
p {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.room-header__drawer-btn {
flex: 0;
@include screen.smallerThan(tabletBreakpoint) {
display: none;
}
}
.room-header__members-btn {
flex: 0;
@include screen.biggerThan(tabletBreakpoint) {
display: none;
}
}
.room-header__back-btn {
flex: 0;
@include dir.side(margin, 0, var(--sp-tight));
@include screen.biggerThan(mobileBreakpoint) {
display: none;
}
}
.room-header__left {
display: flex;
flex-shrink: 1;
min-width: 0;
}
.room-header__right {
display: flex;
flex-grow: 1;
justify-content: flex-end;
min-width: 0;
}

View file

@ -1,5 +1,4 @@
import React, { useEffect, useRef } from "react";
import PropTypes from "prop-types";
import "./RoomViewHeader.scss";
import { twemojify } from "../../../util/twemojify";
@ -33,16 +32,26 @@ import BackArrowIC from "../../../../public/res/ic/outlined/chevron-left.svg";
import { useForceUpdate } from "../../hooks/useForceUpdate";
function RoomViewHeader({ roomId }) {
interface RoomViewHeaderProps {
roomId: string;
}
function RoomViewHeader({ roomId }: RoomViewHeaderProps) {
const [, forceUpdate] = useForceUpdate();
const mx = initMatrix.matrixClient;
const isDM = initMatrix.roomList.directs.has(roomId);
const room = mx.getRoom(roomId);
let avatarSrc = room.getAvatarUrl(mx.baseUrl, 36, 36, "crop");
avatarSrc = isDM
? room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 36, 36, "crop")
? room
.getAvatarFallbackMember()
?.getAvatarUrl(mx.baseUrl, 36, 36, "crop", true, false)
: avatarSrc;
const roomName = room.name;
const { name: roomName, currentState } = room;
const roomTopic = currentState
.getStateEvents("m.room.topic")[0]
?.getContent().topic;
const roomHeaderBtnRef = useRef(null);
useEffect(() => {
@ -89,61 +98,69 @@ function RoomViewHeader({ roomId }) {
return (
<Header>
<IconButton
src={BackArrowIC}
className="room-header__back-btn"
tooltip="Return to navigation"
onClick={() => openNavigation()}
/>
<button
ref={roomHeaderBtnRef}
className="room-header__btn"
onClick={() => toggleRoomSettings()}
type="button"
onMouseUp={(e) => blurOnBubbling(e, ".room-header__btn")}
>
<Avatar
imageSrc={avatarSrc}
text={roomName}
bgColor={colorMXID(roomId)}
size="small"
/>
<TitleWrapper>
<Text variant="h2" weight="medium" primary>
{twemojify(roomName)}
</Text>
</TitleWrapper>
<RawIcon src={ChevronBottomIC} />
</button>
{mx.isRoomEncrypted(roomId) === false && (
<div class="room-header__left">
<IconButton
onClick={() => toggleRoomSettings(tabText.SEARCH)}
tooltip="Search"
src={SearchIC}
src={BackArrowIC}
className="room-header__back-btn"
tooltip="Return to navigation"
onClick={() => openNavigation()}
/>
)}
<IconButton
className="room-header__drawer-btn"
onClick={togglePeopleDrawer}
tooltip="People"
src={UserIC}
/>
<IconButton
className="room-header__members-btn"
onClick={() => toggleRoomSettings(tabText.MEMBERS)}
tooltip="Members"
src={UserIC}
/>
<IconButton
onClick={openRoomOptions}
tooltip="Options"
src={VerticalMenuIC}
/>
<button
ref={roomHeaderBtnRef}
className="room-header__btn"
onClick={() => toggleRoomSettings()}
type="button"
onMouseUp={(e) => blurOnBubbling(e, ".room-header__btn")}
>
<Avatar
imageSrc={avatarSrc}
text={roomName}
bgColor={colorMXID(roomId)}
size="small"
/>
<TitleWrapper>
<Text variant="h2" weight="medium" primary>
{twemojify(roomName)}
</Text>
</TitleWrapper>
<RawIcon src={ChevronBottomIC} />
</button>
<div className="room-header__topic">
{roomTopic && (
<Text variant="b2">{twemojify(roomTopic, undefined, true)}</Text>
)}
</div>
</div>
<div class="room-header__right">
{mx.isRoomEncrypted(roomId) === false && (
<IconButton
onClick={() => toggleRoomSettings(tabText.SEARCH)}
tooltip="Search"
src={SearchIC}
/>
)}
<IconButton
className="room-header__drawer-btn"
onClick={togglePeopleDrawer}
tooltip="People"
src={UserIC}
/>
<IconButton
className="room-header__members-btn"
onClick={() => toggleRoomSettings(tabText.MEMBERS)}
tooltip="Members"
src={UserIC}
/>
<IconButton
onClick={openRoomOptions}
tooltip="Options"
src={VerticalMenuIC}
/>
</div>
</Header>
);
}
RoomViewHeader.propTypes = {
roomId: PropTypes.string.isRequired,
};
export default RoomViewHeader;

View file

@ -7,7 +7,12 @@
"esModuleInterop": true,
"moduleResolution": "Node",
"outDir": "dist",
"skipLibCheck": true
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@": ["src/*"]
}
},
"exclude": ["node_modules", "dist"],
"include": ["src"]

View file

@ -5,6 +5,7 @@ import { viteStaticCopy } from "vite-plugin-static-copy";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import inject from "@rollup/plugin-inject";
import { svgLoader } from "./viteSvgLoader";
import path from "path";
const copyFiles = {
targets: [
@ -35,6 +36,11 @@ export default defineConfig({
port: 8080,
host: true,
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
plugins: [viteStaticCopy(copyFiles), svgLoader(), wasm(), react()],
optimizeDeps: {
esbuildOptions: {