mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
web/roomview: scroll timeline to bottom on resize
This commit is contained in:
parent
0512945c57
commit
b352255d14
3 changed files with 16 additions and 7 deletions
|
@ -13,7 +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 { JSX, useRef } from "react"
|
||||
import { JSX, useEffect, useState } from "react"
|
||||
import { RoomStateStore } from "@/api/statestore"
|
||||
import MessageComposer from "../composer/MessageComposer.tsx"
|
||||
import TypingNotifications from "../composer/TypingNotifications.tsx"
|
||||
|
@ -30,11 +30,18 @@ interface RoomViewProps {
|
|||
}
|
||||
|
||||
const RoomView = ({ room, rightPanelResizeHandle, rightPanel }: RoomViewProps) => {
|
||||
const roomContextDataRef = useRef<RoomContextData | undefined>(undefined)
|
||||
if (roomContextDataRef.current === undefined) {
|
||||
roomContextDataRef.current = new RoomContextData(room)
|
||||
}
|
||||
return <RoomContext value={roomContextDataRef.current}>
|
||||
const [roomContextData] = useState(() => new RoomContextData(room))
|
||||
useEffect(() => {
|
||||
window.activeRoomContext = roomContextData
|
||||
window.addEventListener("resize", roomContextData.scrollToBottom)
|
||||
return () => {
|
||||
window.removeEventListener("resize", roomContextData.scrollToBottom)
|
||||
if (window.activeRoomContext === roomContextData) {
|
||||
window.activeRoomContext = undefined
|
||||
}
|
||||
}
|
||||
}, [roomContextData])
|
||||
return <RoomContext value={roomContextData}>
|
||||
<div className="room-view">
|
||||
<RoomViewHeader room={room}/>
|
||||
<TimelineView/>
|
||||
|
|
|
@ -34,7 +34,7 @@ export class RoomContextData {
|
|||
|
||||
constructor(public store: RoomStateStore) {}
|
||||
|
||||
scrollToBottom() {
|
||||
scrollToBottom = () => {
|
||||
if (this.scrolledToBottom) {
|
||||
this.timelineBottomRef.current?.scrollIntoView()
|
||||
}
|
||||
|
|
2
web/src/vite-env.d.ts
vendored
2
web/src/vite-env.d.ts
vendored
|
@ -4,11 +4,13 @@
|
|||
import type Client from "@/api/client.ts"
|
||||
import type { GCSettings, RoomStateStore } from "@/api/statestore"
|
||||
import type { MainScreenContextFields } from "@/ui/MainScreenContext.ts"
|
||||
import type { RoomContextData } from "@/ui/roomview/roomcontext.ts"
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
client: Client
|
||||
activeRoom?: RoomStateStore | null
|
||||
activeRoomContext?: RoomContextData
|
||||
mainScreenContext: MainScreenContextFields
|
||||
openLightbox: (params: { src: string, alt: string }) => void
|
||||
gcSettings: GCSettings
|
||||
|
|
Loading…
Add table
Reference in a new issue