Skip to content

Commit

Permalink
Changed File save to REST
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbaum committed May 6, 2024
1 parent dbc8ce3 commit e28c576
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 258 deletions.
56 changes: 31 additions & 25 deletions frontend/src/pages/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,25 @@ const handleStoragePanelDismiss = () => {

const handleSaveButtonClick = async () => {
if (uploadedFiles.length === 0) {
console.error("No files to upload.");
return; // Optionally inform the user to select files
alert("No files to upload.");
return;
}

// Define the container name where files should be uploaded
const containerName = import.meta.env.VITE_CONTAINER_NAME; // Replace with your actual container name

try {
// Iterate over all uploaded files
const uploadPromises = uploadedFiles.map(file =>
uploadFile(containerName, file)
);

// Wait for all files to be uploaded
const results = await Promise.all(uploadPromises);

// Here you can handle the results of each upload
console.log("All files uploaded successfully:", results);

// Clear uploaded files state and close the storage panel
setUploadedFiles([]);
handleStoragePanelDismiss();

// Optional: Provide user feedback about successful uploads
for (const file of uploadedFiles) {
const response = await uploadFile(file);
console.log('Upload response:', response); // Log the response or handle it as needed
}
alert("All files have been successfully uploaded.");
setUploadedFiles([]); // Clear the list after uploading
handleStoragePanelDismiss(); // Optionally close the panel
} catch (error) {
// Handle errors for any failed uploads
console.error("Error uploading files:", error);

// Optional: Provide user feedback about the failure
alert("An error occurred during file upload.");
console.error('Upload error:', error);
}
};



const handleCancelStorage = () => {
setUploadedFiles([]); // Clear uploaded files
Expand All @@ -107,6 +94,7 @@ const handleStoragePanelDismiss = () => {
}, [copyClicked]);

useEffect(() => {}, [appStateContext?.state.isCosmosDBAvailable.status])
useEffect(() => {}, [appStateContext?.state.isCosmosDBAvailable.status])

useEffect(() => {
const handleResize = () => {
Expand All @@ -127,10 +115,13 @@ const handleStoragePanelDismiss = () => {
return () => window.removeEventListener('resize', handleResize)
}, [])

return (
return (
<div className={styles.layout}>
{/* Header */}
{/* Header */}
<header className={styles.header} role={"banner"}>
{/* Logo and Title */}
{/* Logo and Title */}
<Stack horizontal verticalAlign="center" horizontalAlign="space-between">
<Stack horizontal verticalAlign="center">
Expand All @@ -144,18 +135,22 @@ const handleStoragePanelDismiss = () => {
</Link>
</Stack>
{/* Buttons */}
{/* Buttons */}
<Stack horizontal tokens={{ childrenGap: 4 }} className={styles.shareButtonContainer}>
{(appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured) &&
<HistoryButton onClick={handleHistoryClick} text={appStateContext?.state?.isChatHistoryOpen ? hideHistoryLabel : showHistoryLabel} />
}
{ui?.show_share_button && <ShareButton onClick={handleShareClick} text={shareLabel} />}
{ui?.show_share_button && <ShareButton onClick={handleShareClick} text={shareLabel} />}
{ui?.show_storage_button && <StorageButton onClick={handleStorageClick} text={storageLabel} />}
</Stack>
</Stack>
</header>
{/* Main content */}
{/* Main content */}
<Outlet />
{/* Share dialog */}
{/* Share dialog */}
<Dialog
onDismiss={handleSharePanelDismiss}
hidden={!isSharePanelOpen}
Expand Down Expand Up @@ -200,13 +195,17 @@ const handleStoragePanelDismiss = () => {
styles={{
main: [{
selectors: {
['@media (min-width: 800px)']: {
maxWidth: '90%',
['@media (min-width: 800px)']: {
maxWidth: '90%',
background: "#FFFFFF",
boxShadow: "0px 14px 28.8px rgba(0, 0, 0, 0.24), 0px 0px 8px rgba(0, 0, 0, 0.2)",
borderRadius: "8px",
maxHeight: '600px',
minHeight: '300px',
maxHeight: '600px',
minHeight: '300px',
}
}
}]
Expand All @@ -219,6 +218,7 @@ const handleStoragePanelDismiss = () => {
{/* File drop zone */}
<DropZone onFilesDropped={handleFiles} />

{/* Uploaded files */}
{/* Uploaded files */}
{uploadedFiles.length > 0 && (
<div className={styles.uploadedFiles}>
Expand All @@ -235,9 +235,15 @@ const handleStoragePanelDismiss = () => {
<PrimaryButton onClick={handleSaveButtonClick} text="Save" />
<DefaultButton onClick={handleCancelStorage} text="Cancel" style={{ marginLeft: '10px' }} />
</div>
{/* Save and Cancel buttons */}
<div style={{ textAlign: 'right', marginTop: '20px' }}>
<PrimaryButton onClick={handleSaveButtonClick} text="Save" />
<DefaultButton onClick={handleCancelStorage} text="Cancel" style={{ marginLeft: '10px' }} />
</div>
</Dialog>
</div>
);
};

export default Layout
export default Layout
Loading

0 comments on commit e28c576

Please sign in to comment.