Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Strictify spaces views
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Apr 6, 2023
1 parent 567248d commit 7ba2c54
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/accessibility/RovingTabIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const useRovingTabIndex = <T extends HTMLElement>(
inputRef?: RefObject<T>,
): [FocusHandler, boolean, RefObject<T>] => {
const context = useContext(RovingTabIndexContext);
let ref = useRef<T>(null);
let ref: RefObject<T> = useRef<T>(null);

if (inputRef) {
// if we are given a ref, use it instead of ours
Expand Down
3 changes: 2 additions & 1 deletion src/components/structures/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ export const useContextMenu = <T extends any = HTMLElement>(inputRef?: RefObject
setIsOpen(false);
};

return [button.current ? isOpen : false, button, open, close, setIsOpen];
const hasButton = typeof button !== "function" && button.current;
return [hasButton ? isOpen : false, button, open, close, setIsOpen];
};

// XXX: Deprecated, used only for dynamic Tooltips. Avoid using at all costs.
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/spaces/SpaceBasicSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 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.
Expand Down Expand Up @@ -38,7 +38,7 @@ export const SpaceAvatar: React.FC<Pick<IProps, "avatarUrl" | "avatarDisabled" |
avatarDisabled = false,
setAvatar,
}) => {
const avatarUploadRef = useRef<HTMLInputElement>();
const avatarUploadRef = useRef<HTMLInputElement>(null);
const [avatar, setAvatarDataUrl] = useState(avatarUrl); // avatar data url cache

let avatarSection;
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/spaces/SpaceCreateMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 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.
Expand Down Expand Up @@ -251,9 +251,9 @@ const SpaceCreateMenu: React.FC<{
const [busy, setBusy] = useState<boolean>(false);

const [name, setName] = useState("");
const spaceNameField = useRef<Field>();
const spaceNameField = useRef<Field>(null);
const [alias, setAlias] = useState("");
const spaceAliasField = useRef<RoomAliasField>();
const spaceAliasField = useRef<RoomAliasField | null>(null);
const [avatar, setAvatar] = useState<File | undefined>(undefined);
const [topic, setTopic] = useState<string>("");

Expand Down
8 changes: 5 additions & 3 deletions src/components/views/spaces/SpacePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 - 2022 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 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.
Expand Down Expand Up @@ -331,9 +331,11 @@ const InnerSpacePanel = React.memo<IInnerSpacePanelProps>(

const SpacePanel: React.FC = () => {
const [isPanelCollapsed, setPanelCollapsed] = useState(true);
const ref = useRef<HTMLDivElement>();
const ref = useRef<HTMLDivElement>(null);

useLayoutEffect(() => {
UIStore.instance.trackElementDimensions("SpacePanel", ref.current);
// ref.current should always be set in useLayoutEffect
UIStore.instance.trackElementDimensions("SpacePanel", ref.current!);
return () => UIStore.instance.stopTrackingElementDimensions("SpacePanel");
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/components/views/spaces/SpacePublicShare.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 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.
Expand Down Expand Up @@ -55,7 +55,7 @@ const SpacePublicShare: React.FC<IProps> = ({ space, onFinished }) => {
<h3>{_t("Share invite link")}</h3>
<span>{copiedText}</span>
</AccessibleButton>
{space.canInvite(MatrixClientPeg.get()?.getUserId()) && shouldShowComponent(UIComponent.InviteUsers) ? (
{space.canInvite(MatrixClientPeg.get()?.getSafeUserId()) && shouldShowComponent(UIComponent.InviteUsers) ? (
<AccessibleButton
className="mx_SpacePublicShare_inviteButton"
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/spaces/SpaceTreeLevel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021 - 2023 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.
Expand Down

0 comments on commit 7ba2c54

Please sign in to comment.