From 6407cd4c0d2cdfd54e2f9c83bbace166f82bc763 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Thu, 25 Aug 2022 12:08:52 +0100
Subject: [PATCH] Reuse empty string & space string logic for event types in
devtools (#9218)
* Reuse empty string & space string logic for event types in devtools
* Fix edge case behaviours
* Make tsc quality higher
* Make remainder of tsc happy
---
.../views/dialogs/devtools/RoomState.tsx | 75 +++++++++----------
1 file changed, 37 insertions(+), 38 deletions(-)
diff --git a/src/components/views/dialogs/devtools/RoomState.tsx b/src/components/views/dialogs/devtools/RoomState.tsx
index d8a6fc0408..4ad4a1c821 100644
--- a/src/components/views/dialogs/devtools/RoomState.tsx
+++ b/src/components/views/dialogs/devtools/RoomState.tsx
@@ -41,6 +41,25 @@ export const StateEventEditor = ({ mxEvent, onBack }: IEditorProps) => {
return ;
};
+interface StateEventButtonProps {
+ label: string;
+ onClick(): void;
+}
+
+const StateEventButton = ({ label, onClick }: StateEventButtonProps) => {
+ const trimmed = label.trim();
+
+ return ;
+};
+
interface IEventTypeProps extends Pick {
eventType: string;
}
@@ -48,45 +67,35 @@ interface IEventTypeProps extends Pick {
const RoomStateExplorerEventType = ({ eventType, onBack }: IEventTypeProps) => {
const context = useContext(DevtoolsContext);
const [query, setQuery] = useState("");
- const [event, setEvent] = useState(null);
+ const [event, setEvent] = useState(null);
- const events = context.room.currentState.events.get(eventType);
+ const events = context.room.currentState.events.get(eventType)!;
useEffect(() => {
if (events.size === 1 && events.has("")) {
- setEvent(events.get(""));
+ setEvent(events.get("")!);
} else {
setEvent(null);
}
}, [events]);
if (event) {
- const onBack = () => {
- setEvent(null);
+ const _onBack = () => {
+ if (events?.size === 1 && events.has("")) {
+ onBack();
+ } else {
+ setEvent(null);
+ }
};
- return ;
+ return ;
}
return
{
- Array.from(events.entries()).map(([stateKey, ev]) => {
- const trimmed = stateKey.trim();
- const onClick = () => {
- setEvent(ev);
- };
-
- return ;
- })
+ Array.from(events.entries()).map(([stateKey, ev]) => (
+ setEvent(ev)} />
+ ))
}
;
@@ -95,11 +104,11 @@ const RoomStateExplorerEventType = ({ eventType, onBack }: IEventTypeProps) => {
export const RoomStateExplorer = ({ onBack, setTool }: IDevtoolsProps) => {
const context = useContext(DevtoolsContext);
const [query, setQuery] = useState("");
- const [eventType, setEventType] = useState(null);
+ const [eventType, setEventType] = useState(null);
const events = context.room.currentState.events;
- if (eventType) {
+ if (eventType !== null) {
const onBack = () => {
setEventType(null);
};
@@ -113,19 +122,9 @@ export const RoomStateExplorer = ({ onBack, setTool }: IDevtoolsProps) => {
return
{
- Array.from(events.keys()).map((eventType) => {
- const onClick = () => {
- setEventType(eventType);
- };
-
- return ;
- })
+ Array.from(events.keys()).map((eventType) => (
+ setEventType(eventType)} />
+ ))
}
;