(null)
const [rightPanel, setRightPanel] = useReducer(rpReducer, null)
const client = use(ClientContext)!
const syncStatus = useEventAsState(client.syncStatus)
const context = useMemo(
() => new ContextFields(setRightPanel, directSetActiveRoom, client),
[client],
)
useLayoutEffect(() => {
window.mainScreenContext = context
}, [context])
useEffect(() => context.keybindings.listen(), [context])
useInsertionEffect(() => {
const styleTags = document.createElement("style")
styleTags.textContent = `
div.html-body > a.hicli-matrix-uri-user[href="matrix:u/${client.userID.slice(1).replaceAll(`"`, `\\"`)}"] {
background-color: var(--highlight-pill-background-color);
color: var(--highlight-pill-text-color);
}
`
document.head.appendChild(styleTags)
return () => {
document.head.removeChild(styleTags)
}
}, [client.userID])
const [roomListWidth, resizeHandle1] = useResizeHandle(
300, 48, 900, "roomListWidth", { className: "room-list-resizer" },
)
const [rightPanelWidth, resizeHandle2] = useResizeHandle(
300, 100, 900, "rightPanelWidth", { className: "right-panel-resizer", inverted: true },
)
const extraStyle = {
["--room-list-width" as string]: `${roomListWidth}px`,
["--right-panel-width" as string]: `${rightPanelWidth}px`,
}
const classNames = ["matrix-main"]
if (activeRoom) {
classNames.push("room-selected")
}
if (rightPanel) {
classNames.push("right-panel-open")
}
let syncLoader: JSX.Element | null = null
if (syncStatus.type === "waiting") {
syncLoader =
Waiting for first sync...
} else if (
syncStatus.type === "errored"
&& (syncStatus.error_count > 2 || (syncStatus.last_sync ?? 0) + SYNC_ERROR_HIDE_DELAY < Date.now())
) {
syncLoader =
Sync is failing
}
return
{resizeHandle1}
{activeRoom
?
: rightPanel && <>
{resizeHandle2}
{rightPanel && }
>}
{syncLoader}
}
export default MainScreen