Skip to content

Commit f4c48df

Browse files
authored
Merge pull request #67 from hytech-racing/deletion
deletion
2 parents 1f6acf7 + e28aeef commit f4c48df

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/DataTable.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export default function DataTable({
5757
<Table.Td>{getFileNameWithoutExtension(file.mcap_files[0].file_name)}</Table.Td>
5858
<Table.Td>{file.date}</Table.Td>
5959
<Table.Td>{file.location}</Table.Td>
60-
61-
{/* Change back to notes once notes field is implemented in the server */}
62-
<Table.Td>{file.car_model}</Table.Td>
60+
<Table.Td>{file.notes}</Table.Td>
6361
</Table.Tr>
6462
))
6563
);

src/components/PreviewCard.tsx

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Table,
99
ScrollArea,
1010
TextInput,
11+
Notification,
1112
} from "@mantine/core";
1213
import {
1314
IconDownload,
@@ -23,6 +24,39 @@ interface PreviewCardProps {
2324
}
2425

2526
function PreviewCard({ selectedData }: PreviewCardProps) {
27+
const [loading, setLoading] = useState(false);
28+
const [error, setError] = useState<string | null>(null);
29+
const [success, setSuccess] = useState<string | null>(null);
30+
31+
const handleDelete = async () => {
32+
setLoading(true)
33+
setError(null);
34+
setSuccess(null)
35+
try {
36+
const response = await fetch(`${import.meta.env.VITE_API_URL}/mcaps/${selectedData?.id}`, {
37+
method: 'DELETE',
38+
});
39+
40+
if (!response.ok) {
41+
if (response.status === 503) {
42+
const errorMsg = await response.text();
43+
setError(`Failed to delete: ${errorMsg} \nTry again in a few minutes!`);
44+
} else {
45+
const errorMsg = await response.text();
46+
setError(`Failed to delete: ${errorMsg}`);
47+
}
48+
} else {
49+
const result = await response.json();
50+
setSuccess('File deleted successfully!');
51+
console.log('Delete successful:', result);
52+
}
53+
} catch (error) {
54+
console.error('Error sending Delete request:', error);
55+
setError('An error occurred during file deletion.');
56+
}
57+
setLoading(false)
58+
}
59+
2660
const formatDate = (dateString: string) => {
2761
const date = new Date(dateString);
2862
return date.toLocaleDateString("en-US", {
@@ -101,23 +135,37 @@ function PreviewCard({ selectedData }: PreviewCardProps) {
101135
bottom: 0,
102136
left: 0,
103137
padding: 20,
104-
gap: "10px",
138+
gap: "8px",
105139
}}
106140
>
107-
{selectedData.mcap_files.map((item) => (
108-
<DownloadButton
109-
buttonText="MCAP"
110-
fileName={item.file_name}
111-
signedUrl={item.signed_url ?? null}
112-
/>
113-
))}
114-
{selectedData.mat_files.map((item) => (
115-
<DownloadButton
116-
buttonText="MAT"
117-
fileName={item.file_name}
118-
signedUrl={item.signed_url}
119-
/>
120-
))}
141+
<div>
142+
{selectedData.mcap_files.map((item) => (
143+
<DownloadButton
144+
buttonText="MCAP"
145+
fileName={item.file_name}
146+
signedUrl={item.signed_url ?? null}
147+
/>
148+
))}
149+
{selectedData.mat_files.map((item) => (
150+
<DownloadButton
151+
buttonText="MAT"
152+
fileName={item.file_name}
153+
signedUrl={item.signed_url}
154+
/>
155+
))}
156+
<Button loading={loading} loaderProps={{ type: 'dots' }} size="compact-md" color="red" onClick={handleDelete}>Delete</Button>
157+
{success && (
158+
<Notification color="green" onClose={() => setSuccess(null)} style={{ marginTop: 10 }}>
159+
{success}
160+
</Notification>
161+
)}
162+
{error && (
163+
<Notification color="red" onClose={() => setError(null)} style={{ marginTop: 10 }}>
164+
{error}
165+
</Notification>
166+
)}
167+
</div>
168+
121169
</div>
122170
</>
123171
) : (

0 commit comments

Comments
 (0)