Skip to content

Commit c26e9be

Browse files
committed
implement notification onClick
1 parent bf3e335 commit c26e9be

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/components/SetupPage/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,29 @@ import DatasetJSONEditor from "../DatasetJSONEditor"
1818
import useInterface from "../../hooks/use-interface"
1919
import useSample from "../../hooks/use-sample"
2020
import Protip from "./Protip"
21+
import { useToasts } from "../Toasts"
2122

2223
const noop = () => {}
2324

2425
export default ({ onClearLabelData }) => {
2526
const { iface, updateInterface } = useInterface()
2627
const { sample } = useSample(0)
27-
28+
const { addToast } = useToasts()
2829
const [currentTab, setTab] = useState(iface?.type ? "configure" : "datatype")
2930

3031
return (
3132
<div>
3233
<Box padding="8px" paddingBottom="0px">
33-
<Tabs value={currentTab} onChange={(e, newTab) => setTab(newTab)}>
34+
<Tabs value={currentTab} onChange={(e, newTab) => {
35+
addToast(
36+
"Couldn't load plugin: ",
37+
"error",
38+
() => {
39+
console.log('passed click')
40+
}
41+
)
42+
setTab(newTab)
43+
}}>
3444
<Tab icon={<CategoryIcon />} label="Data Type" value="datatype" />
3545
<Tab
3646
disabled={!iface?.type}

src/components/Toasts/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export const ToastProvider = ({ children }) => {
9595
id: Math.random().toString().split(".")[1],
9696
message: action.message,
9797
type: action.messageType,
98+
onClick: action.onClick || null,
9899
life: fullLife,
99100
fullLife,
100101
},
@@ -126,8 +127,8 @@ export const ToastProvider = ({ children }) => {
126127
return () => clearInterval(interval)
127128
}, [toasts])
128129

129-
const addToast = (message: string, messageType: string = "info") =>
130-
changeToasts({ type: "add", message, messageType })
130+
const addToast = (message: string, messageType: string = "info", onClick: function = null) =>
131+
changeToasts({ type: "add", message, messageType, onClick })
131132

132133
return (
133134
<>
@@ -141,6 +142,7 @@ export const ToastProvider = ({ children }) => {
141142
<Notification
142143
type={msg.type}
143144
message={msg.message}
145+
onClick={msg.onClick}
144146
onClose={() => changeToasts({ type: "remove", id: msg.id })}
145147
/>
146148
</Fade>
@@ -151,7 +153,7 @@ export const ToastProvider = ({ children }) => {
151153
)
152154
}
153155

154-
export const Notification = ({ type, message, onClose }) => {
156+
export const Notification = ({ type, message, onClick, onClose }) => {
155157
const classes = useStyles()
156158
let Icon = null
157159
switch (type) {
@@ -170,7 +172,12 @@ export const Notification = ({ type, message, onClose }) => {
170172
return (
171173
<paper
172174
className={classes.notificationPaper}
173-
style={{ position: "relative" }}
175+
style={{ position: "relative", cursor: 'pointer' }}
176+
onClick={() => {
177+
if (onClick) {
178+
onClick()
179+
}
180+
}}
174181
>
175182
<div className={classNames(classes.icon, type)}>
176183
<Icon fontSize="large" style={{ padding: 12 }} />

0 commit comments

Comments
 (0)