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

temporary fix by adding reload button #79

Merged
merged 2 commits into from
Feb 2, 2021
Merged
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
25 changes: 18 additions & 7 deletions src/components/PollsList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { useEffect, useState, useCallback } from "react";
import NProgress from "nprogress";
import { Trash } from "react-bootstrap-icons";
import { ArrowClockwise, Trash } from "react-bootstrap-icons";
import { useSelector } from "react-redux";
import {
Card,
Expand All @@ -27,6 +27,7 @@ const PollsList = (): JSX.Element => {
const encryptedEmailID = encrypt(user);
const [pollList, setPollList] = useState<RocketMeetPollFromDB[]>([]);
const [message, setMessage] = useState<string>("");
const [showButton, setShowButton] = useState<boolean>(false);
const [response, setResponse] = useState({
status: false,
type: "",
Expand All @@ -35,7 +36,7 @@ const PollsList = (): JSX.Element => {
const [modalShow, setModalShow] = useState<boolean>(false);
const [id, setId] = useState<string>("");

const getData = async (): Promise<void> => {
const getData = useCallback(async (): Promise<void> => {
try {
NProgress.start();
const fetchedPolls = await serverAPI.getPolls({
Expand All @@ -48,19 +49,22 @@ const PollsList = (): JSX.Element => {
setMessage(
"You haven't created any polls yet. Create one by clicking the button above!"
);
setShowButton(false);
} else {
setPollList([]);
setMessage("Unable to fetch polls. Please try again later.");
setShowButton(true);
}
} catch (err) {
setMessage("Unable to fetch polls. Check your connection.");
setShowButton(true);
NProgress.done();
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [token]);
useEffect(() => {
getData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [getData]);

const handleDelete = async (pollID: string): Promise<void> => {
try {
Expand Down Expand Up @@ -217,7 +221,14 @@ const PollsList = (): JSX.Element => {
<Polls />
</CardColumns>
) : (
<p>{message}</p>
<span>{message} </span>
)}
{showButton ? (
<Button className="rm-delete-button mx-3" onClick={getData}>
<ArrowClockwise size="22" color="black" />
</Button>
) : (
<></>
)}
</div>
</Col>
Expand Down
4 changes: 3 additions & 1 deletion src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ a {
}
.rm-delete-button {
border-color: rgba(0, 0, 0, 0) !important ;
background-color: rgba(0, 0, 0, 0) !important;
box-shadow: none !important;
width: 40px;
height: 40px;
border: none !important;
padding-left: 0 !important;
}
.rm-delete-button:hover {
transition: 0.1s;
background-color: rgba(0, 0, 0, 0) !important;
transform: scale(1.1);
}
.modal-dark {
Expand Down