Spaces:
Running

File size: 3,269 Bytes
ff84109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react';

const CodeEditor = ({ file, onCommit, onDiscard }) => {
  if (!file) {
    return (
      <div className="flex-1 flex flex-col items-center justify-center text-app-muted bg-app-bg">
        <i className="fa-regular fa-folder-open text-6xl mb-6 opacity-20"></i>
        <h3 className="text-xl font-semibold mb-2">Select a file to view changes</h3>
        <p className="max-w-md text-center">Review the diffs and commit your work to the repository.</p>
      </div>
    );
  }

  const lines = file.content.split('\n');

  const getStatusClass = (line) => {
    if (line.includes('+') && !line.includes('import')) return 'bg-status-added/10 border-l-2 border-status-added';
    if (line.includes('-') && !line.includes('import')) return 'bg-status-deleted/10 line-through opacity-60 border-l-2 border-status-deleted';
    return 'hover:bg-app-panel/50';
  };

  return (
    <div className="flex-1 flex flex-col bg-app-bg h-full">
      <div className="h-16 border-b border-app-border flex items-center justify-between px-6 bg-app-bg">
        <div className="flex items-center gap-2 font-mono text-sm text-app-muted">
          <span>root</span>
          <i className="fa-solid fa-chevron-right text-xs opacity-50"></i>
          <span className="text-app-text font-medium">{file.name}</span>
        </div>
        <div className="flex items-center gap-3">
          <button 
            onClick={onDiscard}
            className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-app-muted hover:text-status-deleted transition-colors"
          >
            <i className="fa-solid fa-rotate-left"></i> Discard
          </button>
          <button 
            onClick={onCommit}
            className="flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-accent-primary hover:bg-blue-600 rounded-md shadow-lg shadow-accent-primary/20 transition-all transform active:scale-95"
          >
            <i className="fa-solid fa-check"></i> Commit Changes
          </button>
        </div>
      </div>

      <div className="flex-1 overflow-auto p-6 font-mono text-sm leading-7 text-gray-300">
        {lines.map((line, idx) => {
          // Simple syntax highlighting simulation
          let processedLine = line
            .replace(/(const|let|var|function|return|import|from)/g, '<span class="text-pink-400 font-bold">$1</span>')
            .replace(/('.*?')/g, '<span class="text-cyan-300">$1</span>')
            .replace(/(\/\/.*)/g, '<span class="text-gray-500 italic">$1</span>');

          // Mark added/removed lines visually
          const isAdded = line.includes('+') && !line.includes('import');
          const isRemoved = line.includes('-') && !line.includes('import');

          return (
            <div key={idx} className={`flex group ${isAdded ? 'bg-status-added/10' : isRemoved ? 'bg-status-deleted/10' : 'hover:bg-app-panel/30'}`}>
              <div className="w-10 pr-4 text-right text-gray-600 select-none text-xs border-r border-gray-800 mr-4">
                {idx + 1}
              </div>
              <div className="flex-1 whitespace-pre pl-2" dangerouslySetInnerHTML={{ __html: processedLine }} />
            </div>
          );
        })}
      </div>
    </div>
  );
};