-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from midas1214/main
implement UI for the four pages, download and upload
- Loading branch information
Showing
12 changed files
with
773 additions
and
77 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.login-block { | ||
max-width: 300px; | ||
margin: 20px auto; | ||
padding: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 10px; | ||
background-color: #f9f9f9; | ||
text-align: center; | ||
} | ||
|
||
.login-block input { | ||
width: 100%; | ||
padding: 10px; | ||
margin: 10px -10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
|
||
.button-group { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.button-group button { | ||
width: 45%; | ||
padding: 10px; | ||
background-color: #61dafb; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
font-size: 1rem; | ||
} | ||
|
||
.button-group button:hover { | ||
background-color: #21a1f1; | ||
} | ||
|
||
.error { | ||
color: red; | ||
margin-top: 10px; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
interface PackageMetadata { | ||
ID: string; | ||
Name: string; | ||
Version: string; | ||
} | ||
|
||
const SearchByName: React.FC = () => { | ||
const [packageName, setPackageName] = useState(''); | ||
const [results, setResults] = useState<PackageMetadata[]>([]); | ||
const [authToken, setAuthToken] = useState<string | null>(null); | ||
const [error, setError] = useState<string | null>(null); | ||
const [offset, setOffset] = useState<number>(0); | ||
|
||
// Retrieve auth token from localStorage on component mount | ||
useEffect(() => { | ||
const token = localStorage.getItem('authToken'); | ||
if (token) { | ||
setAuthToken(token); | ||
} else { | ||
alert('Authentication token not found. Please log in.'); | ||
} | ||
}, []); | ||
|
||
const handleSearch = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
setError(null); | ||
|
||
if (!authToken) { | ||
alert('Authentication token is missing. Please log in.'); | ||
return; | ||
} | ||
|
||
try { | ||
const requestBody = [{ Name: packageName }]; | ||
|
||
// const response = await fetch(`/packages?offset=${offset}`, { | ||
// method: 'POST', | ||
// headers: { | ||
// 'Content-Type': 'application/json', | ||
// 'X-Authorization': authToken, | ||
// }, | ||
// body: JSON.stringify(requestBody), | ||
// }); | ||
|
||
const response1 = JSON.stringify({ | ||
status: 200, | ||
data: [ | ||
{ | ||
packageName: 'example-package', | ||
version: '1.0.0', | ||
description: 'Sample description for testing purposes.', | ||
fileUrl: 'https://example.com/uploads/example-package-v1.0.0.zip', | ||
uploadDate: '2024-11-03T14:30:00Z', | ||
debloatEnabled: true, | ||
}, | ||
{ | ||
packageName: 'another-package', | ||
version: '2.0.1', | ||
description: 'Another example package for testing.', | ||
fileUrl: 'https://example.com/uploads/another-package-v2.0.1.zip', | ||
uploadDate: '2024-11-02T10:15:00Z', | ||
debloatEnabled: false, | ||
}, | ||
], | ||
headers: { | ||
offset: '10', | ||
}, | ||
}); | ||
|
||
// Parse the response as JSON | ||
const response = JSON.parse(response1); | ||
|
||
if (response.status === 200) { | ||
const data: PackageMetadata[] = await response.json(); | ||
setResults(data); | ||
const newOffset = parseInt(response.headers.get('offset') || '0', 10); | ||
setOffset(newOffset); | ||
} else if (response.status === 400) { | ||
setError('Search failed: Missing fields or invalid query.'); | ||
} else if (response.status === 403) { | ||
setError('Search failed: Authentication failed due to invalid or missing AuthenticationToken.'); | ||
} else if (response.status === 413) { | ||
setError('Search failed: Too many packages returned.'); | ||
} else { | ||
setError('Search failed with an unknown error.'); | ||
} | ||
} catch (err) { | ||
console.error('Error during search:', err); | ||
setError('An error occurred while searching for packages.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={{ maxWidth: '600px', margin: '0 auto', padding: '20px' }}> | ||
<h2>Search for Packages</h2> | ||
<form onSubmit={handleSearch}> | ||
<label> | ||
Package Name: | ||
<input | ||
type="text" | ||
value={packageName} | ||
onChange={(e) => setPackageName(e.target.value)} | ||
required | ||
style={{ width: '100%', padding: '8px', margin: '10px 0' }} | ||
/> | ||
</label> | ||
<button type="submit" style={{ padding: '10px 20px', backgroundColor: '#007bff', color: '#fff', border: 'none', cursor: 'pointer' }}> | ||
Search | ||
</button> | ||
</form> | ||
|
||
{error && <p style={{ color: 'red' }}>{error}</p>} | ||
|
||
{results.length > 0 && ( | ||
<div style={{ marginTop: '20px' }}> | ||
<h3>Search Results</h3> | ||
<ul> | ||
{results.map((pkg) => ( | ||
<li key={pkg.ID}> | ||
<strong>Name:</strong> {pkg.Name} | <strong>Version:</strong> {pkg.Version} | <strong>ID:</strong> {pkg.ID} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchByName; |
Oops, something went wrong.