Skip to content

Commit 309c216

Browse files
author
Dylan Huang
committed
fix mobx warnings
1 parent 7aa03ce commit 309c216

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

vite-app/src/App.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const App = observer(() => {
3232

3333
ws.onopen = () => {
3434
console.log("Connected to file watcher");
35-
state.isConnected = true;
36-
state.isLoading = true; // Set loading when connection opens
35+
state.setConnected(true);
36+
state.setLoading(true); // Set loading when connection opens
3737
reconnectAttemptsRef.current = 0; // Reset reconnect attempts on successful connection
3838
};
3939

@@ -49,21 +49,21 @@ const App = observer(() => {
4949
console.log("initialize_logs", rows);
5050
state.upsertRows(rows);
5151
} else if (update.type === "log") {
52-
state.isLoading = true; // Set loading for individual log updates
52+
state.setLoading(true); // Set loading for individual log updates
5353
const row: EvaluationRow = EvaluationRowSchema.parse(update.row);
5454
console.log("log", row);
5555
state.upsertRows([row]);
5656
}
5757
} catch (error) {
5858
console.error("Failed to parse WebSocket message:", error);
59-
state.isLoading = false; // Clear loading state on error
59+
state.setLoading(false); // Clear loading state on error
6060
}
6161
};
6262

6363
ws.onclose = (event) => {
6464
console.log("Disconnected from file watcher", event.code, event.reason);
65-
state.isConnected = false;
66-
state.isLoading = false; // Clear loading state on disconnect
65+
state.setConnected(false);
66+
state.setLoading(false); // Clear loading state on disconnect
6767

6868
// Attempt to reconnect if not a normal closure
6969
if (
@@ -76,8 +76,8 @@ const App = observer(() => {
7676

7777
ws.onerror = (error) => {
7878
console.error("WebSocket error:", error);
79-
state.isConnected = false;
80-
state.isLoading = false; // Clear loading state on error
79+
state.setConnected(false);
80+
state.setLoading(false); // Clear loading state on error
8181
};
8282
};
8383

@@ -104,7 +104,7 @@ const App = observer(() => {
104104

105105
// Manual refresh handler
106106
const handleManualRefresh = () => {
107-
state.isLoading = true; // Set loading when manually refreshing
107+
state.setLoading(true); // Set loading when manually refreshing
108108
if (wsRef.current) {
109109
try {
110110
wsRef.current.onclose = null; // Prevent triggering reconnect logic

vite-app/src/GlobalState.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { makeAutoObservable } from "mobx";
1+
import { makeAutoObservable, runInAction } from "mobx";
22
import type { EvaluationRow } from "./types/eval-protocol";
33
import type { PivotConfig } from "./types/filters";
44
import flattenJson from "./util/flatten-json";
@@ -147,18 +147,34 @@ export class GlobalState {
147147
this.savePaginationConfig();
148148
}
149149

150+
// Set loading state
151+
setLoading(loading: boolean) {
152+
this.isLoading = loading;
153+
}
154+
155+
// Set connection state
156+
setConnected(connected: boolean) {
157+
this.isConnected = connected;
158+
}
159+
150160
upsertRows(dataset: EvaluationRow[]) {
151-
this.isLoading = true;
161+
runInAction(() => {
162+
this.isLoading = true;
163+
});
164+
152165
dataset.forEach((row) => {
153166
if (!row.execution_metadata?.rollout_id) {
154167
return;
155168
}
156169
this.dataset[row.execution_metadata.rollout_id] = row;
157170
});
158-
// Reset to first page when dataset changes
159-
this.currentPage = 1;
171+
172+
runInAction(() => {
173+
// Reset to first page when dataset changes
174+
this.currentPage = 1;
175+
this.isLoading = false;
176+
});
160177
this.savePaginationConfig();
161-
this.isLoading = false;
162178
}
163179

164180
toggleRowExpansion(rolloutId?: string) {

0 commit comments

Comments
 (0)