4
4
import { Grid , Link , makeStyles } from '@material-ui/core' ;
5
5
import React , { memo , useCallback , useContext , useEffect , useState } from 'react' ;
6
6
import { TargetList } from '../target/targetList' ;
7
- import { connect } from 'react-redux' ;
7
+ import { connect , useDispatch , useSelector } from 'react-redux' ;
8
8
import * as apiActions from '../../reducers/api/actions' ;
9
9
import * as selectionActions from '../../reducers/selection/actions' ;
10
10
import { DJANGO_CONTEXT } from '../../utils/djangoContext' ;
@@ -13,6 +13,8 @@ import { resetCurrentCompoundsSettings } from '../preview/compounds/redux/action
13
13
import { resetProjectsReducer } from '../projects/redux/actions' ;
14
14
import { withLoadingProjects } from '../target/withLoadingProjects' ;
15
15
import { ToastContext } from '../toast' ;
16
+ import { EditTargetDialog } from '../target/editTargetDialog' ;
17
+ import { TOAST_LEVELS } from '../toast/constants' ;
16
18
17
19
const useStyles = makeStyles ( theme => ( {
18
20
root : {
@@ -25,17 +27,43 @@ const useStyles = makeStyles(theme => ({
25
27
26
28
const Landing = memo (
27
29
( { resetSelectionState, resetTargetState, resetCurrentCompoundsSettings, resetProjectsReducer } ) => {
30
+ const dispatch = useDispatch ( ) ;
28
31
const classes = useStyles ( ) ;
29
32
30
33
const projectWidth = window . innerWidth ;
31
34
const [ isResizing , setIsResizing ] = useState ( false ) ;
32
35
const [ targetListWidth , setTargetListWidth ] = useState ( 450 ) ;
33
36
const [ projectListWidth , setProjectListWidth ] = useState ( projectWidth ) ;
34
37
35
- const { toast } = useContext ( ToastContext ) ;
38
+ const { toast, toastSuccess , toastError , toastInfo , toastWarning } = useContext ( ToastContext ) ;
36
39
const [ loginText , setLoginText ] = useState (
37
40
DJANGO_CONTEXT [ 'username' ] === 'NOT_LOGGED_IN' ? '' : "You're logged in as " + DJANGO_CONTEXT [ 'username' ]
38
41
) ;
42
+ const toastMessages = useSelector ( state => state . selectionReducers . toastMessages ) ;
43
+
44
+ useEffect ( ( ) => {
45
+ if ( toastMessages ?. length > 0 ) {
46
+ toastMessages . forEach ( message => {
47
+ switch ( message . level ) {
48
+ case TOAST_LEVELS . SUCCESS :
49
+ toastSuccess ( message . text ) ;
50
+ break ;
51
+ case TOAST_LEVELS . ERROR :
52
+ toastError ( message . text ) ;
53
+ break ;
54
+ case TOAST_LEVELS . INFO :
55
+ toastInfo ( message . text ) ;
56
+ break ;
57
+ case TOAST_LEVELS . WARNING :
58
+ toastWarning ( message . text ) ;
59
+ break ;
60
+ default :
61
+ break ;
62
+ }
63
+ } ) ;
64
+ dispatch ( selectionActions . setToastMessages ( [ ] ) ) ;
65
+ }
66
+ } , [ dispatch , toastError , toastInfo , toastMessages , toastSuccess , toastWarning ] ) ;
39
67
40
68
useEffect ( ( ) => {
41
69
if ( DJANGO_CONTEXT [ 'authenticated' ] !== true ) {
@@ -67,13 +95,16 @@ const Landing = memo(
67
95
setIsResizing ( true ) ;
68
96
} ;
69
97
70
- const handleMouseMove = useCallback ( e => {
71
- if ( ! isResizing ) return ;
72
- const targetListWidth = e . clientX ;
73
- const projectListWidth = window . innerWidth - targetListWidth ;
74
- setTargetListWidth ( targetListWidth ) ;
75
- setProjectListWidth ( projectListWidth ) ;
76
- } , [ isResizing ] ) ;
98
+ const handleMouseMove = useCallback (
99
+ e => {
100
+ if ( ! isResizing ) return ;
101
+ const targetListWidth = e . clientX ;
102
+ const projectListWidth = window . innerWidth - targetListWidth ;
103
+ setTargetListWidth ( targetListWidth ) ;
104
+ setProjectListWidth ( projectListWidth ) ;
105
+ } ,
106
+ [ isResizing ]
107
+ ) ;
77
108
78
109
const handleMouseUp = useCallback ( ( ) => {
79
110
setIsResizing ( false ) ;
@@ -92,24 +123,27 @@ const Landing = memo(
92
123
} , [ isResizing , handleMouseMove , handleMouseUp ] ) ;
93
124
94
125
return (
95
- < Grid container className = { classes . root } >
96
- < Grid item style = { { width : targetListWidth } } >
97
- < TargetList />
98
- </ Grid >
99
- < div
100
- style = { {
101
- cursor : 'col-resize' ,
102
- width : 3 ,
103
- height : '100%' ,
104
- backgroundColor : '#eeeeee' ,
105
- borderRadius : '3px'
106
- } }
107
- onMouseDown = { handleMouseDownResizer }
108
- > </ div >
109
- < Grid item style = { { width : projectListWidth } } >
110
- < Projects />
126
+ < >
127
+ < Grid container className = { classes . root } >
128
+ < Grid item style = { { width : targetListWidth } } >
129
+ < TargetList />
130
+ </ Grid >
131
+ < div
132
+ style = { {
133
+ cursor : 'col-resize' ,
134
+ width : 3 ,
135
+ height : '100%' ,
136
+ backgroundColor : '#eeeeee' ,
137
+ borderRadius : '3px'
138
+ } }
139
+ onMouseDown = { handleMouseDownResizer }
140
+ > </ div >
141
+ < Grid item style = { { width : projectListWidth } } >
142
+ < Projects />
143
+ </ Grid >
111
144
</ Grid >
112
- </ Grid >
145
+ < EditTargetDialog />
146
+ </ >
113
147
) ;
114
148
}
115
149
) ;
0 commit comments