Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Fix : Oversized Image In Image Drawer Fixed ] #1167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
287 changes: 162 additions & 125 deletions src/components/Tutorials/subComps/ImageDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,72 +50,60 @@ const ImageDrawer = ({ onClose, visible, owner, tutorial_id, imageURLs }) => {
}) => deleting_error
);

const [uploadSnackbarOpen, setUploadSnackbarOpen] = React.useState(false);
const [uploadErrorSnackbarOpen, setUploadErrorSnackbarOpen] =
React.useState(false);
const [deleteSnackbarOpen, setDeleteSnackbarOpen] = React.useState(false);
const [deleteErrorSnackbarOpen, setDeleteErrorSnackbarOpen] =
React.useState(false);

useEffect(() => {
if (uploading === false && uploading_error === false) {
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={true}
autoHideDuration={6000}
message="Image Uploaded successfully...."
/>;
setUploadSnackbarOpen(true);
} else if (uploading === false && uploading_error) {
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={true}
autoHideDuration={6000}
message={uploading_error}
/>;
setUploadErrorSnackbarOpen(true);
}
}, [uploading, uploading_error]);

useEffect(() => {
if (deleting === false && deleting_error === false) {
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={true}
autoHideDuration={6000}
message="Deleted Succefully...."
/>;
setDeleteSnackbarOpen(true);
} else if (deleting === false && deleting_error) {
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={true}
autoHideDuration={6000}
message={deleting_error}
/>;
setDeleteErrorSnackbarOpen(true);
}
}, [deleting, deleting_error]);

const handleSnackbarClose = type => {
switch (type) {
case "upload":
setUploadSnackbarOpen(false);
setUploadErrorSnackbarOpen(false);
break;
case "delete":
setDeleteSnackbarOpen(false);
setDeleteErrorSnackbarOpen(false);
break;
default:
break;
}
};

useEffect(() => {
clearTutorialImagesReducer()(dispatch);
return () => {
clearTutorialImagesReducer()(dispatch);
};
}, [dispatch]);

