Add room topic

This commit is contained in:
Michael Zhang 2023-03-31 18:16:02 -05:00
parent bd2b79c84d
commit e75fef6ba3
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 118 additions and 58 deletions

View file

@ -3,9 +3,8 @@
@use "../../partials/screen"; @use "../../partials/screen";
.room-header__btn { .room-header__btn {
min-width: 0;
@extend .cp-fx__row--s-c; @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); border-radius: var(--bo-radius);
cursor: pointer; 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 { .room-header__drawer-btn {
flex: 0;
@include screen.smallerThan(tabletBreakpoint) { @include screen.smallerThan(tabletBreakpoint) {
display: none; display: none;
} }
} }
.room-header__members-btn { .room-header__members-btn {
flex: 0;
@include screen.biggerThan(tabletBreakpoint) { @include screen.biggerThan(tabletBreakpoint) {
display: none; display: none;
} }
} }
.room-header__back-btn { .room-header__back-btn {
flex: 0;
@include dir.side(margin, 0, var(--sp-tight)); @include dir.side(margin, 0, var(--sp-tight));
@include screen.biggerThan(mobileBreakpoint) { @include screen.biggerThan(mobileBreakpoint) {
display: none; 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 React, { useEffect, useRef } from "react";
import PropTypes from "prop-types";
import "./RoomViewHeader.scss"; import "./RoomViewHeader.scss";
import { twemojify } from "../../../util/twemojify"; import { twemojify } from "../../../util/twemojify";
@ -33,16 +32,26 @@ import BackArrowIC from "../../../../public/res/ic/outlined/chevron-left.svg";
import { useForceUpdate } from "../../hooks/useForceUpdate"; import { useForceUpdate } from "../../hooks/useForceUpdate";
function RoomViewHeader({ roomId }) { interface RoomViewHeaderProps {
roomId: string;
}
function RoomViewHeader({ roomId }: RoomViewHeaderProps) {
const [, forceUpdate] = useForceUpdate(); const [, forceUpdate] = useForceUpdate();
const mx = initMatrix.matrixClient; const mx = initMatrix.matrixClient;
const isDM = initMatrix.roomList.directs.has(roomId); const isDM = initMatrix.roomList.directs.has(roomId);
const room = mx.getRoom(roomId); const room = mx.getRoom(roomId);
let avatarSrc = room.getAvatarUrl(mx.baseUrl, 36, 36, "crop"); let avatarSrc = room.getAvatarUrl(mx.baseUrl, 36, 36, "crop");
avatarSrc = isDM avatarSrc = isDM
? room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 36, 36, "crop") ? room
.getAvatarFallbackMember()
?.getAvatarUrl(mx.baseUrl, 36, 36, "crop", true, false)
: avatarSrc; : avatarSrc;
const roomName = room.name; const { name: roomName, currentState } = room;
const roomTopic = currentState
.getStateEvents("m.room.topic")[0]
?.getContent().topic;
const roomHeaderBtnRef = useRef(null); const roomHeaderBtnRef = useRef(null);
useEffect(() => { useEffect(() => {
@ -89,6 +98,7 @@ function RoomViewHeader({ roomId }) {
return ( return (
<Header> <Header>
<div class="room-header__left">
<IconButton <IconButton
src={BackArrowIC} src={BackArrowIC}
className="room-header__back-btn" className="room-header__back-btn"
@ -115,6 +125,15 @@ function RoomViewHeader({ roomId }) {
</TitleWrapper> </TitleWrapper>
<RawIcon src={ChevronBottomIC} /> <RawIcon src={ChevronBottomIC} />
</button> </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 && ( {mx.isRoomEncrypted(roomId) === false && (
<IconButton <IconButton
onClick={() => toggleRoomSettings(tabText.SEARCH)} onClick={() => toggleRoomSettings(tabText.SEARCH)}
@ -139,11 +158,9 @@ function RoomViewHeader({ roomId }) {
tooltip="Options" tooltip="Options"
src={VerticalMenuIC} src={VerticalMenuIC}
/> />
</div>
</Header> </Header>
); );
} }
RoomViewHeader.propTypes = {
roomId: PropTypes.string.isRequired,
};
export default RoomViewHeader; export default RoomViewHeader;

View file

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

View file

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