Skip to content

Commit 7aa03ce

Browse files
author
Dylan Huang
committed
add loading state
1 parent 4e5584c commit 7aa03ce

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

vite-app/src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const App = observer(() => {
3333
ws.onopen = () => {
3434
console.log("Connected to file watcher");
3535
state.isConnected = true;
36+
state.isLoading = true; // Set loading when connection opens
3637
reconnectAttemptsRef.current = 0; // Reset reconnect attempts on successful connection
3738
};
3839

@@ -48,18 +49,21 @@ const App = observer(() => {
4849
console.log("initialize_logs", rows);
4950
state.upsertRows(rows);
5051
} else if (update.type === "log") {
52+
state.isLoading = true; // Set loading for individual log updates
5153
const row: EvaluationRow = EvaluationRowSchema.parse(update.row);
5254
console.log("log", row);
5355
state.upsertRows([row]);
5456
}
5557
} catch (error) {
5658
console.error("Failed to parse WebSocket message:", error);
59+
state.isLoading = false; // Clear loading state on error
5760
}
5861
};
5962

6063
ws.onclose = (event) => {
6164
console.log("Disconnected from file watcher", event.code, event.reason);
6265
state.isConnected = false;
66+
state.isLoading = false; // Clear loading state on disconnect
6367

6468
// Attempt to reconnect if not a normal closure
6569
if (
@@ -73,6 +77,7 @@ const App = observer(() => {
7377
ws.onerror = (error) => {
7478
console.error("WebSocket error:", error);
7579
state.isConnected = false;
80+
state.isLoading = false; // Clear loading state on error
7681
};
7782
};
7883

@@ -99,6 +104,7 @@ const App = observer(() => {
99104

100105
// Manual refresh handler
101106
const handleManualRefresh = () => {
107+
state.isLoading = true; // Set loading when manually refreshing
102108
if (wsRef.current) {
103109
try {
104110
wsRef.current.onclose = null; // Prevent triggering reconnect logic

vite-app/src/GlobalState.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export class GlobalState {
2929
// Pagination configuration
3030
currentPage: number;
3131
pageSize: number;
32+
// Loading state
33+
isLoading: boolean = true;
3234

3335
constructor() {
3436
// Load pivot config from localStorage or use defaults
@@ -65,7 +67,10 @@ export class GlobalState {
6567
return { ...DEFAULT_PAGINATION_CONFIG, ...parsed };
6668
}
6769
} catch (error) {
68-
console.warn("Failed to load pagination config from localStorage:", error);
70+
console.warn(
71+
"Failed to load pagination config from localStorage:",
72+
error
73+
);
6974
}
7075
return { ...DEFAULT_PAGINATION_CONFIG };
7176
}
@@ -82,10 +87,13 @@ export class GlobalState {
8287
// Save pagination configuration to localStorage
8388
private savePaginationConfig() {
8489
try {
85-
localStorage.setItem("paginationConfig", JSON.stringify({
86-
currentPage: this.currentPage,
87-
pageSize: this.pageSize,
88-
}));
90+
localStorage.setItem(
91+
"paginationConfig",
92+
JSON.stringify({
93+
currentPage: this.currentPage,
94+
pageSize: this.pageSize,
95+
})
96+
);
8997
} catch (error) {
9098
console.warn("Failed to save pagination config to localStorage:", error);
9199
}
@@ -98,7 +106,9 @@ export class GlobalState {
98106
}
99107

100108
// Update pagination configuration and save to localStorage
101-
updatePaginationConfig(updates: Partial<{ currentPage: number; pageSize: number }>) {
109+
updatePaginationConfig(
110+
updates: Partial<{ currentPage: number; pageSize: number }>
111+
) {
102112
if (updates.currentPage !== undefined) {
103113
this.currentPage = updates.currentPage;
104114
}
@@ -138,6 +148,7 @@ export class GlobalState {
138148
}
139149

140150
upsertRows(dataset: EvaluationRow[]) {
151+
this.isLoading = true;
141152
dataset.forEach((row) => {
142153
if (!row.execution_metadata?.rollout_id) {
143154
return;
@@ -147,6 +158,7 @@ export class GlobalState {
147158
// Reset to first page when dataset changes
148159
this.currentPage = 1;
149160
this.savePaginationConfig();
161+
this.isLoading = false;
150162
}
151163

152164
toggleRowExpansion(rolloutId?: string) {

vite-app/src/components/Dashboard.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ const EmptyState = ({ onRefresh }: { onRefresh: () => void }) => {
4949
);
5050
};
5151

52+
const LoadingState = () => {
53+
return (
54+
<div className="bg-white border border-gray-200 p-8 text-center">
55+
<div className="max-w-sm mx-auto">
56+
<div className="text-gray-400 mb-4">
57+
<div className="animate-spin rounded-full h-6 w-6 border-2 border-gray-300 border-t-gray-600 mx-auto"></div>
58+
</div>
59+
<h3 className="text-sm font-medium text-gray-900 mb-2">
60+
Loading evaluation data...
61+
</h3>
62+
<p className="text-xs text-gray-500">
63+
Connecting to the server and loading data
64+
</p>
65+
</div>
66+
</div>
67+
);
68+
};
69+
5270
const Dashboard = observer(({ onRefresh }: DashboardProps) => {
5371
const expandAll = () => state.setAllRowsExpanded(true);
5472
const collapseAll = () => state.setAllRowsExpanded(false);
@@ -81,7 +99,9 @@ const Dashboard = observer(({ onRefresh }: DashboardProps) => {
8199
</div>
82100

83101
{/* Content Area */}
84-
{state.totalCount === 0 ? (
102+
{state.isLoading ? (
103+
<LoadingState />
104+
) : state.totalCount === 0 ? (
85105
<EmptyState onRefresh={onRefresh} />
86106
) : (
87107
<div className="bg-white border border-gray-200">

0 commit comments

Comments
 (0)