This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dialog to navigate long room topics (#8517)
- v3.109.0
- v3.109.0-rc.0
- v3.108.0
- v3.108.0-rc.0
- v3.107.0
- v3.106.0
- v3.106.0-rc.1
- v3.106.0-rc.0
- v3.105.1
- v3.105.0
- v3.104.0
- v3.104.0-rc.1
- v3.104.0-rc.0
- v3.103.0
- v3.103.0-rc.1
- v3.103.0-rc.0
- v3.102.0
- v3.102.0-rc.1
- v3.102.0-rc.0
- v3.101.0
- v3.101.0-rc.1
- v3.101.0-rc.0
- v3.100.0
- v3.100.0-rc.1
- v3.100.0-rc.0
- v3.99.0
- v3.99.0-rc.1
- v3.99.0-rc.0
- v3.98.0
- v3.98.0-rc.0
- v3.97.0
- v3.97.0-rc.0
- v3.96.1
- v3.96.0
- v3.96.0-rc.0
- v3.95.0
- v3.95.0-rc.0
- v3.94.0
- v3.94.0-rc.0
- v3.93.0
- v3.93.0-rc.0
- v3.92.0
- v3.92.0-rc.1
- v3.92.0-rc.0
- v3.91.0
- v3.91.0-rc.1
- v3.91.0-rc.0
- v3.90.0
- v3.89.0
- v3.89.0-rc.0
- v3.88.0
- v3.87.0
- v3.87.0-rc.0
- v3.86.0
- v3.86.0-rc.2
- v3.86.0-rc.1
- v3.86.0-rc.0
- v3.85.0
- v3.85.0-rc.1
- v3.85.0-rc.0
- v3.84.1
- v3.84.0
- v3.84.0-rc.1
- v3.83.0
- v3.83.0-rc.1
- v3.82.0
- v3.82.0-rc.1
- v3.81.1
- v3.81.0
- v3.81.0-rc.1
- v3.80.1
- v3.80.0
- v3.80.0-rc.2
- v3.80.0-rc.1
- v3.79.0
- v3.79.0-rc.2
- v3.79.0-rc.1
- v3.78.0
- v3.78.0-rc.1
- v3.77.1
- v3.77.0
- v3.77.0-rc.1
- v3.76.0
- v3.76.0-rc.2
- v3.76.0-rc.1
- v3.75.0
- v3.75.0-rc.1
- v3.75.0-no-media-devices-hotfix
- v3.74.0
- v3.74.0-rc1
- v3.73.1
- v3.73.0
- v3.73.0-rc.3
- v3.73.0-rc.2
- v3.73.0-rc.1
- v3.72.0
- v3.72.0-rc.2
- v3.72.0-rc.1
- v3.71.1
- v3.71.0
- v3.71.0-rc.1
- v3.70.0
- v3.70.0-rc.1
- v3.69.1
- v3.69.0
- v3.68.0
- v3.68.0-rc.3
- v3.68.0-rc.2
- v3.68.0-rc.1
- v3.67.0
- v3.67.0-rc.2
- v3.67.0-rc.1
- v3.66.0
- v3.66.0-rc.1
- v3.65.0
- v3.65.0-rc.1
- v3.64.2
- v3.64.1
- v3.64.0
- v3.64.0-rc.4
- v3.64.0-rc.3
- v3.64.0-rc.2
- v3.64.0-rc.1
- v3.63.0
- v3.63.0-rc.2
- v3.63.0-rc.1
- v3.62.0
- v3.62.0-rc.2
- v3.62.0-rc.1
- v3.61.0
- v3.61.0-rc.1
- v3.60.0
- v3.60.0-rc.2
- v3.60.0-rc.1
- v3.59.1
- v3.59.0
- v3.59.0-rc.2
- v3.59.0-rc.1
- v3.58.1
- v3.58.0
- v3.58.0-rc.2
- v3.58.0-rc.1
- v3.57.0
- v3.56.0
- v3.55.0
- v3.55.0-rc.1
- v3.54.0
- v3.54.0-rc.1
- v3.53.0
- v3.53.0-rc.2
- v3.53.0-rc.1
- v3.52.0
- v3.52.0-rc.2
- v3.52.0-rc.1
- v3.51.0
- v3.51.0-rc.1
- v3.50.0
- v3.49.0
- v3.49.0-rc.2
- v3.49.0-rc.1
- v3.48.0
- v3.48.0-rc.1
- v3.47.0
- v3.46.0
- v3.46.0-rc.1
- v3.45.0
- v3.45.0-rc.3
- v3.45.0-rc.2
- v3.45.0-rc.1
- no-media-devices-release
Germain
authored
May 13, 2022
1 parent
e0415d0
commit fdd5494
Showing
13 changed files
with
347 additions
and
41 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
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, useRef } from "react"; | ||
import linkifyElement from "linkify-element"; | ||
|
||
interface Props { | ||
as?: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function Linkify({ | ||
as = "div", | ||
children, | ||
}: Props): JSX.Element { | ||
const ref = useRef(); | ||
|
||
useEffect(() => { | ||
linkifyElement(ref.current); | ||
}, [children]); | ||
|
||
return React.createElement(as, { | ||
children, | ||
ref, | ||
}); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
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 { 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2021 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, { useState } from "react"; | ||
import { mount } from "enzyme"; | ||
|
||
import { Linkify } from "../../../../src/components/views/elements/Linkify"; | ||
|
||
describe("Linkify", () => { | ||
it("linkifies the context", () => { | ||
const wrapper = mount(<Linkify> | ||
https://perdu.com | ||
</Linkify>); | ||
expect(wrapper.html()).toBe('<div><a href="https://perdu.com">https://perdu.com</a></div>'); | ||
}); | ||
|
||
it("changes the root tag name", () => { | ||
const TAG_NAME = "p"; | ||
|
||
const wrapper = mount(<Linkify as={TAG_NAME}> | ||
Hello world! | ||
</Linkify>); | ||
|
||
expect(wrapper.find("p")).toHaveLength(1); | ||
}); | ||
|
||
it("relinkifies on update", () => { | ||
function DummyTest() { | ||
const [n, setN] = useState(0); | ||
function onClick() { | ||
setN(n + 1); | ||
} | ||
|
||
// upon clicking the element, change the content, and expect | ||
// linkify to update | ||
return <div onClick={onClick}> | ||
<Linkify> | ||
{ n % 2 === 0 | ||
? "https://perdu.com" | ||
: "https://matrix.org" } | ||
</Linkify> | ||
</div>; | ||
} | ||
|
||
const wrapper = mount(<DummyTest />); | ||
|
||
expect(wrapper.html()).toBe('<div><div><a href="https://perdu.com">https://perdu.com</a></div></div>'); | ||
|
||
wrapper.find('div').at(0).simulate('click'); | ||
|
||
expect(wrapper.html()).toBe('<div><div><a href="https://matrix.org">https://matrix.org</a></div></div>'); | ||
}); | ||
}); |
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,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"); | ||
}); | ||
}); |