Skip to content

Commit 4aaba06

Browse files
committed
v1 of s3 screenshots working
1 parent 4952ec2 commit 4aaba06

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

app/src/components/marketplace/MarketplaceCard.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import {
1919
resetAllState
2020
} from '../../redux/reducers/slice/appStateSlice';
2121
import { useDispatch, useSelector } from 'react-redux';
22-
2322
import { MoreVert } from '@mui/icons-material';
2423
import { RootState } from '../../redux/store';
2524
import Snackbar from '@mui/material/Snackbar';
2625
import axios from 'axios';
27-
import imageSrc from '../../../../resources/marketplace_images/marketplace_image.png';
26+
// import imageSrc from '../../../../resources/marketplace_images/marketplace_image.png';
2827
import { red } from '@mui/material/colors';
2928
import { saveProject } from '../../helperFunctions/projectGetSaveDel';
3029
import { useHistory } from 'react-router-dom';
30+
import { Amplify, Storage } from 'aws-amplify';
31+
import awsconfig from '../../../../src/aws-exports';
3132

3233
interface Project {
3334
forked: String;
@@ -47,9 +48,27 @@ const MarketplaceCard = ({ proj }: { proj: Project }) => {
4748
const dispatch = useDispatch();
4849
const history = useHistory();
4950
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
51+
const [s3ImgURL, setS3ImgURL] = React.useState<null | string>(null);
5052
const open = Boolean(anchorEl);
5153
const [alertOpen, setAlertOpen] = React.useState<boolean>(false);
52-
const state = useSelector((store: RootState) => store.appState);
54+
55+
useEffect(() => {
56+
async function s3ImgFetch() {
57+
Amplify.configure(awsconfig);
58+
try {
59+
const objId: string = proj._id.toString();
60+
// the below functions are commented out as not to incur too many charges
61+
// const response: string = await Storage.get(objId);
62+
// const response: string = await Storage.get('test');
63+
// setS3ImgURL(response);
64+
} catch (error) {
65+
console.error(`Error fetching image preview for ${proj._id}: `, error);
66+
}
67+
}
68+
s3ImgFetch();
69+
}, []);
70+
71+
5372
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
5473
setAnchorEl(event.currentTarget);
5574
};
@@ -107,8 +126,8 @@ const MarketplaceCard = ({ proj }: { proj: Project }) => {
107126
sx={{ borderRadius: '12px', height: 200 }}
108127
component="img"
109128
height="194"
110-
image={imageSrc}
111-
alt="component buttons"
129+
image={s3ImgURL}
130+
alt="component preview"
112131
/>
113132
<CardHeader
114133
avatar={

app/src/components/top/NavBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ const NavBar = () => {
9494
.then((newProject: State) => {
9595
console.log('Project published successfully', newProject);
9696
setPublishModalOpen(false);
97+
dispatch(updateProjectId(newProject._id));
98+
dispatch(updateProjectName(newProject.name));
99+
dispatch(updateProjectPublished(newProject.published));
97100
dispatch(toggleScreenshotTrigger());
98-
dispatch(updateProjectId(newProject._id))
99-
dispatch(updateProjectName(newProject.name))
100-
dispatch(updateProjectPublished(newProject.published))
101101
setAlertOpen(true)
102102
})
103103
.catch((error) => {

app/src/containers/MainContainer.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import awsconfig from '../../../src/aws-exports';
1313
const MainContainer = (props): JSX.Element => {
1414
const dispatch = useDispatch();
1515
const screenshotTrigger = useSelector((store: RootState) => store.appState.screenshotTrigger);
16+
const id: string = useSelector((store: RootState) => store.appState._id);
1617
const { isDarkMode, style } = useSelector((store) => ({
1718
isDarkMode: store.darkMode.isDarkMode,
1819
style: store.styleSlice,
@@ -26,9 +27,6 @@ const MainContainer = (props): JSX.Element => {
2627
try {
2728
const canvas: HTMLCanvasElement = await html2canvas(containerRef.current);
2829
const screenshotURL: string = canvas.toDataURL('image/png');
29-
// const canvasImg: HTMLImageElement = new Image();
30-
// canvasImg.src = canvas.toDataURL();
31-
// containerRef.current.appendChild(canvasImg);
3230
const imgBuffer: Buffer | void = Buffer.from(screenshotURL.replace(/^data:image\/\w+;base64,/, ''), 'base64');
3331
dispatch(toggleScreenshotTrigger());
3432
return imgBuffer;
@@ -39,7 +37,6 @@ const MainContainer = (props): JSX.Element => {
3937
}
4038
handleScreenshot().then((imgBuffer: Buffer | void) => {
4139
if (imgBuffer) {
42-
console.log('Screenshot URL:', imgBuffer);
4340
uploadScreenshotS3(imgBuffer);
4441
}
4542
});
@@ -60,7 +57,7 @@ const MainContainer = (props): JSX.Element => {
6057
// Call this function to check the connection
6158
checkStorageConnection();
6259
try {
63-
await Storage.put('test.png', imgBuffer, {
60+
await Storage.put(id, imgBuffer, {
6461
contentType: 'image/png',
6562
});
6663
console.log('Screenshot uploaded to S3');

app/src/containers/MarketplaceContainer.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const MarketplaceContainer = () => {
1919
});
2020
setMarketplaceProjects(response.data);
2121
setDisplayProjects(response.data);
22-
2322
} catch (error) {
2423
console.error('Error fetching MP data:', error);
2524
}
@@ -30,13 +29,8 @@ const MarketplaceContainer = () => {
3029

3130

3231
const updateDisplayProjects = (searchResults) => {
33-
3432
setDisplayProjects(searchResults);//have to pass this down as a prop so that the setting is done outside of Rendering otherwise callstack issues
35-
3633
};
37-
38-
39-
4034

4135
return (
4236
<div style={containerStyles}>

0 commit comments

Comments
 (0)