Skip to content

Commit

Permalink
show the images that have not been uploaded yet
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianovide committed Jul 7, 2021
1 parent 0507b4d commit be43f82
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 145 deletions.
16 changes: 9 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ const App = (props) => {
// didMount
prevLocationRef.current = location;

dbFirebase.processScheduledUploads(console.log);

setStats(config.getStats(geojson, dbStats));

let { photoId, mapLocation } = extractPathnameParams();
Expand Down Expand Up @@ -269,14 +267,16 @@ const App = (props) => {
);
}

// if there is a user
// The user has logged in
if (user && !unregisterOwnPhotos.current) {
unregisterOwnPhotos.current = dbFirebase.ownPhotosRT(
addFeature,
modifyFeature,
removeFeature,
unexpectedErrorFn
);

dbFirebase.processScheduledUploads();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [geojson, location, user]);
Expand Down Expand Up @@ -411,8 +411,12 @@ const App = (props) => {
open: true,
message: "Photo upload scheduled :)",
});
const onProgress = (progress) => console.log(`Uploading photo progress ${progress}`);
const { promise, cancel } = await dbFirebase.scheduleUpload({ location, imgSrc, fieldsValues, onProgress });
// TODO: do I need the promise ????
const { promise, cancel } = await dbFirebase.scheduleUpload({
location,
imgSrc,
fieldsValues,
});
console.debug("I could cancel with ", cancel);
await promise;
setAlert({ key: "photoUploaded", open: true, message: "Photo uploaded !" });
Expand Down Expand Up @@ -723,8 +727,6 @@ const App = (props) => {
photos={getOwnPhotos()}
handleClose={history.goBack}
handlePhotoClick={handlePhotoClick}
// handleRejectClick={handleRejectClick}
// handleApproveClick={handleApproveClick}
/>
)}
/>
Expand Down
176 changes: 84 additions & 92 deletions src/components/OwnPhotosPage.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,107 @@
import React, { Component } from "react";

import _ from "lodash";
import React from "react";

import CheckIcon from "@material-ui/icons/Check";
import ClearIcon from "@material-ui/icons/Clear";
import CloudUpload from "@material-ui/icons/CloudUpload"
import HourglassEmptyIcon from "@material-ui/icons/HourglassEmpty";

import Dialog from "@material-ui/core/Dialog";
import DialogContent from "@material-ui/core/DialogContent";
import List from "@material-ui/core/List";
import ListItem from "@material-ui/core/ListItem";
import ListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction";
import ListItemText from "@material-ui/core/ListItemText";
import Avatar from "@material-ui/core/Avatar";
import ListItemAvatar from "@material-ui/core/ListItemAvatar";
import { Icon } from "@material-ui/core";

import _ from "lodash";

import PageWrapper from "./PageWrapper";
import CardComponent from "./CardComponent";
import config from "custom/config";
import { Icon } from "@material-ui/core";
import { dbFirebase } from "features/firebase";

const placeholderImage = process.env.PUBLIC_URL + "/custom/images/logo.svg";

export default class OwnPhotosPage extends Component {
constructor(props) {
super(props);
this.state = {
confirmDialogHandleCancel: this.handleCancelDialog,
confirmDialogHandleOk: null,
zoomDialogOpen: false,
photoSelected: {},
};
const OwnPhotosPage = (props) => {
const label = config.PAGES.ownPhotos.label;

function createAction(photo) {
// the icon depends on the status
if (dbFirebase.getUploadProgress(photo.properties.id) < 100) {
// still being uploaded
// TODO: display progress
// TODO: add cancell button
return (
<Icon>
<CloudUpload color="error" />
</Icon>
);
} else if (photo.properties.published === false) {
// rejected
return (
<Icon>
<ClearIcon color="error" />
</Icon>
);
} else if (photo.properties.published === true) {
// approved
return (
<Icon>
<CheckIcon color="secondary" />
</Icon>
);
} else {
// waiting for moderation
return (
<Icon>
<HourglassEmptyIcon color="action" />
</Icon>
);
}
}

handleZoomDialogClose = () => {
this.setState({ zoomDialogOpen: false });
};

handleCancelDialog = () => {
this.setState({ confirmDialogOpen: false });
};

render() {
const { handleClose, photos } = this.props;
const label = config.PAGES.ownPhotos.label;
function createThumbnail(photo) {
return dbFirebase.getUploadingPhoto(photo.properties.id, photo.properties.thumbnail);
}

return (
<PageWrapper label={label} handleClose={handleClose} hasHeader={false}>
<List dense={false}>
{_.map(photos, (photo) => (
<ListItem
key={photo.properties.id}
button
onClick={() => this.props.handlePhotoClick(photo)}
>
<ListItemAvatar>
<Avatar
imgProps={{
onError: (e) => {
e.target.src = placeholderImage;
},
}}
src={photo.properties.thumbnail}
/>
</ListItemAvatar>
<ListItemText
primary={config.PHOTO_ZOOMED_FIELDS.updated(
photo.properties.updated
)}
/>
<ListItemSecondaryAction>
<Icon>
{photo.properties.published === true && (
<CheckIcon color="secondary" />
)}
{photo.properties.published === false && (
<ClearIcon color="error" />
)}
{photo.properties.published !== false &&
photo.properties.published !== true && (
<HourglassEmptyIcon olor="action" />
)}
</Icon>
</ListItemSecondaryAction>
</ListItem>
))}
</List>
function createUpdated(photo) {
const progress = dbFirebase.getUploadProgress(photo.properties.id);
return progress < 100
? `${progress} %`
: config.PHOTO_ZOOMED_FIELDS.updated(photo.properties.updated);
}

<Dialog
open={this.state.zoomDialogOpen}
onClose={this.handleZoomDialogClose}
>
<DialogContent>
<div style={{ textAlign: "center" }}>
<img
className={"main-image"}
onError={(e) => {
e.target.src = placeholderImage;
return (
<PageWrapper
label={label}
handleClose={props.handleClose}
hasHeader={false}
>
<List dense={false}>
{_.map(props.photos, (photo) => (
<ListItem
key={photo.properties.id}
button
onClick={() => props.handlePhotoClick(photo)}
>
<ListItemAvatar>
<Avatar
imgProps={{
onError: (e) => {
e.target.src = placeholderImage;
},
}}
alt={this.state.photoSelected.id}
src={this.state.photoSelected.main}
src={createThumbnail(photo)}
/>
</div>
<CardComponent
photoSelected={this.state.photoSelected}
handleRejectClick={this.props.handleRejectClick}
handleApproveClick={this.props.handleApproveClick}
/>
</DialogContent>
</Dialog>
</PageWrapper>
);
}
}
</ListItemAvatar>
<ListItemText primary={createUpdated(photo)} />
<ListItemSecondaryAction>
{createAction(photo)}
</ListItemSecondaryAction>
</ListItem>
))}
</List>
</PageWrapper>
);
};

export default OwnPhotosPage;
Loading

0 comments on commit be43f82

Please sign in to comment.