forked from Mirrors/gomuks
web/rightpanel: close when same button is clicked again
This commit is contained in:
parent
5095019f45
commit
54234036a7
1 changed files with 9 additions and 2 deletions
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import { use, useCallback, useLayoutEffect, useMemo, useState } from "react"
|
import { use, useCallback, useLayoutEffect, useMemo, useReducer, useState } from "react"
|
||||||
import type { RoomID } from "@/api/types"
|
import type { RoomID } from "@/api/types"
|
||||||
import ClientContext from "./ClientContext.ts"
|
import ClientContext from "./ClientContext.ts"
|
||||||
import MainScreenContext, { MainScreenContextFields } from "./MainScreenContext.ts"
|
import MainScreenContext, { MainScreenContextFields } from "./MainScreenContext.ts"
|
||||||
|
@ -23,9 +23,16 @@ import RoomView from "./roomview/RoomView.tsx"
|
||||||
import { useResizeHandle } from "./util/useResizeHandle.tsx"
|
import { useResizeHandle } from "./util/useResizeHandle.tsx"
|
||||||
import "./MainScreen.css"
|
import "./MainScreen.css"
|
||||||
|
|
||||||
|
const rpReducer = (prevState: RightPanelProps | null, newState: RightPanelProps | null) => {
|
||||||
|
if (prevState?.type === newState?.type) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return newState
|
||||||
|
}
|
||||||
|
|
||||||
const MainScreen = () => {
|
const MainScreen = () => {
|
||||||
const [activeRoomID, setActiveRoomID] = useState<RoomID | null>(null)
|
const [activeRoomID, setActiveRoomID] = useState<RoomID | null>(null)
|
||||||
const [rightPanel, setRightPanel] = useState<RightPanelProps | null>(null)
|
const [rightPanel, setRightPanel] = useReducer(rpReducer, null)
|
||||||
const client = use(ClientContext)!
|
const client = use(ClientContext)!
|
||||||
const activeRoom = activeRoomID ? client.store.rooms.get(activeRoomID) : undefined
|
const activeRoom = activeRoomID ? client.store.rooms.get(activeRoomID) : undefined
|
||||||
const setActiveRoom = useCallback((roomID: RoomID) => {
|
const setActiveRoom = useCallback((roomID: RoomID) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue