Skip to content

Commit

Permalink
web/composer: don't allow media to be too wide
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 25, 2025
1 parent 15238b6 commit c2ab65e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions web/src/ui/composer/ComposerMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { RefCallback, useState } from "react"
import Client from "@/api/client.ts"
import { RoomStateStore, usePreference } from "@/api/statestore"
import type { MediaMessageEventContent } from "@/api/types"
Expand All @@ -27,10 +28,19 @@ export interface ComposerMediaProps {
}

export const ComposerMedia = ({ content, clearMedia }: ComposerMediaProps) => {
const defaultMaxWidth = 360
const paddingAndButtonWidth = 16 + 40
const [maxWidth, setMaxWidth] = useState(defaultMaxWidth)
const [mediaContent, containerClass, containerStyle] = useMediaContent(
content, "m.room.message", { height: 120, width: 360 },
content, "m.room.message", { height: 120, width: maxWidth },
)
return <div className="composer-media">
const containerRef: RefCallback<HTMLDivElement> = elem => {
setMaxWidth(Math.min(
(elem?.getBoundingClientRect().width ?? defaultMaxWidth) - paddingAndButtonWidth,
defaultMaxWidth,
))
}
return <div className="composer-media" ref={containerRef}>
<div className={`media-container ${containerClass}`} style={containerStyle}>
{mediaContent}
</div>
Expand Down

0 comments on commit c2ab65e

Please sign in to comment.