codex-lens 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/public/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Codex Lens</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/main-
|
|
7
|
+
<script type="module" crossorigin src="./assets/main-D-AWzk2Q.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="./assets/main-CYNmzqDG.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
package/src/components/App.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
|
2
2
|
import { TerminalPanel } from './TerminalPanel';
|
|
3
3
|
import { CodeViewer } from './CodeViewer';
|
|
4
4
|
|
|
@@ -12,8 +12,17 @@ export function App() {
|
|
|
12
12
|
const [latestVersion, setLatestVersion] = useState(null);
|
|
13
13
|
const [hasUpdate, setHasUpdate] = useState(false);
|
|
14
14
|
const [projectName, setProjectName] = useState('');
|
|
15
|
-
const [saving, setSaving] = useState(false);
|
|
16
15
|
const wsRef = useRef(null);
|
|
16
|
+
const activeTabIdRef = useRef(null);
|
|
17
|
+
const tabsRef = useRef([]);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
activeTabIdRef.current = activeTabId;
|
|
21
|
+
}, [activeTabId]);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
tabsRef.current = tabs;
|
|
25
|
+
}, [tabs]);
|
|
17
26
|
|
|
18
27
|
useEffect(() => {
|
|
19
28
|
fetchStatus();
|
|
@@ -87,34 +96,42 @@ export function App() {
|
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
method: 'POST',
|
|
100
|
-
headers: { 'Content-Type': 'application/json' },
|
|
101
|
-
body: JSON.stringify({ path: activeTab.path, content: activeTab.content })
|
|
102
|
-
});
|
|
99
|
+
const saveCurrentFile = useCallback(() => {
|
|
100
|
+
const currentTabId = activeTabIdRef.current;
|
|
101
|
+
const currentTabs = tabsRef.current;
|
|
102
|
+
const activeTab = currentTabs.find(t => t.id === currentTabId);
|
|
103
|
+
|
|
104
|
+
if (!activeTab || activeTab.isDiff) {
|
|
105
|
+
console.log('No active tab or is diff, skip save');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
103
108
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
const port = window.location.port === '5173' ? '5174' : window.location.port;
|
|
110
|
+
const protocol = window.location.protocol === 'https:' ? 'https:' : 'http:';
|
|
111
|
+
|
|
112
|
+
console.log('Saving file:', activeTab.path);
|
|
113
|
+
|
|
114
|
+
fetch(`${protocol}//${window.location.hostname}:${port}/api/save-file`, {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
headers: { 'Content-Type': 'application/json' },
|
|
117
|
+
body: JSON.stringify({ path: activeTab.path, content: activeTab.content })
|
|
118
|
+
})
|
|
119
|
+
.then(response => {
|
|
120
|
+
if (response.ok) {
|
|
121
|
+
console.log('File saved successfully');
|
|
122
|
+
setTabs(prevTabs => prevTabs.map(t =>
|
|
123
|
+
t.id === currentTabId ? { ...t, isModified: false } : t
|
|
124
|
+
));
|
|
125
|
+
} else {
|
|
126
|
+
response.json().then(error => {
|
|
127
|
+
console.error('Failed to save file:', error);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
.catch(error => {
|
|
110
132
|
console.error('Failed to save file:', error);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
console.error('Failed to save file:', error);
|
|
114
|
-
} finally {
|
|
115
|
-
setSaving(false);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
133
|
+
});
|
|
134
|
+
}, []);
|
|
118
135
|
|
|
119
136
|
function handleContentChange(newContent) {
|
|
120
137
|
setTabs(prevTabs => prevTabs.map(t => {
|