Skip to content

Commit

Permalink
#2 reset project reducer after exit from project or target
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 10, 2020
1 parent b8ef6c7 commit 29becee
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 56 deletions.
78 changes: 45 additions & 33 deletions js/components/landing/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,63 @@ 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: '}
<Link href="/accounts/login" color="inherit" variant="subtitle2">
FedID Login
</Link>
</>
);
}
}, []);
useEffect(() => {
if (DJANGO_CONTEXT['authenticated'] !== true) {
setLoginText(
<>
{'To view own targets login here: '}
<Link href="/accounts/login" color="inherit" variant="subtitle2">
FedID Login
</Link>
</>
);
}
}, []);

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 (
<Grid container spacing={2}>
<Grid item xs={4}>
<TargetList key="TARGLIST" />
return (
<Grid container spacing={2}>
<Grid item xs={4}>
<TargetList key="TARGLIST" />
</Grid>
<Grid item xs={8}>
{/*<SessionList />*/}
<Projects />
</Grid>
</Grid>
<Grid item xs={8}>
{/*<SessionList />*/}
<Projects />
</Grid>
</Grid>
);
});
);
}
);

function mapStateToProps(state) {
return {};
}
const mapDispatchToProps = {
resetSelectionState: selectionActions.resetSelectionState,
resetTargetState: apiActions.resetTargetState,
resetCurrentCompoundsSettings
resetCurrentCompoundsSettings,
resetProjectsReducer
};

export default connect(mapStateToProps, mapDispatchToProps)(Landing);
3 changes: 2 additions & 1 deletion js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +94,7 @@ const Preview = memo(({ isStateLoaded, headerHeight }) => {
return () => {
dispatch(removeAllNglComponents());
dispatch(resetCurrentCompoundsSettings(true));
console.log(' Unmount Preview ');
dispatch(resetProjectsReducer());
};
}, [dispatch]);

Expand Down
4 changes: 2 additions & 2 deletions js/components/preview/projectHistory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -79,7 +79,7 @@ export const ProjectHistory = memo(({ height, setHeight, showFullHistory }) => {
ref={panelRef}
headerActions={[
<IconButton color="inherit" onClick={showFullHistory}>
<MoreVert />
<MergeType />
</IconButton>
]}
>
Expand Down
38 changes: 19 additions & 19 deletions js/components/projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, []),
Expand Down
2 changes: 2 additions & 0 deletions js/components/projects/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export const setProjectSnapshot = (snapshot, snapshotDetail) => ({
type: constants.SET_SNAPSHOT,
payload: { snapshot, snapshotDetail }
});

export const resetProjectsReducer = () => ({ type: constants.RESET_PROJECTS_REDUCER });
4 changes: 3 additions & 1 deletion js/components/projects/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 3 additions & 0 deletions js/components/projects/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 29becee

Please sign in to comment.