This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 819
Add dialog to navigate long room topics #8517
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f8641be
Add useTopic hook
6617ea3
Add useHover hook
5b047a6
Make long room topic readable
3fc8dcc
Add useTopic tests
cc6468c
Add linkify side-effect for the room topic
2eed725
Lint fix on test file
664956b
Fix getTopic import
66659bf
PR fixes
5c79da0
lint fix
a76c1c3
Add linkify component
8f53e9d
Merge branch 'develop' into gsouquet/room-topic-9623
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
/* | ||
Copyright 2020 The Matrix.org Foundation C.I.C. | ||
germain-gg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { useEffect, useState } from "react"; | ||
import { EventType } from "matrix-js-sdk/src/@types/event"; | ||
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; | ||
import { Room } from "matrix-js-sdk/src/models/room"; | ||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; | ||
|
||
import { useTypedEventEmitter } from "../useEventEmitter"; | ||
|
||
export const getTopic = (room: Room) => { | ||
return room?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic; | ||
}; | ||
|
||
export function useTopic(room: Room): string { | ||
const [topic, setTopic] = useState(getTopic(room)); | ||
useTypedEventEmitter(room.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => { | ||
if (ev.getType() !== EventType.RoomTopic) return; | ||
setTopic(getTopic(room)); | ||
}); | ||
useEffect(() => { | ||
setTopic(getTopic(room)); | ||
}, [room]); | ||
|
||
return topic; | ||
} |
This file contains hidden or 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,42 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { useEffect, useState } from "react"; | ||
|
||
export default function useHover(ref: React.MutableRefObject<HTMLElement>) { | ||
const [hovered, setHoverState] = useState(false); | ||
|
||
const handleMouseOver = () => setHoverState(true); | ||
const handleMouseOut = () => setHoverState(false); | ||
|
||
useEffect( | ||
() => { | ||
const node = ref.current; | ||
if (node) { | ||
node.addEventListener("mouseover", handleMouseOver); | ||
node.addEventListener("mouseout", handleMouseOut); | ||
|
||
return () => { | ||
node.removeEventListener("mouseover", handleMouseOver); | ||
node.removeEventListener("mouseout", handleMouseOut); | ||
}; | ||
} | ||
}, | ||
[ref], | ||
); | ||
|
||
return hovered; | ||
} |
This file contains hidden or 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 hidden or 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,69 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from "react"; | ||
import { Room } from "matrix-js-sdk/src/models/room"; | ||
import { mount } from "enzyme"; | ||
import { act } from "react-dom/test-utils"; | ||
|
||
import { useTopic } from "../src/hooks/room/useTopic"; | ||
import { mkEvent, stubClient } from "./test-utils"; | ||
import { MatrixClientPeg } from "../src/MatrixClientPeg"; | ||
|
||
describe("useTopic", () => { | ||
it("should display the room topic", () => { | ||
stubClient(); | ||
const room = new Room("!TESTROOM", MatrixClientPeg.get(), "@alice:example.org"); | ||
const topic = mkEvent({ | ||
type: 'm.room.topic', | ||
room: '!TESTROOM', | ||
user: '@alice:example.org', | ||
content: { | ||
topic: 'Test topic', | ||
}, | ||
ts: 123, | ||
event: true, | ||
}); | ||
|
||
room.addLiveEvents([topic]); | ||
|
||
function RoomTopic() { | ||
const topic = useTopic(room); | ||
return <p>{ topic }</p>; | ||
} | ||
|
||
const wrapper = mount(<RoomTopic />); | ||
|
||
expect(wrapper.text()).toBe("Test topic"); | ||
|
||
const updatedTopic = mkEvent({ | ||
type: 'm.room.topic', | ||
room: '!TESTROOM', | ||
user: '@alice:example.org', | ||
content: { | ||
topic: 'New topic', | ||
}, | ||
ts: 666, | ||
event: true, | ||
}); | ||
|
||
act(() => { | ||
room.addLiveEvents([updatedTopic]); | ||
}); | ||
|
||
expect(wrapper.text()).toBe("New topic"); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.