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

react-hot-toast animation for indicating success and failure in the client side #38

Open
wants to merge 4 commits into
base: main
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
44 changes: 43 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"react-bootstrap": "^2.6.0",
"react-dom": "^18.2.0",
"react-drag-drop-files": "^2.3.7",
"react-hot-toast": "^2.4.0",
"react-scripts": "5.0.1",
"workbox-core": "^6.5.4",
"workbox-expiration": "^6.5.4",
Expand Down
22 changes: 20 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import NavigationBar from './NavigationBar';
import AuthDialog from './AuthDialog';
import UploadInterface from './UploadInterface';
import ProjectForm from './ProjectForm';
import { githubUpload } from './github-upload';
import toast, { Toaster } from 'react-hot-toast';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
Expand All @@ -18,7 +20,7 @@ function App() {
const [token, setToken] = useState(null);
const [repository, setRepository] = useState(null);
const [show, setShow] = useState(true);
const isAuthorized = token && repository;
const isAuthorized = token && repository && true;

return (
<>
Expand All @@ -33,12 +35,28 @@ function App() {
<AuthDialog show={show} setShow={setShow} setToken={setToken} setRepository={setRepository} />
<Stack direction={'row'}>
<Item>
<UploadInterface isAuthorized={isAuthorized} />
<UploadInterface
isAuthorized={isAuthorized}
uploadFile={(file) => {
let loadId = toast.loading('Uploading Image...');
githubUpload(token, repository, file)
.then(() => {
toast.dismiss(loadId);
toast.success('Image uploaded successfully!');
})
.catch((e) => {
toast.dismiss(loadId);
toast.error('Image upload failed!');
console.error(e);
});
}}
/>
</Item>
<Item>
<ProjectForm />
</Item>
</Stack>
<Toaster position="bottom-left" />
</>
);
}
Expand Down
10 changes: 7 additions & 3 deletions src/UploadInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from 'prop-types';

const fileTypes = ["jpg", "jpeg", "png", "bmp", "gif"];

function UploadInterface({ isAuthorized }) {
function UploadInterface({ isAuthorized, uploadFile }) {
const [image, setImage] = useState(null);
const imgPreviewEl = useRef(null);

Expand Down Expand Up @@ -55,6 +55,9 @@ function UploadInterface({ isAuthorized }) {
variant="success"
className="mt-3"
disabled={!(isAuthorized && image)}
onClick={() => {
uploadFile(image);
}}
>
Upload
</Button>
Expand All @@ -66,7 +69,8 @@ function UploadInterface({ isAuthorized }) {
}

UploadInterface.propTypes = {
isAuthorized:PropTypes.bool
isAuthorized:PropTypes.bool,
uploadFile: PropTypes.func
}

export default UploadInterface
export default UploadInterface
File renamed without changes.