|
1 | 1 | import { useState, useEffect, useCallback } from 'react' |
2 | | -import { Newspaper, RefreshCw, Settings, Check, Clock, AlertCircle, Zap } from 'lucide-react' |
| 2 | +import { Loader2, Newspaper, RefreshCw, Settings, Check, Clock, AlertCircle, Zap } from 'lucide-react' |
3 | 3 | import { slackDigestAPI, digestPreferencesAPI } from '@/lib/api/client' |
4 | 4 | import { useConnectionManager } from '@/lib/hooks/useConnectionManager' |
5 | 5 | import DigestPreferencesPanel from './DigestPreferencesPanel' |
@@ -165,7 +165,7 @@ function DigestSection({ section }) { |
165 | 165 | const DIGEST_PREFS_AUTOPEN_KEY = 'deepsql.digestPrefs.autoOpened.v1' |
166 | 166 |
|
167 | 167 | export default function DigestFeedSection() { |
168 | | - const { connectionId, selectedConnection } = useConnectionManager() |
| 168 | + const { connectionId, selectedConnection, isLoading: connectionsLoading } = useConnectionManager() |
169 | 169 | const [digests, setDigests] = useState([]) |
170 | 170 | const [loading, setLoading] = useState(false) |
171 | 171 | const [triggering, setTriggering] = useState(false) |
@@ -257,6 +257,26 @@ export default function DigestFeedSection() { |
257 | 257 | } |
258 | 258 | } |
259 | 259 |
|
| 260 | + // Wait for connection list to load first |
| 261 | + if (connectionsLoading) { |
| 262 | + return ( |
| 263 | + <div className={styles.root}> |
| 264 | + <div className={styles.topBar}> |
| 265 | + <div className={styles.topBarLeft}> |
| 266 | + <Newspaper size={17} className={styles.topBarIcon} /> |
| 267 | + <span className={styles.topBarTitle}>DB Digest</span> |
| 268 | + </div> |
| 269 | + </div> |
| 270 | + <div className={styles.feed}> |
| 271 | + <div className={styles.loadingState}> |
| 272 | + <Loader2 size={20} className={styles.spinning} color="#9ca3af" /> |
| 273 | + <span>Loading connections…</span> |
| 274 | + </div> |
| 275 | + </div> |
| 276 | + </div> |
| 277 | + ) |
| 278 | + } |
| 279 | + |
260 | 280 | return ( |
261 | 281 | <div className={styles.root}> |
262 | 282 | {/* Top bar */} |
@@ -309,15 +329,16 @@ export default function DigestFeedSection() { |
309 | 329 | </div> |
310 | 330 | )} |
311 | 331 |
|
312 | | - {!error && !loading && !connectionId && ( |
| 332 | + {/* Either no connection or stale connectionId not in the effective user's list */} |
| 333 | + {!error && !loading && (!connectionId || !selectedConnection) && ( |
313 | 334 | <div className={styles.emptyState}> |
314 | 335 | <Newspaper size={32} color="#d1d5db" /> |
315 | 336 | <h3>No connection selected</h3> |
316 | 337 | <p>Select a connection to view its digest history.</p> |
317 | 338 | </div> |
318 | 339 | )} |
319 | 340 |
|
320 | | - {!error && !loading && !!connectionId && digests.length === 0 && ( |
| 341 | + {!error && !loading && !!connectionId && !!selectedConnection && digests.length === 0 && ( |
321 | 342 | <div className={styles.emptyState}> |
322 | 343 | <Newspaper size={32} color="#d1d5db" /> |
323 | 344 | <h3>No digests yet</h3> |
|
0 commit comments