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.
@@ -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-Dv8f8BcE.js"></script>
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-lens",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "A visualization tool for Codex that monitors API requests and file system changes",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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
- async function saveCurrentFile() {
91
- const activeTab = tabs.find(t => t.id === activeTabId);
92
- if (!activeTab || activeTab.isDiff) return;
93
-
94
- setSaving(true);
95
- try {
96
- const port = window.location.port === '5173' ? '5174' : window.location.port;
97
- const protocol = window.location.protocol === 'https:' ? 'https:' : 'http:';
98
- const response = await fetch(`${protocol}//${window.location.hostname}:${port}/api/save-file`, {
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
- if (response.ok) {
105
- setTabs(prevTabs => prevTabs.map(t =>
106
- t.id === activeTabId ? { ...t, isModified: false } : t
107
- ));
108
- } else {
109
- const error = await response.json();
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
- } catch (error) {
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 => {