Skip to content

Real-time dashboard for monitoring global news, markets, and geopolitical events

TypeScript

Phase 5: Complete integration and cleanup

Sean Thielen-Esparza6639c83532c1
diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts
new file mode 100644
index 0000000..abe62e5
--- /dev/null
+++ b/src/lib/api/index.ts
@@ -0,0 +1,6 @@
+/**
+ * API barrel exports
+ */
+
+export { fetchCategoryNews, fetchAllNews } from './news';
+export { fetchCryptoPrices, fetchIndices, fetchSectorPerformance, fetchCommodities, fetchAllMarkets } from './markets';
diff --git a/src/lib/api/markets.ts b/src/lib/api/markets.ts
new file mode 100644
index 0000000..459c6e5
--- /dev/null
+++ b/src/lib/api/markets.ts
@@ -0,0 +1,112 @@
+/**
+ * Markets API - Fetch market data from various sources
+ */
+
+import { ServiceClient } from '$lib/services/client';
+import { INDICES, SECTORS, COMMODITIES, CRYPTO } from '$lib/config/markets';
+import type { MarketItem, SectorPerformance, CryptoItem } from '$lib/types';
+
+const client = new ServiceClient({ debug: false });
+
+interface CoinGeckoPrice {
+ usd: number;
+ usd_24h_change?: number;
+}
+
+interface CoinGeckoPricesResponse {
+ [key: string]: CoinGeckoPrice;
+}
+
+/**
+ * Fetch crypto prices from CoinGecko
+ */
+export async function fetchCryptoPrices(): Promise<CryptoItem[]> {
+ try {
+ const ids = CRYPTO.map((c) => c.id).join(',');
+ const result = await client.request<CoinGeckoPricesResponse>(
+ 'COINGECKO',
+ `/api/v3/simple/price?ids=${ids}&vs_currencies=usd&include_24hr_change=true`
+ );
+
+ return CRYPTO.map((crypto) => {
+ const data = result.data[crypto.id];
+ return {
+ id: crypto.id,
+ symbol: crypto.symbol,
+ name: crypto.name,
+ current_price: data?.usd || 0,
+ price_change_24h: data?.usd_24h_change || 0,
+ price_change_percentage_24h: data?.usd_24h_change || 0
+ };
+ });
+ } catch (error) {
+ console.error('[Markets API] Error fetching crypto:', error);
+ return CRYPTO.map((c) => ({
+ id: c.id,
+ symbol: c.symbol,
+ name: c.name,
+ current_price: 0,
+ price_change_24h: 0,
+ price_change_percentage_24h: 0
+ }));
+ }
+}
+
+/**
+ * Fetch market indices (via proxy for Yahoo Finance)
+ */
+export async function fetchIndices(): Promise<MarketItem[]> {
+ // For now, return placeholder data - would need Yahoo Finance API or similar
+ // The original app uses a proxy to scrape market data
+ return INDICES.map((index) => ({
+ symbol: index.symbol,
+ name: index.name,
+ price: 0,
+ change: 0,
+ changePercent: 0,
+ type: 'index' as const
+ }));
+}
+
+/**
+ * Fetch sector performance
+ */
+export async function fetchSectorPerformance(): Promise<SectorPerformance[]> {
+ // Placeholder - would need market data provider
+ return SECTORS.map((sector) => ({
+ symbol: sector.symbol,
+ name: sector.name,
+ price: 0,
+ change: 0,
+ changePercent: 0
+ }));
+}
+
+/**
+ * Fetch commodities
+ */
+export async function fetchCommodities(): Promise<MarketItem[]> {
+ // Placeholder - would need commodities data provider
+ return COMMODITIES.map((commodity) => ({
+ symbol: commodity.symbol,
+ name: commodity.name,
+ price: 0,
+ change: 0,
+ changePercent: 0,
+ type: 'commodity' as const
+ }));
+}
+
+/**
+ * Fetch all market data
+ */
+export async function fetchAllMarkets() {
+ const [crypto, indices, sectors, commodities] = await Promise.all([
+ fetchCryptoPrices(),
+ fetchIndices(),
+ fetchSectorPerformance(),
+ fetchCommodities()
+ ]);
+
+ return { crypto, indices, sectors, commodities };
+}
diff --git a/src/lib/api/news.ts b/src/lib/api/news.ts
new file mode 100644
index 0000000..71e4ef2
--- /dev/null
+++ b/src/lib/api/news.ts
@@ -0,0 +1,105 @@
+/**
+ * News API - Fetch news from GDELT and other sources
+ */
+
+import { ServiceClient } from '$lib/services/client';
+import { FEEDS } from '$lib/config/feeds';
+import type { NewsItem, NewsCategory } from '$lib/types';
+import { containsAlertKeyword, detectRegion, detectTopics } from '$lib/config/keywords';
+
+const client = new ServiceClient({ debug: false });
+
+interface GdeltArticle {
+ title: string;
+ url: string;
+ seendate: string;
+ domain: string;
+ socialimage?: string;
+}
+
+interface GdeltResponse {
+ articles?: GdeltArticle[];
+}
+
+/**
+ * Transform GDELT article to NewsItem
+ */
+function transformGdeltArticle(
+ article: GdeltArticle,
+ category: NewsCategory,
+ source: string
+): NewsItem {
+ const title = article.title || '';
+ const alert = containsAlertKeyword(title);
+
+ return {
+ id: `gdelt-${article.url?.slice(-20) || Math.random().toString(36)}`,
+ title,
+ link: article.url,
+ pubDate: article.seendate,
+ timestamp: article.seendate ? new Date(article.seendate).getTime() : Date.now(),
+ source: source || article.domain || 'Unknown',
+ category,
+ isAlert: !!alert,
+ alertKeyword: alert?.keyword || undefined,
+ region: detectRegion(title) ?? undefined,
+ topics: detectTopics(title)
+ };
+}
+
+/**
+ * Fetch news for a specific category using GDELT
+ */
+export async function fetchCategoryNews(category: NewsCategory): Promise<NewsItem[]> {
+ // Build query from category keywords
+ const categoryQueries: Record<NewsCategory, string> = {
+ politics: 'politics OR government OR election OR congress',
+ tech: 'technology OR software OR startup OR silicon valley',
+ finance: 'finance OR stock market OR economy OR banking',
+ gov: 'federal government OR white house OR congress OR regulation',
+ ai: 'artificial intelligence OR machine learning OR AI OR ChatGPT',
+ intel: 'intelligence OR security OR military OR defense'
+ };
+
+ try {
+ const query = encodeURIComponent(categoryQueries[category]);
+ const result = await client.request<GdeltResponse>(
+ 'GDELT',
+ `/api/v2/doc/doc?query=${query}&mode=artlist&maxrecords=20&format=json&sort=date`
+ );
+
+ if (!result.data?.articles) return [];
+
+ // Get source names for this category
+ const categoryFeeds = FEEDS[category] || [];
+ const defaultSource = categoryFeeds[0]?.name || 'News';
+
+ return result.data.articles.map((article) =>
+ transformGdeltArticle(article, category, article.domain || defaultSource)
+ );
+ } catch (error) {
+ console.error(`[News API] Error fetching ${category}:`, error);
+ return [];
+ }
+}
+
+/**
+ * Fetch all news
+ */
+export async function fetchAllNews(): Promise<Record<NewsCategory, NewsItem[]>> {
+ const categories: NewsCategory[] = ['politics', 'tech', 'finance', 'gov', 'ai', 'intel'];
+ const results = await Promise.all(
+ categories.map(async (category) => ({
+ category,
+ items: await fetchCategoryNews(category)
+ }))
+ );
+
+ return results.reduce(
+ (acc, { category, items }) => {
+ acc[category] = items;
+ return acc;
+ },
+ {} as Record<NewsCategory, NewsItem[]>
+ );
+}
diff --git a/src/lib/components/panels/MapPanel.svelte b/src/lib/components/panels/MapPanel.svelte
index 11d4c95..b5f78cf 100644
--- a/src/lib/components/panels/MapPanel.svelte
+++ b/src/lib/components/panels/MapPanel.svelte
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
+ import { browser } from '$app/environment';
import { Panel } from '$lib/components/common';
import {
HOTSPOTS,
@@ -553,7 +554,9 @@
});
onDestroy(() => {
- window.removeEventListener('resize', updateZoomBehavior);
+ if (browser) {
+ window.removeEventListener('resize', updateZoomBehavior);
+ }
});
</script>
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 965e508..4e8609e 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -1,43 +1,344 @@
<script lang="ts">
- // Placeholder dashboard - will be built out in Phase 3-4
+ import { onMount } from 'svelte';
+ import { Header, Dashboard } from '$lib/components/layout';
+ import { SettingsModal, MonitorFormModal } from '$lib/components/modals';
+ import {
+ NewsPanel,
+ MarketsPanel,
+ HeatmapPanel,
+ CommoditiesPanel,
+ CryptoPanel,
+ MainCharPanel,
+ CorrelationPanel,
+ NarrativePanel,
+ MonitorsPanel,
+ MapPanel,
+ WhalePanel,
+ PolymarketPanel,
+ ContractsPanel,
+ LayoffsPanel,
+ IntelPanel,
+ SituationPanel
+ } from '$lib/components/panels';
+ import {
+ news,
+ politicsNews,
+ techNews,
+ financeNews,
+ govNews,
+ aiNews,
+ intelNews,
+ markets,
+ monitors,
+ settings,
+ refresh
+ } from '$lib/stores';
+ import { fetchAllNews, fetchAllMarkets } from '$lib/api';
+ import type { CustomMonitor } from '$lib/types';
+
+ // Modal state
+ let settingsOpen = $state(false);
+ let monitorFormOpen = $state(false);
+ let editingMonitor = $state<CustomMonitor | null>(null);
+
+ // Derived data for panels that need aggregated news
+ const allNewsItems = $derived([
+ ...$politicsNews.items,
+ ...$techNews.items,
+ ...$financeNews.items,
+ ...$govNews.items,
+ ...$aiNews.items,
+ ...$intelNews.items
+ ]);
+
+ // Data fetching
+ async function loadNews() {
+ // Set loading for all categories
+ const categories = ['politics', 'tech', 'finance', 'gov', 'ai', 'intel'] as const;
+ categories.forEach((cat) => news.setLoading(cat, true));
+
+ try {
+ const data = await fetchAllNews();
+ Object.entries(data).forEach(([category, items]) => {
+ news.setItems(category as keyof typeof data, items);
+ });
+ } catch (error) {
+ categories.forEach((cat) => news.setError(cat, String(error)));
+ }
+ }
+
+ async function loadMarkets() {
+ try {
+ const data = await fetchAllMarkets();
+ markets.setIndices(data.indices);
+ markets.setSectors(data.sectors);
+ markets.setCommodities(data.commodities);
+ markets.setCrypto(data.crypto);
+ } catch (error) {
+ console.error('Failed to load markets:', error);
+ }
+ }
+
+ // Refresh handlers
+ async function handleRefresh() {
+ refresh.startRefresh();
+ try {
+ await Promise.all([loadNews(), loadMarkets()]);
+ refresh.endRefresh();
+ } catch (error) {
+ refresh.endRefresh([String(error)]);
+ }
+ }
+
+ // Monitor handlers
+ function handleCreateMonitor() {
+ editingMonitor = null;
+ monitorFormOpen = true;
+ }
+
+ function handleEditMonitor(monitor: CustomMonitor) {
+ editingMonitor = monitor;
+ monitorFormOpen = true;
+ }
+
+ function handleDeleteMonitor(id: string) {
+ monitors.deleteMonitor(id);
+ }
+
+ function handleToggleMonitor(id: string) {
+ monitors.toggleMonitor(id);
+ }
+
+ // Get panel visibility
+ const isPanelVisible = (id: string) => $settings.enabled[id as keyof typeof $settings.enabled] !== false;
+
+ // Initial load
+ onMount(() => {
+ loadNews();
+ loadMarkets();
+ refresh.setupAutoRefresh(handleRefresh);
+
+ return () => {
+ refresh.stopAutoRefresh();
+ };
+ });
</script>
<svelte:head>
<title>Situation Monitor</title>
+ <meta name="description" content="Real-time global situation monitoring dashboard" />
</svelte:head>
-<main class="p-4">
- <header class="mb-6 flex items-center justify-between">
- <h1 class="text-xl font-bold">Situation Monitor</h1>
- <div class="flex items-center gap-4">
- <span class="text-text-dim text-sm">SvelteKit Migration - Phase 0 Complete</span>
- </div>
- </header>
-
- <div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
- <!-- Placeholder panels -->
- <div class="rounded border border-border bg-surface p-4">
- <h2 class="mb-2 text-sm font-semibold text-text-dim">Politics</h2>
- <p class="text-text-muted text-xs">Panel content coming in Phase 4</p>
- </div>
- <div class="rounded border border-border bg-surface p-4">
- <h2 class="mb-2 text-sm font-semibold text-text-dim">Tech</h2>
- <p class="text-text-muted text-xs">Panel content coming in Phase 4</p>
- </div>
- <div class="rounded border border-border bg-surface p-4">
- <h2 class="mb-2 text-sm font-semibold text-text-dim">Finance</h2>
- <p class="text-text-muted text-xs">Panel content coming in Phase 4</p>
- </div>
- <div class="rounded border border-border bg-surface p-4">
- <h2 class="mb-2 text-sm font-semibold text-text-dim">Markets</h2>
- <p class="text-text-muted text-xs">Panel content coming in Phase 4</p>
- </div>
- </div>
-
- <footer class="mt-8 text-center text-text-muted text-xs">
- <p>
- Migration in progress. Original app available at
- <a href="/index.html" class="underline hover:text-text-primary">/index.html</a>
- </p>
- </footer>
-</main>
+<div class="app">
+ <Header
+ onRefresh={handleRefresh}
+ onSettingsClick={() => (settingsOpen = true)}
+ />
+
+ <main class="main-content">
+ <Dashboard>
+ <!-- Map Panel - Full width -->
+ {#if isPanelVisible('map')}
+ <div class="panel-slot map-slot">
+ <MapPanel monitors={$monitors.monitors} />
+ </div>
+ {/if}
+
+ <!-- News Panels -->
+ {#if isPanelVisible('politics')}
+ <div class="panel-slot">
+ <NewsPanel category="politics" panelId="politics" title="Politics" />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('tech')}
+ <div class="panel-slot">
+ <NewsPanel category="tech" panelId="tech" title="Tech" />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('finance')}
+ <div class="panel-slot">
+ <NewsPanel category="finance" panelId="finance" title="Finance" />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('gov')}
+ <div class="panel-slot">
+ <NewsPanel category="gov" panelId="gov" title="Government" />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('ai')}
+ <div class="panel-slot">
+ <NewsPanel category="ai" panelId="ai" title="AI" />
+ </div>
+ {/if}
+
+ <!-- Markets Panels -->
+ {#if isPanelVisible('markets')}
+ <div class="panel-slot">
+ <MarketsPanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('heatmap')}
+ <div class="panel-slot">
+ <HeatmapPanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('commodities')}
+ <div class="panel-slot">
+ <CommoditiesPanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('crypto')}
+ <div class="panel-slot">
+ <CryptoPanel />
+ </div>
+ {/if}
+
+ <!-- Analysis Panels -->
+ {#if isPanelVisible('mainchar')}
+ <div class="panel-slot">
+ <MainCharPanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('correlation')}
+ <div class="panel-slot">
+ <CorrelationPanel news={allNewsItems} />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('narrative')}
+ <div class="panel-slot">
+ <NarrativePanel news={allNewsItems} />
+ </div>
+ {/if}
+
+ <!-- Custom Monitors -->
+ {#if isPanelVisible('monitors')}
+ <div class="panel-slot">
+ <MonitorsPanel
+ monitors={$monitors.monitors}
+ matches={$monitors.matches}
+ onCreateMonitor={handleCreateMonitor}
+ onEditMonitor={handleEditMonitor}
+ onDeleteMonitor={handleDeleteMonitor}
+ onToggleMonitor={handleToggleMonitor}
+ />
+ </div>
+ {/if}
+
+ <!-- Intel Panel -->
+ {#if isPanelVisible('intel')}
+ <div class="panel-slot">
+ <IntelPanel />
+ </div>
+ {/if}
+
+ <!-- Situation Panels -->
+ {#if isPanelVisible('venezuela')}
+ <div class="panel-slot">
+ <SituationPanel
+ panelId="venezuela"
+ config={{
+ title: 'Venezuela Watch',
+ subtitle: 'Humanitarian crisis monitoring',
+ criticalKeywords: ['maduro', 'caracas', 'venezuela', 'guaido']
+ }}
+ news={allNewsItems.filter(
+ (n) =>
+ n.title.toLowerCase().includes('venezuela') ||
+ n.title.toLowerCase().includes('maduro')
+ )}
+ />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('greenland')}
+ <div class="panel-slot">
+ <SituationPanel
+ panelId="greenland"
+ config={{
+ title: 'Greenland Watch',
+ subtitle: 'Arctic geopolitics monitoring',
+ criticalKeywords: ['greenland', 'arctic', 'nuuk', 'denmark']
+ }}
+ news={allNewsItems.filter(
+ (n) =>
+ n.title.toLowerCase().includes('greenland') ||
+ n.title.toLowerCase().includes('arctic')
+ )}
+ />
+ </div>
+ {/if}
+
+ <!-- Placeholder panels for additional data sources -->
+ {#if isPanelVisible('whales')}
+ <div class="panel-slot">
+ <WhalePanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('polymarket')}
+ <div class="panel-slot">
+ <PolymarketPanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('contracts')}
+ <div class="panel-slot">
+ <ContractsPanel />
+ </div>
+ {/if}
+
+ {#if isPanelVisible('layoffs')}
+ <div class="panel-slot">
+ <LayoffsPanel />
+ </div>
+ {/if}
+ </Dashboard>
+ </main>
+
+ <!-- Modals -->
+ <SettingsModal open={settingsOpen} onClose={() => (settingsOpen = false)} />
+ <MonitorFormModal
+ open={monitorFormOpen}
+ onClose={() => (monitorFormOpen = false)}
+ editMonitor={editingMonitor}
+ />
+</div>
+
+<style>
+ .app {
+ min-height: 100vh;
+ display: flex;
+ flex-direction: column;
+ background: var(--bg);
+ }
+
+ .main-content {
+ flex: 1;
+ padding: 0.5rem;
+ overflow-y: auto;
+ }
+
+ .panel-slot {
+ min-height: 200px;
+ }
+
+ .map-slot {
+ grid-column: 1 / -1;
+ min-height: 300px;
+ }
+
+ @media (max-width: 768px) {
+ .main-content {
+ padding: 0.25rem;
+ }
+ }
+</style>