From 29beceea16ffed38fe995ffcb7b52ea133b44681 Mon Sep 17 00:00:00 2001 From: Tibor Postek Date: Tue, 10 Mar 2020 08:34:05 +0100 Subject: [PATCH] #2 reset project reducer after exit from project or target --- js/components/landing/Landing.js | 78 +++++++++++-------- js/components/preview/Preview.js | 3 +- js/components/preview/projectHistory/index.js | 4 +- js/components/projects/index.js | 38 ++++----- js/components/projects/redux/actions.js | 2 + js/components/projects/redux/constants.js | 4 +- js/components/projects/redux/reducer.js | 3 + 7 files changed, 76 insertions(+), 56 deletions(-) diff --git a/js/components/landing/Landing.js b/js/components/landing/Landing.js index c98d05627..6f4b69f53 100644 --- a/js/components/landing/Landing.js +++ b/js/components/landing/Landing.js @@ -12,43 +12,54 @@ import { DJANGO_CONTEXT } from '../../utils/djangoContext'; import { Projects } from '../projects'; import { HeaderContext } from '../header/headerContext'; import { resetCurrentCompoundsSettings } from '../preview/compounds/redux/actions'; +import { resetProjectsReducer } from '../projects/redux/actions'; -const Landing = memo(({ resetSelectionState, resetTargetState }) => { - const { setSnackBarTitle } = useContext(HeaderContext); - const [loginText, setLoginText] = useState("You're logged in as " + DJANGO_CONTEXT['username']); +const Landing = memo( + ({ resetSelectionState, resetTargetState, resetCurrentCompoundsSettings, resetProjectsReducer }) => { + const { setSnackBarTitle } = useContext(HeaderContext); + const [loginText, setLoginText] = useState("You're logged in as " + DJANGO_CONTEXT['username']); - useEffect(() => { - if (DJANGO_CONTEXT['authenticated'] !== true) { - setLoginText( - <> - {'To view own targets login here: '} - - FedID Login - - - ); - } - }, []); + useEffect(() => { + if (DJANGO_CONTEXT['authenticated'] !== true) { + setLoginText( + <> + {'To view own targets login here: '} + + FedID Login + + + ); + } + }, []); - useEffect(() => { - resetTargetState(); - resetSelectionState(); - setSnackBarTitle(loginText); - resetCurrentCompoundsSettings(true); - }, [resetTargetState, resetSelectionState, setSnackBarTitle, loginText]); + useEffect(() => { + resetTargetState(); + resetSelectionState(); + setSnackBarTitle(loginText); + resetCurrentCompoundsSettings(true); + resetProjectsReducer(); + }, [ + resetTargetState, + resetSelectionState, + setSnackBarTitle, + loginText, + resetCurrentCompoundsSettings, + resetProjectsReducer + ]); - return ( - - - + return ( + + + + + + {/**/} + + - - {/**/} - - - - ); -}); + ); + } +); function mapStateToProps(state) { return {}; @@ -56,7 +67,8 @@ function mapStateToProps(state) { const mapDispatchToProps = { resetSelectionState: selectionActions.resetSelectionState, resetTargetState: apiActions.resetTargetState, - resetCurrentCompoundsSettings + resetCurrentCompoundsSettings, + resetProjectsReducer }; export default connect(mapStateToProps, mapDispatchToProps)(Landing); diff --git a/js/components/preview/Preview.js b/js/components/preview/Preview.js index d3d2dbc76..a6451ed1d 100644 --- a/js/components/preview/Preview.js +++ b/js/components/preview/Preview.js @@ -21,6 +21,7 @@ import { ProjectHistory } from './projectHistory'; import { ProjectDetailDrawer } from '../projects/projectDetailDrawer'; import { removeAllNglComponents } from '../../reducers/ngl/actions'; import { resetCurrentCompoundsSettings } from './compounds/redux/actions'; +import { resetProjectsReducer } from '../projects/redux/actions'; //import HotspotList from '../hotspot/hotspotList'; const hitNavigatorWidth = 504; @@ -93,7 +94,7 @@ const Preview = memo(({ isStateLoaded, headerHeight }) => { return () => { dispatch(removeAllNglComponents()); dispatch(resetCurrentCompoundsSettings(true)); - console.log(' Unmount Preview '); + dispatch(resetProjectsReducer()); }; }, [dispatch]); diff --git a/js/components/preview/projectHistory/index.js b/js/components/preview/projectHistory/index.js index 0ebeac034..8e67c1d9b 100644 --- a/js/components/preview/projectHistory/index.js +++ b/js/components/preview/projectHistory/index.js @@ -3,7 +3,7 @@ import { Panel } from '../../common/Surfaces/Panel'; import { ComputeSize } from '../../../utils/computeSize'; import { Grid, IconButton, Typography, Table, TableBody, TableRow, TableCell, TableHead } from '@material-ui/core'; import { templateExtend, TemplateName, Orientation, Gitgraph } from '@gitgraph/react'; -import { Delete, Share, MoreVert } from '@material-ui/icons'; +import { Delete, Share, MergeType } from '@material-ui/icons'; import moment from 'moment'; import { useSelector } from 'react-redux'; @@ -79,7 +79,7 @@ export const ProjectHistory = memo(({ height, setHeight, showFullHistory }) => { ref={panelRef} headerActions={[ - + ]} > diff --git a/js/components/projects/index.js b/js/components/projects/index.js index 7be2688ae..4ba5c20b1 100644 --- a/js/components/projects/index.js +++ b/js/components/projects/index.js @@ -59,36 +59,36 @@ export const Projects = memo(({ history }) => { 'green', 'blue' ]), - createData('Cheapest molecules', 'ATAD', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 2, [ + createData('Cheapest molecules', 'EPB41L3A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 2, [ 'red', 'green', 'blue' ]), - createData('Apoximation of electon', 'NUDT4A', moment().format('LLL'), 'james.smith@diamond.co.uk', 3, [ + createData('Apoximation of electon', 'EPB41L3A', moment().format('LLL'), 'james.smith@diamond.co.uk', 3, [ 'red', 'green', 'blue' ]), - createData('My fake project', 'XX02KALRNA', moment().format('LLL'), 'jane.jackson@gmail.com', 4, []), - createData('Unique science', 'CAMK1DA', moment().format('LLL'), 'jane.jackson@gmail.com', 5, []), - createData('Cheapest molecules', 'ATAD', moment().format('LLL'), 'jane.jackson@gmail.com', 7, []), - createData('Apoximation of electon', 'NUDT4A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 8, []), + createData('My fake project', 'EPB41L3A', moment().format('LLL'), 'jane.jackson@gmail.com', 4, []), + createData('Unique science', 'EPB41L3A', moment().format('LLL'), 'jane.jackson@gmail.com', 5, []), + createData('Cheapest molecules', 'EPB41L3A', moment().format('LLL'), 'jane.jackson@gmail.com', 7, []), + createData('Apoximation of electon', 'EPB41L3A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 8, []), createData('Best coumpounds ever', 'NUDT5A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 6, []), - createData('Unique science', 'CAMK1DA', moment().format('LLL'), 'tibor.postek@m2ms.sk', 10, []), - createData('My fake project', 'XX02KALRNA', moment().format('LLL'), 'tibor.postek@m2ms.sk', 9, []), - createData('Best coumpounds ever', 'NUDT5A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 11, []), - createData('Apoximation of electon', 'NUDT4A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 18, []), - createData('Cheapest molecules', 'ATAD', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 12, []), - createData('My fake project', 'XX02KALRNA', moment().format('LLL'), 'jane.jackson@gmail.com', 14, []), - createData('Unique science', 'CAMK1DA', moment().format('LLL'), 'jane.jackson@gmail.com', 15, []), - createData('Apoximation of electon', 'NUDT4A', moment().format('LLL'), 'james.smith@diamond.co.uk', 13, []), - createData('Cheapest molecules', 'ATAD', moment().format('LLL'), 'jane.jackson@gmail.com', 17, []), + createData('Unique science', 'EPB41L3A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 10, []), + createData('My fake project', 'EPB41L3A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 9, []), + createData('Best coumpounds ever', 'EPB41L3A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 11, []), + createData('Apoximation of electon', 'EPB41L3A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 18, []), + createData('Cheapest molecules', 'EPB41L3A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 12, []), + createData('My fake project', 'EPB41L3A', moment().format('LLL'), 'jane.jackson@gmail.com', 14, []), + createData('Unique science', 'EPB41L3A', moment().format('LLL'), 'jane.jackson@gmail.com', 15, []), + createData('Apoximation of electon', 'EPB41L3A', moment().format('LLL'), 'james.smith@diamond.co.uk', 13, []), + createData('Cheapest molecules', 'EPB41L3A', moment().format('LLL'), 'jane.jackson@gmail.com', 17, []), createData('Best coumpounds ever', 'NUDT5A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 16, []), - createData('Unique science', 'CAMK1DA', moment().format('LLL'), 'tibor.postek@m2ms.sk', 20, []), - createData('My fake project', 'XX02KALRNA', moment().format('LLL'), 'tibor.postek@m2ms.sk', 19, []), + createData('Unique science', 'EPB41L3A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 20, []), + createData('My fake project', 'EPB41L3A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 19, []), createData('Best coumpounds ever', 'NUDT5A', moment().format('LLL'), 'tibor.postek@m2ms.sk', 21, []), - createData('Apoximation of electon', 'NUDT4A', moment().format('LLL'), 'james.smith@diamond.co.uk', 23, []), - createData('Cheapest molecules', 'ATAD', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 22, []), + createData('Apoximation of electon', 'EPB41L3A', moment().format('LLL'), 'james.smith@diamond.co.uk', 23, []), + createData('Cheapest molecules', 'EPB41L3A', moment().format('LLL'), 'pavol.brunclik@m2ms.sk', 22, []), createData('Unique science', 'CAMK1DA', moment().format('LLL'), 'jane.jackson@gmail.com', 25, []), createData('My fake project', 'XX02KALRNA', moment().format('LLL'), 'jane.jackson@gmail.com', 24, []), createData('Cheapest molecules', 'ATAD', moment().format('LLL'), 'jane.jackson@gmail.com', 27, []), diff --git a/js/components/projects/redux/actions.js b/js/components/projects/redux/actions.js index a59e03fa5..defbf5494 100644 --- a/js/components/projects/redux/actions.js +++ b/js/components/projects/redux/actions.js @@ -27,3 +27,5 @@ export const setProjectSnapshot = (snapshot, snapshotDetail) => ({ type: constants.SET_SNAPSHOT, payload: { snapshot, snapshotDetail } }); + +export const resetProjectsReducer = () => ({ type: constants.RESET_PROJECTS_REDUCER }); diff --git a/js/components/projects/redux/constants.js b/js/components/projects/redux/constants.js index 5beb7f610..4c3576915 100644 --- a/js/components/projects/redux/constants.js +++ b/js/components/projects/redux/constants.js @@ -6,7 +6,9 @@ export const constants = { RESET_CURRENT_PROJECT_STATE: prefix + 'RESET_CURRENT_PROJECT_STATE', SET_PROJECT_MODAL_OPEN: prefix + 'SET_PROJECT_MODAL_OPEN', SET_PROJECT_MODAL_IS_LOADING: prefix + 'SET_PROJECT_MODAL_IS_LOADING', - SET_SNAPSHOT: prefix + 'SET_SNAPSHOT' + SET_SNAPSHOT: prefix + 'SET_SNAPSHOT', + + RESET_PROJECTS_REDUCER: prefix + 'RESET_PROJECTS_REDUCER' }; export const ProjectCreationType = { diff --git a/js/components/projects/redux/reducer.js b/js/components/projects/redux/reducer.js index aaea8aa6a..c1a33157a 100644 --- a/js/components/projects/redux/reducer.js +++ b/js/components/projects/redux/reducer.js @@ -51,6 +51,9 @@ export const projectReducers = (state = INITIAL_STATE, action = {}) => { snapshotDetail: action.payload.snapshotDetail }); + case constants.RESET_PROJECTS_REDUCER: + return Object.assign({}, INITIAL_STATE); + default: return state; }