-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
1109 lines (950 loc) · 32.8 KB
/
app.js
File metadata and controls
1109 lines (950 loc) · 32.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ===================================
// SIGNALBOARD - CORE APPLICATION
// Customer feedback signal tracking for product teams
// Author: Emmanuel Ahishakiye
// ===================================
// ===================================
// STATE MANAGEMENT
// ===================================
const state = {
currentView: 'dashboard',
// Customer feedback signals
signals: [],
// Baseline metrics for comparison
benchmarks: [
{
id: 'default',
name: 'Q1 Baseline',
targetImpact: 1000,
urgencyThreshold: 3,
customerTierWeight: { enterprise: 3, pro: 2, free: 1 },
active: true
}
],
currentBenchmark: null,
// PM user profile
user: {
name: 'Emmanuel Ahishakiye',
email: 'emmanuel@cloudflare.com',
productArea: 'Developer Platform',
team: 'Product Management',
focus: 'reliability'
},
theme: 'light',
captureStream: null,
currentFacingMode: 'environment',
currentCapture: null
};
// ===================================
// INITIALIZATION
// ===================================
document.addEventListener('DOMContentLoaded', () => {
initializeApp();
});
function initializeApp() {
console.log('Initializing SignalBoard...');
// Load persisted data
loadFromLocalStorage();
// Setup event listeners
setupNavigation();
setupThemeToggle();
setupCaptureControls();
setupSignalForm();
setupBenchmarkForm();
setupProfileForm();
setupTimelineFilter();
// Initialize current benchmark
if (state.benchmarks.length > 0 && !state.currentBenchmark) {
state.currentBenchmark = state.benchmarks.find(b => b.active) || state.benchmarks[0];
}
// Initial render
updateDashboard();
renderRecentSignals();
renderTimeline();
renderBenchmarks();
console.log('✓ SignalBoard initialized successfully');
console.log(`→ Signals: ${state.signals.length}`);
console.log(`→ Benchmarks: ${state.benchmarks.length}`);
}
// ===================================
// NAVIGATION SYSTEM
// ===================================
function setupNavigation() {
const navItems = document.querySelectorAll('.nav-item');
navItems.forEach(item => {
item.addEventListener('click', () => {
const view = item.dataset.view;
switchView(view);
// Update active state
navItems.forEach(i => i.classList.remove('active'));
item.classList.add('active');
});
});
}
function switchView(viewName) {
// Hide all views
document.querySelectorAll('.view').forEach(view => {
view.classList.remove('active');
});
// Show target view
const targetView = document.getElementById(`${viewName}-view`);
if (targetView) {
targetView.classList.add('active');
state.currentView = viewName;
// Cleanup on view change
if (viewName !== 'capture' && state.captureStream) {
stopCapture();
}
}
console.log(`→ Switched to view: ${viewName}`);
}
// ===================================
// THEME TOGGLE
// ===================================
function setupThemeToggle() {
const themeSwitch = document.getElementById('theme-switch');
if (!themeSwitch) return;
// Set initial theme
if (state.theme === 'dark') {
document.body.classList.add('dark-theme');
themeSwitch.checked = true;
}
themeSwitch.addEventListener('change', (e) => {
if (e.target.checked) {
document.body.classList.add('dark-theme');
state.theme = 'dark';
} else {
document.body.classList.remove('dark-theme');
state.theme = 'light';
}
saveToLocalStorage();
});
}
// ===================================
// CAPTURE CONTROLS
// ===================================
function setupCaptureControls() {
const uploadBtn = document.getElementById('upload-btn');
const fileInput = document.getElementById('file-input');
const pasteBtn = document.getElementById('paste-btn');
const githubBtn = document.getElementById('github-btn');
const analyzeBtn = document.getElementById('analyze-btn');
if (!uploadBtn || !fileInput) return;
// File upload
uploadBtn.addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (!file) return;
// Validate file type (CSV or text)
if (!file.name.match(/\.(csv|txt)$/i)) {
showToast('Please upload a CSV or TXT file');
return;
}
const reader = new FileReader();
reader.onload = (event) => {
handleFileUpload(event.target.result, file.name);
};
reader.readAsText(file);
});
// Paste feedback
pasteBtn?.addEventListener('click', () => {
showSignalForm();
showToast('Manual entry mode activated');
});
// GitHub import (mock)
githubBtn?.addEventListener('click', () => {
showToast('GitHub integration coming soon');
});
// Analyze button
analyzeBtn?.addEventListener('click', async () => {
await analyzeSignal();
});
}
function handleFileUpload(content, filename) {
console.log(`Processing file: ${filename}`);
showLoading('Parsing feedback data...');
setTimeout(() => {
hideLoading();
showSignalForm();
showToast(`Loaded ${filename} successfully`);
}, 1000);
}
function showSignalForm() {
const container = document.getElementById('signal-form-container');
if (container) {
container.classList.remove('hidden');
container.scrollIntoView({ behavior: 'smooth' });
}
}
function hideSignalForm() {
const container = document.getElementById('signal-form-container');
if (container) {
container.classList.add('hidden');
}
}
function stopCapture() {
if (state.captureStream) {
state.captureStream.getTracks().forEach(track => track.stop());
state.captureStream = null;
}
}
// ===================================
// SIGNAL ANALYSIS (AI Simulation)
// ===================================
async function analyzeSignal() {
if (!state.currentCapture) {
showToast('No input to analyze');
return;
}
showLoading('Analyzing signal with AI...');
// Simulate AI processing delay
await new Promise(resolve => setTimeout(resolve, 2000));
// Simulate AI analysis result
const analysis = simulateAIAnalysis();
hideLoading();
// Populate form with AI results
document.getElementById('signal-title').value = analysis.title;
document.getElementById('signal-impact').value = analysis.impact;
document.getElementById('signal-urgency').value = analysis.urgency;
document.getElementById('signal-source').value = analysis.source;
document.getElementById('signal-category').value = analysis.category;
document.getElementById('signal-tier').value = analysis.tier;
document.getElementById('signal-context').value = analysis.context;
showToast('AI analysis complete');
}
function simulateAIAnalysis() {
const samples = [
{
title: 'Workers timeout under high load in EU region',
impact: 85,
urgency: 4,
source: 'support',
category: 'bug',
tier: 'enterprise',
context: 'Multiple enterprise customers in EU reporting 504 errors during peak traffic. Affects Workers deployments with >1000 req/s.'
},
{
title: 'TypeScript bindings request for Workers KV',
impact: 72,
urgency: 2,
source: 'github',
category: 'feature',
tier: 'pro',
context: '12 developers requesting native TypeScript support for KV bindings. Current workaround requires manual type generation.'
},
{
title: 'R2 pricing feedback - highly positive',
impact: 65,
urgency: 1,
source: 'community',
category: 'feedback',
tier: 'enterprise',
context: 'Storage-heavy users praising new pricing model. Migration tools cited as key differentiator.'
},
{
title: 'Pages deployment speed regression',
impact: 78,
urgency: 3,
source: 'internal',
category: 'performance',
tier: 'pro',
context: 'Build times increased 40% after recent infra change. Affecting CI/CD pipelines for large projects.'
},
{
title: 'KV consistency model documentation gap',
impact: 55,
urgency: 2,
source: 'support',
category: 'documentation',
tier: 'free',
context: 'Support tickets show confusion around eventual consistency. Need better examples and edge case documentation.'
}
];
return samples[Math.floor(Math.random() * samples.length)];
}
// ===================================
// SIGNAL FORM HANDLING
// ===================================
function setupSignalForm() {
const saveBtn = document.getElementById('save-signal-btn');
const form = document.getElementById('signal-form');
if (form) {
form.addEventListener('submit', (e) => {
e.preventDefault();
saveSignal();
});
}
if (saveBtn) {
saveBtn.addEventListener('click', (e) => {
e.preventDefault();
saveSignal();
});
}
}
function saveSignal() {
const title = document.getElementById('signal-title')?.value.trim();
const impact = parseFloat(document.getElementById('signal-impact')?.value) || 0;
const urgency = parseInt(document.getElementById('signal-urgency')?.value) || 1;
const source = document.getElementById('signal-source')?.value || 'internal';
const category = document.getElementById('signal-category')?.value || 'feedback';
const tier = document.getElementById('signal-tier')?.value || 'free';
const context = document.getElementById('signal-context')?.value.trim() || '';
// Validation
if (!title || impact <= 0) {
showToast('Title and impact score required');
return;
}
if (impact > 100) {
showToast('Impact score must be between 0-100');
return;
}
// Create signal object
const signal = {
id: Date.now(),
title,
impact,
urgency,
source,
category,
tier,
context,
timestamp: new Date().toISOString(),
date: new Date().toLocaleDateString()
};
// Add to state
state.signals.unshift(signal);
saveToLocalStorage();
// Reset form
resetSignalForm();
// Update UI
updateDashboard();
renderRecentSignals();
renderTimeline();
// Navigate back
switchView('dashboard');
showToast('Signal saved successfully');
console.log('→ Signal saved:', signal.title);
}
function resetSignalForm() {
const form = document.getElementById('signal-form');
if (form) form.reset();
hideSignalForm();
state.currentCapture = null;
}
// ===================================
// DASHBOARD UPDATES
// ===================================
function updateDashboard() {
const today = new Date().toLocaleDateString();
const todaySignals = state.signals.filter(signal => signal.date === today);
// Calculate daily impact
const dailyImpact = todaySignals.reduce((sum, signal) => {
// Weight by tier
const tierWeight = state.currentBenchmark?.customerTierWeight?.[signal.tier] || 1;
return sum + (signal.impact * tierWeight);
}, 0);
// Calculate benchmark progress
const benchmark = state.currentBenchmark;
if (!benchmark) return;
updateStatCard('daily-impact', dailyImpact, benchmark.targetImpact);
// Update critical signals count
const criticalCount = todaySignals.filter(s => s.urgency >= 3).length;
updateStatCard('critical-signals', criticalCount, 10);
// Update signal velocity (signals per week)
const weekAgo = new Date();
weekAgo.setDate(weekAgo.getDate() - 7);
const weekSignals = state.signals.filter(s => new Date(s.timestamp) >= weekAgo);
updateStatCard('signal-velocity', weekSignals.length, 50);
}
function updateStatCard(id, value, target) {
const valueEl = document.getElementById(id);
const progressEl = document.getElementById(`${id}-progress`);
if (valueEl) {
valueEl.textContent = Math.round(value);
}
if (progressEl && target > 0) {
const percentage = Math.min((value / target) * 100, 100);
progressEl.style.width = `${percentage}%`;
}
}
// ===================================
// RECENT SIGNALS RENDERING
// ===================================
function renderRecentSignals() {
const container = document.getElementById('recent-signals');
if (!container) return;
const today = new Date().toLocaleDateString();
const todaySignals = state.signals.filter(signal => signal.date === today);
if (todaySignals.length === 0) {
container.innerHTML = `
<div class="empty-state">
<svg width="64" height="64" viewBox="0 0 20 20" fill="currentColor" opacity="0.3">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" />
</svg>
<p>No signals captured yet today</p>
<button class="btn-primary" onclick="switchView('capture')">Capture First Signal</button>
</div>
`;
return;
}
container.innerHTML = todaySignals.slice(0, 6).map(signal => `
<div class="signal-card">
<div class="signal-header">
<div>
<h4 class="signal-title">${signal.title}</h4>
<p class="signal-source">
${formatSource(signal.source)} • ${formatCategory(signal.category)} • ${signal.tier.toUpperCase()}
</p>
</div>
<button class="btn-icon" onclick="deleteSignal(${signal.id})" aria-label="Delete signal">
<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" />
</svg>
</button>
</div>
<div class="signal-meta">
<div class="signal-metric">
<span class="metric-label">Impact</span>
<span class="metric-value">${Math.round(signal.impact)}</span>
</div>
<div class="signal-metric">
<span class="metric-label">Urgency</span>
<span class="metric-value">${formatUrgency(signal.urgency)}</span>
</div>
<div class="signal-metric">
<span class="metric-label">Time</span>
<span class="metric-value">${new Date(signal.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</span>
</div>
</div>
</div>
`).join('');
}
// ===================================
// TIMELINE RENDERING
// ===================================
function setupTimelineFilter() {
const filterSelect = document.getElementById('history-filter');
if (filterSelect) {
filterSelect.addEventListener('change', () => {
renderTimeline();
});
}
const sourceFilter = document.getElementById('source-filter');
if (sourceFilter) {
sourceFilter.addEventListener('change', () => {
renderTimeline();
});
}
}
function renderTimeline() {
const container = document.getElementById('timeline-list');
if (!container) return;
const filter = document.getElementById('history-filter')?.value || 'all';
const sourceFilter = document.getElementById('source-filter')?.value || 'all';
let filteredSignals = [...state.signals];
const now = new Date();
// Time filter
if (filter === 'today') {
const today = now.toLocaleDateString();
filteredSignals = filteredSignals.filter(signal => signal.date === today);
} else if (filter === 'week') {
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
filteredSignals = filteredSignals.filter(signal => new Date(signal.timestamp) >= weekAgo);
} else if (filter === 'month') {
const monthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
filteredSignals = filteredSignals.filter(signal => new Date(signal.timestamp) >= monthAgo);
}
// Source filter
if (sourceFilter !== 'all') {
filteredSignals = filteredSignals.filter(signal => signal.source === sourceFilter);
}
if (filteredSignals.length === 0) {
container.innerHTML = `
<div class="empty-state">
<svg width="64" height="64" viewBox="0 0 20 20" fill="currentColor" opacity="0.3">
<path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" />
</svg>
<p>No signals found for this period</p>
</div>
`;
return;
}
container.innerHTML = filteredSignals.map(signal => `
<div class="timeline-item">
<div class="history-info">
<h4>${signal.title}</h4>
<p class="history-meta">
${new Date(signal.timestamp).toLocaleDateString()} •
${new Date(signal.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} •
${formatSource(signal.source)}
</p>
</div>
<div class="history-stats">
<div class="history-stat">
<span class="history-stat-value">${Math.round(signal.impact)}</span>
<span class="history-stat-label">impact</span>
</div>
<div class="history-stat">
<span class="history-stat-value">${formatUrgency(signal.urgency)}</span>
<span class="history-stat-label">urgency</span>
</div>
</div>
</div>
`).join('');
}
// ===================================
// BENCHMARKS
// ===================================
function setupBenchmarkForm() {
const form = document.getElementById('plan-form');
if (form) {
form.addEventListener('submit', (e) => {
e.preventDefault();
createBenchmark();
});
}
}
function createBenchmark() {
const name = document.getElementById('plan-name')?.value.trim();
const targetImpact = parseFloat(document.getElementById('plan-calories')?.value) || 0;
const urgencyWeight = parseFloat(document.getElementById('plan-protein')?.value) || 1;
const tierWeight = parseFloat(document.getElementById('plan-carbs')?.value) || 1;
const categoryWeight = parseFloat(document.getElementById('plan-fats')?.value) || 1;
if (!name || targetImpact <= 0) {
showToast('Benchmark name and target impact required');
return;
}
const benchmark = {
id: Date.now().toString(),
name,
targetImpact,
urgencyWeight,
tierWeight,
categoryWeight,
active: false
};
state.benchmarks.push(benchmark);
saveToLocalStorage();
renderBenchmarks();
hideCreateBenchmark();
showToast('Benchmark created');
}
function renderBenchmarks() {
const container = document.getElementById('benchmarks-list');
if (!container) return;
if (state.benchmarks.length === 0) {
container.innerHTML = `
<div class="empty-state">
<svg width="64" height="64" viewBox="0 0 20 20" fill="currentColor" opacity="0.3">
<path d="M2 11a1 1 0 011-1h2a1 1 0 011 1v5a1 1 0 01-1 1H3a1 1 0 01-1-1v-5zM8 7a1 1 0 011-1h2a1 1 0 011 1v9a1 1 0 01-1 1H9a1 1 0 01-1-1V7zM14 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1h-2a1 1 0 01-1-1V4z" />
</svg>
<p>No benchmarks defined yet</p>
<button class="btn-primary" onclick="showCreateBenchmark()">Create First Benchmark</button>
</div>
`;
return;
}
container.innerHTML = state.benchmarks.map(benchmark => `
<div class="benchmark-card ${benchmark.active ? 'active' : ''}" onclick="selectBenchmark('${benchmark.id}')">
<div class="plan-header">
<div>
<h3 class="plan-name">${benchmark.name}</h3>
${benchmark.active ? '<span class="plan-badge">Active</span>' : ''}
</div>
<button class="btn-icon" onclick="deleteBenchmark(event, '${benchmark.id}')">
<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" />
</svg>
</button>
</div>
<div class="plan-goals">
<div class="plan-goal">
<span class="plan-goal-label">Target Impact</span>
<span class="plan-goal-value">${Math.round(benchmark.targetImpact)}</span>
</div>
</div>
</div>
`).join('');
}
function selectBenchmark(benchmarkId) {
state.benchmarks.forEach(b => b.active = false);
const selected = state.benchmarks.find(b => b.id === benchmarkId);
if (selected) {
selected.active = true;
state.currentBenchmark = selected;
}
saveToLocalStorage();
renderBenchmarks();
updateDashboard();
showToast('Benchmark activated');
}
function deleteBenchmark(event, benchmarkId) {
event.stopPropagation();
if (!confirm('Delete this benchmark?')) return;
state.benchmarks = state.benchmarks.filter(b => b.id !== benchmarkId);
if (state.currentBenchmark?.id === benchmarkId) {
state.currentBenchmark = state.benchmarks[0] || null;
if (state.currentBenchmark) {
state.currentBenchmark.active = true;
}
}
saveToLocalStorage();
renderBenchmarks();
updateDashboard();
showToast('Benchmark deleted');
}
function showCreateBenchmark() {
const modal = document.getElementById('create-plan-modal');
if (modal) modal.classList.remove('hidden');
}
function hideCreateBenchmark() {
const modal = document.getElementById('create-plan-modal');
if (modal) modal.classList.add('hidden');
const form = document.getElementById('plan-form');
if (form) form.reset();
}
// ===================================
// PROFILE
// ===================================
function setupProfileForm() {
const form = document.getElementById('profile-form');
if (!form) return;
// Load current profile
document.getElementById('user-name').value = state.user.name;
document.getElementById('user-email').value = state.user.email;
form.addEventListener('submit', (e) => {
e.preventDefault();
saveProfile();
});
}
function saveProfile() {
state.user = {
name: document.getElementById('user-name')?.value.trim() || state.user.name,
email: document.getElementById('user-email')?.value.trim() || state.user.email,
productArea: document.getElementById('user-product-area')?.value || state.user.productArea,
team: document.getElementById('user-team')?.value.trim() || state.user.team,
focus: document.getElementById('user-focus')?.value || state.user.focus
};
// Update display
const displayName = document.getElementById('profile-display-name');
const displayEmail = document.getElementById('profile-display-email');
if (displayName) displayName.textContent = state.user.name;
if (displayEmail) displayEmail.textContent = state.user.email;
saveToLocalStorage();
showToast('Profile updated successfully');
}
// ===================================
// DELETE AND CLEAR
// ===================================
function deleteSignal(signalId) {
if (!confirm('Remove this signal?')) return;
state.signals = state.signals.filter(signal => signal.id !== signalId);
saveToLocalStorage();
updateDashboard();
renderRecentSignals();
renderTimeline();
showToast('Signal removed');
}
function clearTodaySignals() {
if (!confirm('Clear all signals from today?')) return;
const today = new Date().toLocaleDateString();
state.signals = state.signals.filter(signal => signal.date !== today);
saveToLocalStorage();
updateDashboard();
renderRecentSignals();
renderTimeline();
showToast('Today\'s signals cleared');
}
// ===================================
// LOCAL STORAGE
// ===================================
function saveToLocalStorage() {
try {
localStorage.setItem('signalboard-state', JSON.stringify({
signals: state.signals,
benchmarks: state.benchmarks,
user: state.user,
theme: state.theme
}));
} catch (error) {
console.error('Error saving to localStorage:', error);
}
}
function loadFromLocalStorage() {
try {
const saved = localStorage.getItem('signalboard-state');
if (saved) {
const data = JSON.parse(saved);
state.signals = data.signals || [];
state.benchmarks = data.benchmarks || state.benchmarks;
state.user = data.user || state.user;
state.theme = data.theme || 'light';
state.currentBenchmark = state.benchmarks.find(b => b.active) || state.benchmarks[0];
}
} catch (error) {
console.error('Error loading from localStorage:', error);
}
}
// ===================================
// UI HELPERS
// ===================================
function showLoading(message = 'Loading...') {
const overlay = document.getElementById('loading-overlay');
const loadingText = document.querySelector('.loading-text');
if (loadingText) loadingText.textContent = message;
if (overlay) overlay.classList.remove('hidden');
}
function hideLoading() {
const overlay = document.getElementById('loading-overlay');
if (overlay) overlay.classList.add('hidden');
}
function showToast(message, duration = 3000) {
const toast = document.getElementById('toast');
const toastMessage = document.getElementById('toast-message');
if (toastMessage) toastMessage.textContent = message;
if (toast) {
toast.classList.remove('hidden');
setTimeout(() => {
toast.classList.add('hidden');
}, duration);
}
}
// ===================================
// FORMATTING UTILITIES
// ===================================
function formatSource(source) {
const sources = {
github: 'GitHub',
support: 'Support',
community: 'Community',
sales: 'Sales',
internal: 'Internal'
};
return sources[source] || source;
}
function formatCategory(category) {
const categories = {
bug: 'Bug',
feature: 'Feature',
performance: 'Performance',
ux: 'UX',
documentation: 'Docs',
feedback: 'Feedback'
};
return categories[category] || category;
}
function formatUrgency(urgency) {
const levels = {
1: 'Low',
2: 'Medium',
3: 'High',
4: 'Critical'
};
return levels[urgency] || 'Unknown';
}
function formatDate(date) {
return new Date(date).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric'
});
}
function formatTime(date) {
return new Date(date).toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit'
});
}
function formatDateTime(timestamp) {
const date = new Date(timestamp);
return `${formatDate(date)} at ${formatTime(date)}`;
}
// ===================================
// INSIGHTS REFRESH
// ===================================
function refreshInsights() {
showLoading('Refreshing insights...');
setTimeout(() => {
hideLoading();
showToast('Insights updated');
console.log('→ Insights refreshed');
}, 1000);
}
// ===================================
// PROFILE AVATAR UPLOAD
// ===================================
function setupProfilePictureUpload() {
const editBtn = document.getElementById('edit-avatar-btn');
const fileInput = document.getElementById('avatar-upload');
const avatarImg = document.getElementById('profile-avatar-img');
const avatarPlaceholder = document.getElementById('profile-avatar-placeholder');
if (!editBtn || !fileInput) return;
editBtn.addEventListener('click', () => {
fileInput.click();
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (!file) return;
if (!file.type.match('image.*')) {
showToast('Please select an image file');
return;
}
if (file.size > 5 * 1024 * 1024) {
showToast('Image must be less than 5MB');
return;
}
const reader = new FileReader();
reader.onload = (event) => {
const imageData = event.target.result;
if (avatarImg) {
avatarImg.src = imageData;
avatarImg.classList.remove('hidden');
}
if (avatarPlaceholder) {
avatarPlaceholder.style.display = 'none';
}
state.user.avatar = imageData;
saveToLocalStorage();
showToast('Profile picture updated');
};
reader.readAsDataURL(file);
});
loadSavedAvatar();
}
function loadSavedAvatar() {
if (!state.user || !state.user.avatar) return;
const avatarImg = document.getElementById('profile-avatar-img');
const avatarPlaceholder = document.getElementById('profile-avatar-placeholder');
if (avatarImg && state.user.avatar) {
avatarImg.src = state.user.avatar;
avatarImg.classList.remove('hidden');
if (avatarPlaceholder) {
avatarPlaceholder.style.display = 'none';
}
}
}
// Initialize profile picture upload after a short delay
setTimeout(() => {
setupProfilePictureUpload();
}, 100);
// ===================================
// ANALYTICS INTEGRATION
// ===================================
function trackEvent(eventName, properties = {}) {
console.log(`[Analytics] ${eventName}`, properties);
// In production, this would send to analytics service
}
// Track key user actions
function trackSignalCreated(signal) {
trackEvent('signal_created', {
category: signal.category,
source: signal.source,
tier: signal.tier,
impact: signal.impact
});
}
function trackViewSwitch(viewName) {
trackEvent('view_switched', { view: viewName });
}
// ===================================
// KEYBOARD SHORTCUTS
// ===================================