Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbaum committed May 10, 2024
1 parent e28c576 commit 6f2b4ef
Showing 1 changed file with 59 additions and 75 deletions.
134 changes: 59 additions & 75 deletions frontend/src/pages/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,58 @@ import DropZone from './DropZone';


const Layout = () => {
const [isSharePanelOpen, setIsSharePanelOpen] = useState<boolean>(false)
const [isStoragePanelOpen, setIsStoragePanelOpen] = useState<boolean>(false);
const [copyClicked, setCopyClicked] = useState<boolean>(false)
const [copyText, setCopyText] = useState<string>('Copy URL')
const [shareLabel, setShareLabel] = useState<string | undefined>('Share')
const [storageLabel, setStorageLabel] = useState<string | undefined>("Storage");
const [hideHistoryLabel, setHideHistoryLabel] = useState<string>('Hide chat history')
const [showHistoryLabel, setShowHistoryLabel] = useState<string>('Show chat history')
const [uploadedFiles, setUploadedFiles] = useState<File[]>([]);
const appStateContext = useContext(AppStateContext)
const ui = appStateContext?.state.frontendSettings?.ui

const handleShareClick = () => {
setIsSharePanelOpen(true);
};
const [isSharePanelOpen, setIsSharePanelOpen] = useState<boolean>(false)
const [isStoragePanelOpen, setIsStoragePanelOpen] = useState<boolean>(false);
const [copyClicked, setCopyClicked] = useState<boolean>(false)
const [copyText, setCopyText] = useState<string>('Copy URL')
const [shareLabel, setShareLabel] = useState<string | undefined>('Share')
const [storageLabel, setStorageLabel] = useState<string | undefined>("Storage");
const [hideHistoryLabel, setHideHistoryLabel] = useState<string>('Hide chat history')
const [showHistoryLabel, setShowHistoryLabel] = useState<string>('Show chat history')
const [uploadedFiles, setUploadedFiles] = useState<File[]>([]);
const appStateContext = useContext(AppStateContext)
const ui = appStateContext?.state.frontendSettings?.ui

const handleShareClick = () => {
setIsSharePanelOpen(true);
};

const handleStorageClick = () => {
setIsStoragePanelOpen(true);
};
const handleStorageClick = () => {
setIsStoragePanelOpen(true);
};

const handleSharePanelDismiss = () => {
setIsSharePanelOpen(false);
setCopyClicked(false);
setCopyText("Copy URL");
};
const handleSharePanelDismiss = () => {
setIsSharePanelOpen(false);
setCopyClicked(false);
setCopyText("Copy URL");
};

const handleStoragePanelDismiss = () => {
setIsStoragePanelOpen(false);
};
const handleStoragePanelDismiss = () => {
setIsStoragePanelOpen(false);
};

const handleCopyClick = () => {
navigator.clipboard.writeText(window.location.href)
setCopyClicked(true)
}
const handleCopyClick = () => {
navigator.clipboard.writeText(window.location.href)
setCopyClicked(true)
}

const handleHistoryClick = () => {
appStateContext?.dispatch({ type: 'TOGGLE_CHAT_HISTORY' })
}
const handleHistoryClick = () => {
appStateContext?.dispatch({ type: 'TOGGLE_CHAT_HISTORY' })
}

// Handle dropped files
const handleFiles = (files: File[]) => {
// Process the dropped files here
// For now, just store them in state
setUploadedFiles([...uploadedFiles, ...files]);
};

const handleSaveButtonClick = async () => {
if (uploadedFiles.length === 0) {
alert("No files to upload.");
return;
}

try {
for (const file of uploadedFiles) {
const response = await uploadFile(file);
Expand All @@ -78,50 +78,45 @@ const handleStoragePanelDismiss = () => {
console.error('Upload error:', error);
}
};



const handleCancelStorage = () => {
setUploadedFiles([]); // Clear uploaded files
handleStoragePanelDismiss(); // Close the storage panel
};


useEffect(() => {
if (copyClicked) {
setCopyText("Copied URL");
}
}, [copyClicked]);

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

useEffect(() => {
const handleResize = () => {
if (window.innerWidth < 480) {
setShareLabel(undefined)
setHideHistoryLabel('Hide history')
setShowHistoryLabel('Show history')
} else {
setShareLabel('Share')
setHideHistoryLabel('Hide chat history')
setShowHistoryLabel('Show chat history')
}
}
useEffect(() => { }, [appStateContext?.state.isCosmosDBAvailable.status])

window.addEventListener('resize', handleResize)
handleResize()
useEffect(() => {
const handleResize = () => {
if (window.innerWidth < 480) {
setShareLabel(undefined)
setHideHistoryLabel('Hide history')
setShowHistoryLabel('Show history')
} else {
setShareLabel('Share')
setHideHistoryLabel('Hide chat history')
setShowHistoryLabel('Show chat history')
}
}

return () => window.removeEventListener('resize', handleResize)
}, [])
window.addEventListener('resize', handleResize)
handleResize()

return (
return (
return () => window.removeEventListener('resize', handleResize)
}, [])
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 @@ -135,27 +130,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}
styles={{

main: [{
selectors: {
['@media (min-width: 480px)']: {
Expand Down Expand Up @@ -196,17 +186,14 @@ const handleStoragePanelDismiss = () => {
main: [{
selectors: {
['@media (min-width: 800px)']: {
maxWidth: '90%',
['@media (min-width: 800px)']: {
maxWidth: '90%',
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',
maxHeight: '600px',
minHeight: '300px',
}

}
}]
}}
Expand All @@ -217,8 +204,6 @@ const handleStoragePanelDismiss = () => {
>
{/* File drop zone */}
<DropZone onFilesDropped={handleFiles} />

{/* Uploaded files */}
{/* Uploaded files */}
{uploadedFiles.length > 0 && (
<div className={styles.uploadedFiles}>
Expand Down Expand Up @@ -246,4 +231,3 @@ const handleStoragePanelDismiss = () => {
};

export default Layout
export default Layout

0 comments on commit 6f2b4ef

Please sign in to comment.