Skip to content

Commit fd1f8fd

Browse files
authored
Merge pull request #3 from Achintha444/HCI-madhavi
Hci madhavi
2 parents 074f764 + 3714808 commit fd1f8fd

File tree

5 files changed

+186
-7
lines changed

5 files changed

+186
-7
lines changed

package-lock.json

Lines changed: 138 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@apollo/client": "3.3.16",
3636
"apollo-server-express": "2.22.2",
3737
"body-parser": "1.19.0",
38+
"bootstrap": "^4.6.0",
3839
"cookie": "0.4.1",
3940
"cookie-parser": "1.4.5",
4041
"cross-env": "7.0.3",
@@ -56,6 +57,7 @@
5657
"react-alert-template-basic": "^1.0.1",
5758
"react-alert-template-oldschool-dark": "^1.0.1",
5859
"react-apollo": "3.1.5",
60+
"react-bootstrap": "^1.6.0",
5961
"react-dom": "17.0.2",
6062
"react-notifications-component": "^3.1.0",
6163
"react-render-html": "0.6.0",

src/components/error-action.spec.tsx

Whitespace-only changes.

src/components/error-action.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react';
2+
import { useRouter } from 'next/router';
3+
import Modal from 'react-bootstrap/Modal'
4+
import "bootstrap/dist/css/bootstrap.min.css";
5+
6+
export interface IErrorActionProps {
7+
currentUrl: string;
8+
}
9+
10+
export function ErrorAction(props: IErrorActionProps): JSX.Element {
11+
const { currentUrl } = props;
12+
13+
const [show, setShow] = React.useState(true);
14+
15+
const router = useRouter();
16+
17+
const handleClose = () => setShow(false);
18+
19+
const handleLogin = () => {
20+
router.push(`/login?goto=${currentUrl}`);
21+
}
22+
23+
return (
24+
<React.Fragment>
25+
<Modal show={show} onHide={handleClose} style={{fontFamily: "Verdana, Geneva, sans-serif", fontSize: "10pt"}}>
26+
<Modal.Body>
27+
<p>You have not logged in yet. Please login to continue!</p>
28+
<div className="float-right" style={{display: 'flex', justifyContent:'center', alignItems:'center'}} >
29+
<input type="submit" value="login" onClick={handleLogin} />
30+
</div>
31+
<div className="float-right mr-1" style={{display: 'flex', justifyContent:'center', alignItems:'center'}} >
32+
<input type="submit" value="cancel" onClick={handleClose} />
33+
</div>
34+
</Modal.Body>
35+
</Modal>
36+
</React.Fragment>
37+
);
38+
}

src/components/news-title.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as React from 'react';
44
import { parse } from 'url';
55

66
import { UPVOTE_NEWS_ITEM_MUTATION } from '../data/mutations/upvote-news-item-mutation';
7+
import { ErrorAction } from './error-action';
78

89
export interface INewsTitleProps {
910
id: number;
@@ -27,8 +28,12 @@ export const newsTitleFragment = `
2728
export function NewsTitle(props: INewsTitleProps): JSX.Element {
2829
const { id, isRankVisible = true, isUpvoteVisible = true, rank, title, upvoted, url } = props;
2930

31+
const [notLoggedIn, setNotLoggedIn] = React.useState(false);
32+
3033
const [upvoteNewsItem] = useMutation(UPVOTE_NEWS_ITEM_MUTATION, {
31-
onError: () => Router.push('/login', `/vote?id=${id}&how=up&goto=news`),
34+
onError: () => {
35+
setNotLoggedIn(true);
36+
},
3237
variables: { id },
3338
});
3439

@@ -48,7 +53,8 @@ export function NewsTitle(props: INewsTitleProps): JSX.Element {
4853
<div className="votearrow" title="upvote" />
4954
</a>
5055
)}
51-
</div>
56+
</div>
57+
<div>{ notLoggedIn && (<ErrorAction currentUrl="news" />) }</div>
5258
</td>
5359
<td className="title">
5460
<a className="storylink" href={url || `item?id=${id}`}>

0 commit comments

Comments
 (0)