Skip to content

Commit 9e996bc

Browse files
committed
tsify drag drop notification
1 parent e7f30b3 commit 9e996bc

File tree

4 files changed

+90
-101
lines changed

4 files changed

+90
-101
lines changed

lib/ReactViews/DragDropNotification.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/ReactViews/DragDropNotification.jsx

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import classNames from "classnames";
2+
import { reaction } from "mobx";
3+
import { observer } from "mobx-react";
4+
import { FC, useEffect, useRef, useState } from "react";
5+
import { Trans } from "react-i18next";
6+
import Icon from "../Styled/Icon";
7+
import { useViewState } from "./Context";
8+
import Styles from "./drag-drop-notification.scss";
9+
10+
const DragDropNotification: FC = observer(() => {
11+
const viewState = useViewState();
12+
const [showNotification, setShowNotification] = useState(false);
13+
const notificationTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
14+
null
15+
);
16+
17+
useEffect(() => {
18+
const disposer = reaction(
19+
() => viewState.lastUploadedFiles,
20+
() => {
21+
if (notificationTimeoutRef.current) {
22+
clearTimeout(notificationTimeoutRef.current);
23+
}
24+
// show notification, restart timer
25+
setShowNotification(true);
26+
// initialise new time out
27+
notificationTimeoutRef.current = setTimeout(() => {
28+
setShowNotification(false);
29+
}, 5000);
30+
}
31+
);
32+
33+
return () => {
34+
if (notificationTimeoutRef.current) {
35+
clearTimeout(notificationTimeoutRef.current);
36+
}
37+
disposer();
38+
};
39+
}, [viewState.lastUploadedFiles]);
40+
41+
const handleHover = () => {
42+
// reset timer on hover
43+
if (notificationTimeoutRef.current) {
44+
clearTimeout(notificationTimeoutRef.current);
45+
}
46+
};
47+
48+
const handleMouseLeave = () => {
49+
notificationTimeoutRef.current = setTimeout(() => {
50+
setShowNotification(false);
51+
}, 4000);
52+
};
53+
54+
const handleClick = () => {
55+
viewState.openUserData();
56+
};
57+
58+
const fileNames = viewState.lastUploadedFiles.join(",");
59+
60+
return (
61+
<button
62+
className={classNames(Styles.notification, {
63+
[Styles.isActive]: showNotification && fileNames.length > 0
64+
})}
65+
onMouseEnter={handleHover}
66+
onMouseLeave={handleMouseLeave}
67+
onClick={handleClick}
68+
>
69+
<div className={Styles.icon}>
70+
<Icon glyph={Icon.GLYPHS.upload} />
71+
</div>
72+
<div className={Styles.info}>
73+
<Trans
74+
i18nKey="dragDrop.notification"
75+
count={viewState.lastUploadedFiles.length}
76+
>
77+
<span className={Styles.filename}>&quot;{{ fileNames }}&quot;</span>
78+
{{ count: viewState.lastUploadedFiles.length }} been added to{" "}
79+
<span className={Styles.action}>My data</span>
80+
</Trans>
81+
</div>
82+
</button>
83+
);
84+
});
85+
86+
DragDropNotification.displayName = "DragDropNotification";
87+
88+
export default DragDropNotification;

wwwroot/languages/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@
614614
},
615615
"dragDrop": {
616616
"text": "<0>Drag & Drop</0><1>Your data anywhere to view on the map<1>",
617-
"not": "<0>bbbb</0>"
617+
"notification": "<0>\"{{fileNames}}\"</0> has been added to <4>My Data</4>.",
618+
"notification_plural": "<0>\"{{fileNames}}\"</0> have been added to <4>My Data</4>."
618619
},
619620
"loader": {
620621
"loadingMessage": "Loading"

0 commit comments

Comments
 (0)