From e7353e184fe73747e8663cdd4d2ef488762e0f37 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 25 Aug 2022 11:43:47 +0100 Subject: [PATCH] Fix groupcall debug info in rageshakes We were putting the whole array from setState in, so the debug info was wrapped in an array when it shouldn't be. Also comment the groupCallInspector setState/context dance which I now *finally* understand. --- src/room/GroupCallInspector.tsx | 7 +++++-- src/settings/submit-rageshake.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/room/GroupCallInspector.tsx b/src/room/GroupCallInspector.tsx index 48d3d35..80dcbac 100644 --- a/src/room/GroupCallInspector.tsx +++ b/src/room/GroupCallInspector.tsx @@ -121,8 +121,11 @@ export function InspectorContextProvider({ }: { children: React.ReactNode; }) { - // The context will be initialized empty. - // It is then set from within GroupCallInspector. + // We take the tuple of [currentState, setter] and stick + // it straight into the context for other things to call + // the setState method... this feels like a fairly severe + // contortion of the hooks API - is this really the best way + // to do this? const context = useState({}); return ( diff --git a/src/settings/submit-rageshake.ts b/src/settings/submit-rageshake.ts index 26a0b60..5128030 100644 --- a/src/settings/submit-rageshake.ts +++ b/src/settings/submit-rageshake.ts @@ -40,7 +40,9 @@ export function useSubmitRageshake(): { error: Error; } { const client: MatrixClient = useClient().client; - const json = useContext(InspectorContext); + // The value of the context is the whole tuple returned from setState, + // so we just want the current state. + const [inspectorState] = useContext(InspectorContext); const [{ sending, sent, error }, setState] = useState({ sending: false, @@ -231,10 +233,12 @@ export function useSubmitRageshake(): { body.append("compressed-log", new Blob([buf]), entry.id); } - if (json) { + if (inspectorState) { body.append( "file", - new Blob([JSON.stringify(json)], { type: "text/plain" }), + new Blob([JSON.stringify(inspectorState)], { + type: "text/plain", + }), "groupcall.txt" ); } @@ -262,7 +266,7 @@ export function useSubmitRageshake(): { console.error(error); } }, - [client, json, sending] + [client, inspectorState, sending] ); return {