Skip to content

Commit

Permalink
#2708 image upload and download works
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaryan1203 committed Sep 29, 2024
1 parent 1540118 commit c3fff30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/components/NERUploadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const NERUploadButton = ({ dataTypeId, handleFileChange, onSubmit, addedImage, s
component="img"
src={addedImage ? URL.createObjectURL(addedImage) : ''}
alt="Image Preview"
sx={{ maxWidth: '300px', maxHeight: '300px', mb: 1 }}
sx={{ maxWidth: '200px', mb: 1 }}
/>
<Box sx={{ display: 'flex', width: 'fit-content' }}>
<Button
Expand Down
24 changes: 17 additions & 7 deletions src/frontend/src/pages/AdminToolsPage/TeamConfig/TeamTypeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import CreateTeamTypeFormModal from './CreateTeamTypeFormModal';
import { TeamType } from 'shared';
import EditTeamTypeFormModal from './EditTeamTypeFormModal';
import { useAllTeamTypes, useSetTeamTypeImage } from '../../../hooks/team-types.hooks';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { useToast } from '../../../hooks/toasts.hooks';
import NERUploadButton from '../../../components/NERUploadButton';
import { downloadGoogleImage } from '../../../apis/finance.api';

const TeamTypeTable: React.FC = () => {
const {
Expand All @@ -23,6 +24,19 @@ const TeamTypeTable: React.FC = () => {
const [editingTeamType, setEditingTeamType] = useState<TeamType | undefined>(undefined);
const [addedImages, setAddedImages] = useState<{ [key: string]: File | undefined }>({});
const toast = useToast();
const [imageUrls, setImageUrls] = useState<{ [key: string]: string | undefined }>({}); // Added state to store the image URL

useEffect(() => {
try {
teamTypes?.forEach(async (teamType) => {
const imageBlob = await downloadGoogleImage(teamType.imageFileId ?? '');
const url = URL.createObjectURL(imageBlob);
setImageUrls((prev) => ({ ...prev, [teamType.teamTypeId]: url }));
});
} catch (error) {
toast.error('Failed to fetch image');
}
}, [teamTypes]);

Check warning on line 39 in src/frontend/src/pages/AdminToolsPage/TeamConfig/TeamTypeTable.tsx

View workflow job for this annotation

GitHub Actions / run-linting-check

React Hook useEffect has a missing dependency: 'toast'. Either include it or remove the dependency array

const { mutateAsync: setTeamTypeImage } = useSetTeamTypeImage();

Expand Down Expand Up @@ -56,8 +70,6 @@ const TeamTypeTable: React.FC = () => {
};

const teamTypesTableRows = teamTypes.map((teamType) => {
const imageUrl = teamType.imageFileId ? `https://drive.google.com/uc?id=${teamType.imageFileId}` : '';

return (
<TableRow>
<TableCell onClick={() => setEditingTeamType(teamType)} sx={{ cursor: 'pointer', border: '2px solid black' }}>
Expand Down Expand Up @@ -86,14 +98,12 @@ const TeamTypeTable: React.FC = () => {
</TableCell>
<TableCell sx={{ border: '2px solid black' }}>
<Box sx={{ display: 'flex', flexDirection: 'column', mb: 1 }}>
{console.log(imageUrl)}
{teamType.imageFileId && !addedImages[teamType.teamTypeId] && (
<Box
key={imageUrl}
component="img"
src={imageUrl}
src={imageUrls[teamType.teamTypeId]}
alt="Image Preview"
sx={{ maxWidth: '100%', maxHeight: '200px', mt: 1, mb: 1 }}
sx={{ maxWidth: '100px', mt: 1, mb: 1 }}
/>
)}
<NERUploadButton
Expand Down

0 comments on commit c3fff30

Please sign in to comment.