Skip to content

Commit

Permalink
Display loading spinner and status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Dec 10, 2024
1 parent b9e0f66 commit ab3ddb6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<input id="stepfwd" type="button" value="&rarr;" />
<input id="shimurl" type="text" value="https://tardis.element.dev/" placeholder="Shim URL" />
<input id="resolve" type="button" value="Resolve State" />
<div class="loader" id="loader"></div>
<span class="loader-status" id="loader-status"></span>
</div>
<div id="infocontainer">
<pre id="closeinfocontainer">[ Close ]</pre>
Expand Down
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,20 @@ if (existingShimUrl) {
dag.setShimUrl(existingShimUrl);
}

const loaderElement = document.getElementById("loader")!;
const loaderMsgElement = document.getElementById("loader-status")!;

const setLoaderMessage = (text: string) => {
loaderMsgElement.innerText = text;
};

document.getElementById("resolve")!.addEventListener("click", async (ev) => {
if (!dag.shimUrl) {
console.error("you need to set a shim url to resolve state!");
return {};
}
console.log(dag.shimUrl);
loaderElement.style.display = "block";
setLoaderMessage(`Connecting to ${dag.shimUrl}`);
try {
await transport.connect(dag.shimUrl, resolver);
await dag.debugger.resolve(
Expand All @@ -382,19 +390,23 @@ document.getElementById("resolve")!.addEventListener("click", async (ev) => {
atEvent: MatrixEvent,
): Promise<Record<StateKeyTuple, EventID>> => {
try {
setLoaderMessage(`Resolving state at event ${atEvent.event_id}`);
const r = await resolver.resolveState(roomId, roomVer, states, atEvent);
return r.state;
} catch (err) {
console.error("failed to resolve state:", err);
setLoaderMessage(`Failed to resolve state at event ${atEvent.event_id} : ${err}`);
throw err;
}
return {};
},
);
setLoaderMessage("");
} catch (err) {
console.error("failed to setup WS connection:", err);
console.error("resolving state failed: ", err);
} finally {
transport.close();
}
loaderElement.style.display = "none";
dag.refresh();
});

Expand Down
4 changes: 4 additions & 0 deletions src/state_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class StateResolver implements StateResolverReceiver {
resolve({ state: {} });
return;
}
if (resolvedData.error && resolvedData.error !== "") {
reject(resolvedData.error);
return;
}
resolve({
state: resolvedData.result,
});
Expand Down
21 changes: 21 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ body {
border-color: #00060b;
border: 1px solid;
margin: 5px;
display: flex;
}

#infocontainer {
Expand Down Expand Up @@ -82,6 +83,26 @@ body {
flex-grow: 1;
}

.loader {
border: 3px solid #f3f3f3; /* Light grey */
border-top: 3px solid #3498db; /* Blue */
border-radius: 50%;
width: 16px;
height: 16px;
animation: spin 1s linear infinite;
margin: 0 10 0 10;
display: none;
}

.loader-status {

}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

.node-text {
font-family: Gill Sans,Gill Sans MT,Calibri,sans-serif;
}
Expand Down

0 comments on commit ab3ddb6

Please sign in to comment.