akborana4 commited on
Commit
f22a7f7
·
verified ·
1 Parent(s): d413da3

Create static/js/settings.js

Browse files
Files changed (1) hide show
  1. static/js/settings.js +122 -0
static/js/settings.js ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // static/js/settings.js
2
+
3
+ let currentAccentColor = '#ffc107';
4
+
5
+ function switchSettingsPanel(panelId, element) {
6
+ // Hide all panels
7
+ document.querySelectorAll('.settings-section').forEach(p => p.classList.remove('active'));
8
+ // Show target
9
+ document.getElementById(panelId).classList.add('active');
10
+
11
+ // Update tabs
12
+ document.querySelectorAll('.settings-tab').forEach(t => t.classList.remove('active'));
13
+ element.classList.add('active');
14
+ }
15
+
16
+ function setAccentColor(hexCode, element) {
17
+ currentAccentColor = hexCode;
18
+
19
+ // Update swatches visually
20
+ document.querySelectorAll('.color-swatch').forEach(s => s.classList.remove('active'));
21
+ if(element) {
22
+ element.classList.add('active');
23
+ }
24
+
25
+ // Update the custom color picker input to match if needed
26
+ document.getElementById('custom-accent-color').value = hexCode;
27
+
28
+ previewSettings();
29
+ }
30
+
31
+ function previewSettings() {
32
+ // 1. Apply Accent Color
33
+ document.documentElement.style.setProperty('--accent-main', currentAccentColor);
34
+ // Generate a softer glow color based on the hex (simplified logic)
35
+ document.documentElement.style.setProperty('--accent-glow', currentAccentColor + '40');
36
+
37
+ // 2. Apply Theme (Light/Dark)
38
+ const theme = document.getElementById('setting-theme-mode').value;
39
+ if (theme === 'light') {
40
+ document.documentElement.style.setProperty('--bg-base', '#f5f5f5');
41
+ document.documentElement.style.setProperty('--bg-surface', '#ffffff');
42
+ document.documentElement.style.setProperty('--text-primary', '#111111');
43
+ document.documentElement.style.setProperty('--text-secondary', '#555555');
44
+ document.documentElement.style.setProperty('--glass-border', '1px solid rgba(0,0,0,0.1)');
45
+ document.documentElement.style.setProperty('--panel-bg', 'rgba(255,255,255,0.8)');
46
+ } else {
47
+ // Revert to Dark
48
+ document.documentElement.style.setProperty('--bg-base', '#050505');
49
+ document.documentElement.style.setProperty('--bg-surface', '#0a0a0a');
50
+ document.documentElement.style.setProperty('--text-primary', '#ffffff');
51
+ document.documentElement.style.setProperty('--text-secondary', '#a0a0a0');
52
+ document.documentElement.style.setProperty('--glass-border', '1px solid rgba(255, 255, 255, 0.05)');
53
+ document.documentElement.style.setProperty('--panel-bg', 'rgba(20, 20, 20, 0.6)');
54
+ }
55
+
56
+ // 3. Apply Editor Settings
57
+ const editorFont = document.getElementById('setting-editor-font').value;
58
+ const editorSize = document.getElementById('setting-editor-font-size').value;
59
+ document.documentElement.style.setProperty('--font-mono', editorFont);
60
+
61
+ if (typeof editor !== 'undefined' && editor) {
62
+ editor.setOptions({
63
+ fontFamily: editorFont,
64
+ fontSize: editorSize
65
+ });
66
+ }
67
+
68
+ // 4. Apply Terminal Settings
69
+ const termSize = document.getElementById('setting-terminal-font-size').value;
70
+ const termOutput = document.getElementById('terminal-output');
71
+ if (termOutput) {
72
+ termOutput.style.fontSize = termSize;
73
+ }
74
+ }
75
+
76
+ async function saveSettings() {
77
+ const btn = document.getElementById('save-settings-btn');
78
+ btn.innerText = "Saving...";
79
+
80
+ const settingsData = {
81
+ theme: document.getElementById('setting-theme-mode').value,
82
+ accent: currentAccentColor,
83
+ editorFont: document.getElementById('setting-editor-font').value,
84
+ editorSize: document.getElementById('setting-editor-font-size').value,
85
+ termSize: document.getElementById('setting-terminal-font-size').value
86
+ };
87
+
88
+ try {
89
+ const res = await fetch('/api/settings', {
90
+ method: 'POST',
91
+ headers: {'Content-Type': 'application/json'},
92
+ body: JSON.stringify({token: currentToken, settings: settingsData})
93
+ });
94
+
95
+ const data = await res.json();
96
+ if(data.success) {
97
+ btn.innerText = "✓ Saved";
98
+ setTimeout(() => btn.innerText = "Save Settings", 2000);
99
+ } else {
100
+ alert("Failed to save settings.");
101
+ btn.innerText = "Save Settings";
102
+ }
103
+ } catch (e) {
104
+ alert("Network error.");
105
+ btn.innerText = "Save Settings";
106
+ }
107
+ }
108
+
109
+ // Called on login/boot
110
+ async function loadSettings() {
111
+ if(!currentUser) return;
112
+
113
+ // Set username in profile
114
+ const usernameInput = document.getElementById('setting-username');
115
+ const avatar = document.getElementById('profile-avatar');
116
+ if(usernameInput) usernameInput.value = currentUser;
117
+ if(avatar) avatar.innerText = currentUser.charAt(0).toUpperCase();
118
+
119
+ // In a full app, we would fetch the user's specific settings from the DB here via a GET route.
120
+ // For now, we apply the default UI state so everything looks perfect immediately.
121
+ previewSettings();
122
+ }