FrederickSundeep commited on
Commit
5dabbcf
·
1 Parent(s): 5ecdcc8

commit 015

Browse files
Files changed (2) hide show
  1. src/App.js +3 -2
  2. src/components/FileUpload.jsx +4 -1
src/App.js CHANGED
@@ -11,7 +11,8 @@ export default function App() {
11
  const [loading, setLoading] = useState(false);
12
 
13
  const detectLanguage = (filename) => {
14
- const ext = filename.split('.').pop();
 
15
  switch (ext) {
16
  case "js": return "javascript";
17
  case "py": return "python";
@@ -65,7 +66,7 @@ export default function App() {
65
  <ChatBox messages={messages} loading={loading}/>
66
  <div className="buttons">
67
  <FileUpload onCodeParsed={(code, filename) => {
68
- const lang = detectLanguage(filename.name);
69
  const formatted = `\`\`\`${lang}\n${code}\n\`\`\``;
70
  setLastCode(formatted);
71
  setMessages((prev) => [
 
11
  const [loading, setLoading] = useState(false);
12
 
13
  const detectLanguage = (filename) => {
14
+ if (!filename || typeof filename !== "string") return "";
15
+ const ext = filename.split('.').pop().toLowerCase();
16
  switch (ext) {
17
  case "js": return "javascript";
18
  case "py": return "python";
 
66
  <ChatBox messages={messages} loading={loading}/>
67
  <div className="buttons">
68
  <FileUpload onCodeParsed={(code, filename) => {
69
+ const lang = detectLanguage(filename);
70
  const formatted = `\`\`\`${lang}\n${code}\n\`\`\``;
71
  setLastCode(formatted);
72
  setMessages((prev) => [
src/components/FileUpload.jsx CHANGED
@@ -9,7 +9,10 @@ export default function FileUpload({ onCodeParsed }) {
9
 
10
  const reader = new FileReader();
11
  reader.onload = () => {
12
- onCodeParsed(reader.result);
 
 
 
13
  };
14
  reader.readAsText(file);
15
  };
 
9
 
10
  const reader = new FileReader();
11
  reader.onload = () => {
12
+ const code = reader.result;
13
+ if (typeof onCodeParsed === "function") {
14
+ onCodeParsed(code, file.name); // ✅ pass both code and filename
15
+ }
16
  };
17
  reader.readAsText(file);
18
  };