-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
831bb83
commit 32482cc
Showing
6 changed files
with
149 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { useEffect } from 'react'; | ||
|
||
import initMatrix from '../../client/initMatrix'; | ||
|
||
import { useForceUpdate } from './useForceUpdate'; | ||
|
||
export function useRoomStateUpdate(roomId) { | ||
const [, forceUpdate] = useForceUpdate(); | ||
const mx = initMatrix.matrixClient; | ||
|
||
useEffect(() => { | ||
const handleStateEvent = (event) => { | ||
if (event.getRoomId() !== roomId) return; | ||
forceUpdate(); | ||
}; | ||
|
||
mx.on('RoomState.events', handleStateEvent); | ||
return () => { | ||
mx.removeListener('RoomState.events', handleStateEvent); | ||
}; | ||
}, [roomId]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import './RoomIntegrations.scss'; | ||
|
||
import { getHttpUriForMxc } from 'matrix-js-sdk'; | ||
import { blurOnBubbling } from '../../atoms/button/script'; | ||
|
||
import initMatrix from '../../../client/initMatrix'; | ||
import colorMXID from '../../../util/colorMXID'; | ||
|
||
import Avatar from '../../atoms/avatar/Avatar'; | ||
import Text from '../../atoms/text/Text'; | ||
import { MenuHeader } from '../../atoms/context-menu/ContextMenu'; | ||
import { useRoomStateUpdate } from '../../hooks/useRoomStateUpdate'; | ||
|
||
function Bridge({ | ||
name, bot, avatarSrc, channel, url, | ||
}) { | ||
return ( | ||
<div className="bridge__container"> | ||
<a | ||
className="bridge" | ||
href={url} | ||
onMouseUp={(e) => blurOnBubbling(e, '.bridge')} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
<Avatar imageSrc={avatarSrc} bgColor={colorMXID(bot)} text={name} size="small" /> | ||
<div className="bridge__text"> | ||
<Text variant="b1">{name}</Text> | ||
<Text variant="b3">{channel}</Text> | ||
</div> | ||
</a> | ||
</div> | ||
); | ||
} | ||
|
||
Bridge.defaultProps = { | ||
bot: null, | ||
avatarSrc: null, | ||
url: null, | ||
}; | ||
|
||
Bridge.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
bot: PropTypes.string, | ||
avatarSrc: PropTypes.string, | ||
channel: PropTypes.string.isRequired, | ||
url: PropTypes.string, | ||
}; | ||
|
||
function RoomIntegrations({ roomId }) { | ||
useRoomStateUpdate(roomId); | ||
const mx = initMatrix.matrixClient; | ||
const room = mx.getRoom(roomId); | ||
const bEvents = room.currentState.getStateEvents('uk.half-shot.bridge'); | ||
|
||
return ( | ||
<div className="room-integrations__bridges"> | ||
<MenuHeader>Bridges</MenuHeader> | ||
{bEvents.map((event) => { | ||
const { protocol, channel, bridgebot } = event.getContent(); | ||
return ( | ||
<Bridge | ||
key={event.state_key} | ||
name={protocol?.displayname} | ||
bot={bridgebot} | ||
avatarSrc={getHttpUriForMxc(mx.baseUrl, protocol?.avatar_url, 36, 36, 'crop')} | ||
channel={channel?.displayname || channel?.id} | ||
url={channel?.external_url || protocol?.external_url} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
RoomIntegrations.propTypes = { | ||
roomId: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default RoomIntegrations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.bridge { | ||
width: 100%; | ||
padding: var(--sp-extra-tight) var(--sp-normal); | ||
display: flex; | ||
align-items: center; | ||
|
||
&__container { | ||
display: flex; | ||
} | ||
|
||
@media (hover: hover) { | ||
&:hover { | ||
background-color: var(--bg-surface-hover); | ||
text-decoration: none; | ||
} | ||
} | ||
&:focus { | ||
outline: none; | ||
background-color: var(--bg-surface-hover); | ||
} | ||
&:active { | ||
background-color: var(--bg-surface-active); | ||
} | ||
|
||
&__text { | ||
margin-left: var(--sp-tight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters