Skip to content

Commit 331cc9c

Browse files
committed
use new api endpoint
1 parent 6d52f2e commit 331cc9c

File tree

1 file changed

+31
-58
lines changed

1 file changed

+31
-58
lines changed

spicecloud/pages/index.tsx

Lines changed: 31 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,65 +27,38 @@ export default function Home() {
2727
const [loading, setLoading] = useState(true);
2828
const [error, setError] = useState<string | null>(null);
2929

30-
const fetchData = async () => {
31-
try {
32-
setLoading(true);
33-
// Simulated data for demo
34-
const mockData = [
35-
{
36-
id: '1',
37-
hash: 'abc123',
38-
timestamp: Date.now() - 1800000,
39-
file_name: 'func_sample.go',
40-
file_path: 'C:\\Users\\marua\\Desktop\\scripts\\2024\\2025\\spicecode\\tests\\sample-code\\func_sample.go',
41-
age: 1800000,
42-
readable_timestamp: '29/06/2025, 23:13:33',
43-
metrics: {
44-
line_count: 28,
45-
comment_line_count: 2,
46-
inline_comment_count: 1,
47-
function_count: 15,
48-
external_dependencies_count: 1,
49-
comment_ratio: 0.1667,
50-
file_extension: '.go',
51-
file_size: 1024,
52-
indentation_type: 'tabs',
53-
indentation_size: 4,
54-
method_type_count: { public: 8, private: 7 }
55-
}
56-
},
57-
{
58-
id: '2',
59-
hash: 'def456',
60-
timestamp: Date.now() - 1920000,
61-
file_name: 'example.js',
62-
file_path: 'C:\\Users\\marua\\Desktop\\scripts\\2024\\2025\\spicecode\\tests\\sample-code\\example.js',
63-
age: 1920000,
64-
readable_timestamp: '29/06/2025, 23:11:33',
65-
metrics: {
66-
line_count: 45,
67-
comment_line_count: 8,
68-
inline_comment_count: 3,
69-
function_count: 6,
70-
external_dependencies_count: 3,
71-
comment_ratio: 0.2444,
72-
file_extension: '.js',
73-
file_size: 2048
74-
}
75-
}
76-
];
77-
78-
setData(mockData);
79-
if (mockData.length > 0 && !selectedFile) {
80-
setSelectedFile(mockData[0]);
30+
const fetchData = async () => {
31+
try {
32+
setLoading(true);
33+
34+
// ‼ ajuste a rota se o seu endpoint for diferente
35+
const res = await fetch('/api/files');
36+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
37+
38+
const json = await res.json();
39+
40+
const files = json.map((f: any) => ({
41+
...f,
42+
age: Date.now() - f.timestamp,
43+
readable_timestamp: new Date(f.timestamp).toLocaleString('pt-BR'),
44+
// se comment_ratio vier como string (“16.23%”) e você preferir número:
45+
metrics: {
46+
...f.metrics,
47+
comment_ratio: typeof f.metrics.comment_ratio === 'string'
48+
? parseFloat(f.metrics.comment_ratio) / 100
49+
: f.metrics.comment_ratio
8150
}
82-
} catch (err) {
83-
setError('Error fetching data');
84-
console.error(err);
85-
} finally {
86-
setLoading(false);
87-
}
88-
};
51+
}));
52+
53+
setData(files);
54+
if (files.length && !selectedFile) setSelectedFile(files[0]);
55+
} catch (err) {
56+
setError('Erro ao buscar dados');
57+
console.error(err);
58+
} finally {
59+
setLoading(false);
60+
}
61+
};
8962

9063
useEffect(() => {
9164
fetchData();

0 commit comments

Comments
 (0)