const props = {
name: "file",
multiple: true,
beforeUpload(file, files) {
uploadTutorialImages(owner, tutorial_id, files)(
firebase,
firestore,
dispatch
);
return false;
}
const beforeUpload = async files => {
console.log("Image Upload Started!!!")
await uploadTutorialImages(owner, tutorial_id, files)(
firebase,
firestore,
dispatch
);
console.log("Uploaded the Images");
return false;
};

const deleteFile = (name, url) =>
Expand All @@ -127,85 +115,134 @@ const ImageDrawer = ({ onClose, visible, owner, tutorial_id, imageURLs }) => {
)(firebase, firestore, dispatch);

return (
<Drawer
title="Images"
data-testid="imageDrawer"
anchor="right"
closable={true}
onClose={onClose}
open={visible}
getContainer={true}
style={{ position: "absolute" }}
width="400px"
className="image-drawer"
destroyOnClose={true}
maskClosable={false}
>
<div className="col-pad-24" data-testId="tutorialImgUpload">
<Grid>
<input
id="file-upload"
fullWidth
accept="image/*"
type="file"
{...props}
/>
{uploading ? (
<>
<LoadingOutlined /> Please wait...
<p className="ant-upload-hint mt-8">Uploading image(s)...</p>
</>
) : (
<>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">
Click or drag images to here to upload
</p>
</>
)}
</Grid>
{imageURLs &&
imageURLs.length > 0 &&
imageURLs.map((image, i) => (
<Grid className="mb-24" key={i}>
<Grid xs={24} md={8}>
<img src={image.url} alt="" />
</Grid>
<Grid xs={24} md={16} className="pl-8" style={{}}>
<h4 className="pb-8">{image.name}</h4>

<CopyToClipboard
text={`![alt=image; scale=1.0](${image.url})`}
onCopy={() => (
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={true}
autoHideDuration={6000}
message="Copied...."
/>
)}
>
<Button type="primary">Copy URL</Button>
</CopyToClipboard>

<Button
loading={deleting}
onClick={() => deleteFile(image.name, image.url)}
type="ghost"
danger
>
Delete
</Button>
<>
<Drawer
title="Images"
data-testid="imageDrawer"
anchor="right"
closable={true}
onClose={onClose}
open={visible}
getContainer={true}
style={{ position: "absolute" }}
width="400px"
className="image-drawer"
destroyOnClose={true}
maskClosable={false}
>
<div className="col-pad-24" data-testId="tutorialImgUpload">
<Grid>
<input
id="file-upload"
fullWidth
accept="image/*"
type="file"
name="file"
multiple
onChange={event => beforeUpload(event.target.files)}
/>
{uploading ? (
<>
<LoadingOutlined /> Please wait...
<p className="ant-upload-hint mt-8">Uploading image(s)...</p>
</>
) : (
<>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text">
Click or drag images to here to upload
</p>
</>
)}
</Grid>
{imageURLs &&
imageURLs.length > 0 &&
imageURLs.map((image, i) => (
<Grid className="mb-24" key={i}>
<Grid
style={{
maxWidth: "240px",
objectFit: "cover"
}}
xs={24} md={8}>
<img src={image.url} alt="" />
</Grid>
<Grid xs={24} md={16} className="pl-8" style={{}}>
<h4 className="pb-8">{image.name}</h4>

<CopyToClipboard
text={`![alt=image; scale=1.0](${image.url})`}
onCopy={() => (
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={true}
autoHideDuration={6000}
message="Copied...."
/>
)}
>
<Button type="primary">Copy URL</Button>
</CopyToClipboard>

<Button
loading={deleting}
onClick={() => deleteFile(image.name, image.url)}
type="ghost"
danger
>
Delete
</Button>
</Grid>
</Grid>
</Grid>
))}
</div>
</Drawer>
))}
</div>
</Drawer>
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={uploadSnackbarOpen}
autoHideDuration={6000}
onClose={() => handleSnackbarClose("upload")}
message="Image Uploaded successfully...."
/>
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={uploadErrorSnackbarOpen}
autoHideDuration={6000}
onClose={() => handleSnackbarClose("upload")}
message={uploading_error}
/>
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={deleteSnackbarOpen}
autoHideDuration={6000}
onClose={() => handleSnackbarClose("delete")}
message="Deleted Successfully...."
/>
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left"
}}
open={deleteErrorSnackbarOpen}
autoHideDuration={6000}
onClose={() => handleSnackbarClose("delete")}
message={deleting_error}
/>
</>
);
};

Expand Down
11 changes: 7 additions & 4 deletions src/store/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ export const resendVerifyEmail = email => async dispatch => {
export const checkUserHandleExists = userHandle => async firebase => {
try {
const handle = await firebase
.ref(`/cl_user_handle/${userHandle}`)
.once("value");
return handle.exists();
.firestore()
.collection("cl_user")
.doc(userHandle)
.get();
console.log("User Handle",handle)
return handle.exists;
} catch (e) {
throw e.message;
}
Expand All @@ -195,7 +198,7 @@ export const checkOrgHandleExists = orgHandle => async firebase => {
.doc(orgHandle)
.get();

console.log(organizationHandle);
console.log("Organization Handle",organizationHandle);
return organizationHandle.exists;
} catch (e) {
throw e.message;
Expand Down
10 changes: 5 additions & 5 deletions src/store/actions/tutorialsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export const createTutorial =
}
};

const checkUserOrOrgHandle = handle => async firestore => {
const userHandleExists = await checkUserHandleExists(handle)(firestore);
const orgHandleExists = await checkOrgHandleExists(handle)(firestore);
const checkUserOrOrgHandle = handle => async firebase => {
const userHandleExists = await checkUserHandleExists(handle)(firebase);
const orgHandleExists = await checkOrgHandleExists(handle)(firebase);

if (userHandleExists && !orgHandleExists) {
return "user";
Expand Down Expand Up @@ -388,8 +388,8 @@ export const uploadTutorialImages =
(owner, tutorial_id, files) => async (firebase, firestore, dispatch) => {
try {
dispatch({ type: actions.TUTORIAL_IMAGE_UPLOAD_START });
const type = await checkUserOrOrgHandle(owner)(firestore);

const type = await checkUserOrOrgHandle(owner)(firebase);
const storagePath = `tutorials/${type}/${owner}/${tutorial_id}`;
const dbPath = `tutorials`;
await firebase.uploadFiles(storagePath, files, dbPath, {
Expand Down