Skip to content

Commit

Permalink
refactor: rfv state CU-6gpt8q
Browse files Browse the repository at this point in the history
Replaced Just of list for an empty StrMap.
  • Loading branch information
mbetancurt committed Jul 9, 2020
1 parent fb99886 commit b66e731
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/Ades.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import VerificationScreen from './VerificationScreen';
import {API} from './consts';
import BottomArea from './layout/BottomArea';
import NotificationCenter from './NotificationCenter';
import {Information, OperationGoneRogue} from './entities/Notification';
import {OperationGoneRogue} from './entities/Notification';

/*function alertIsImportant(alertUtmMessage) {
return (
Expand Down Expand Up @@ -238,7 +238,7 @@ function Ades() {
return () => {
clearTimeout(timeoutDebugNotification.current);
};
}, [state.debug]);
}, [state.debug]); // eslint-disable-line react-hooks/exhaustive-deps

if (isLoggedIn && role === 'admin') {
/* Operator pages */
Expand Down
5 changes: 2 additions & 3 deletions src/NotificationCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import styles from './css/notification.module.css';
import './css/animate.css';
import {fM} from './libs/SaferSanctuary';
import useSound from 'use-sound';
import {Information, OperationGoneRogue} from './entities/Notification';
import * as classnames from 'classnames';

function NotificationCenter() {
Expand All @@ -28,7 +27,7 @@ function NotificationCenter() {
} else {
stop();
}
}, [sound, play]);
}, [sound, play, stop]);

useEffect(() => {
scroll.scrollTo(scrolled, {smooth: true, containerId: 'notifications', ignoreCancelEvents: true});
Expand All @@ -48,7 +47,7 @@ function NotificationCenter() {
}
});
if (!hasAnySound) setSound('');
}, [state.updated]);
}, [state.updated]); // eslint-disable-line react-hooks/exhaustive-deps

return (
<>
Expand Down
3 changes: 0 additions & 3 deletions src/dashboard/home/HomeScreen.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from 'react';
import styles from './home.module.css';
import OpsEvolutionChart from './OpsEvolutionChart';
import DronesChart from './DronesChart';
import UserRow from './UserRow';
import useAdesState from '../../state/AdesState';
import S from 'sanctuary';
import {maybeValues} from '../../libs/SaferSanctuary';
Expand Down
10 changes: 5 additions & 5 deletions src/entities/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class Notification {
}

get header() {
if (!this._header) throw ('Notification: Attempted to get header of default notification. Don\'t use the notification class, only its inherited');
if (!this._header) throw (new Error('Notification: Attempted to get header of default notification. Don\'t use the notification class, only its inherited'));
return this._header;
}

get body() {
if (!this._body) throw ('Notification: Attempted to get body of default notification. Don\'t use the notification class, only its inherited');
if (!this._body) throw (new Error('Notification: Attempted to get body of default notification. Don\'t use the notification class, only its inherited'));
return this._body;
}

Expand Down Expand Up @@ -111,15 +111,15 @@ class UTMMessage extends Notification {
}

get uss_name() {
throw('uss_name is unused');
throw(new Error('uss_name is unused'));
}

get discovery_reference() {
throw('discovery_reference is unused');
throw(new Error('discovery_reference is unused'));
}

get message_type() {
throw('message_type is unused');
throw(new Error('message_type is unused'));
}

get prev_message_id() {
Expand Down
46 changes: 29 additions & 17 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import OperationEditMarker from './elements/OperationEditMarker';

/* Hooks */
import useOperationFilter from './hooks/useOperationFilter';
import useRfvLogic from './hooks/useRfvLogic';
import useAdesState from '../state/AdesState';
import useEditorLogic from './hooks/useEditorLogic';
import useSimulatorLogic from './hooks/useSimulatorLogic';
Expand All @@ -38,12 +39,10 @@ import {initializeLeaflet} from './MapAuxs';
import RightArea from '../layout/RightArea';

import Polyline from './elements/Polyline';
import {fM, mapValues, maybeValues} from '../libs/SaferSanctuary';
import {fM, maybeValues} from '../libs/SaferSanctuary';
import SelectedDrone from './viewer/SelectedDrone';
import {Button, Dialog, Intent} from '@blueprintjs/core';



/* Main function */
function Map({ mode }) {
const map = useRef(null);
Expand Down Expand Up @@ -77,7 +76,8 @@ function Map({ mode }) {


/* Viewer state */
const [ops, opsFiltered, id, filtersSelected, setFiltersSelected, , idsShowing, setIdsShowing, rfvs, setRfvsShowing] = useOperationFilter();
const [rfvs, setRfvs] = useRfvLogic();
const [ops, opsFiltered, id, filtersSelected, setFiltersSelected, , idsShowing, setIdsShowing] = useOperationFilter();
const [currentSelectedOperation, setSelectedOperation] = useState(S.Nothing);
const [currentSelectedDrone, setSelectedDrone] = useState(S.Nothing);

Expand Down Expand Up @@ -215,18 +215,30 @@ function Map({ mode }) {
/>;
});
})}
{mapValues(state.rfv.list)(() => {})((rfv) => {
if (rfvs.indexOf(rfv.id) !== -1) {
return (
<RestrictedFlightVolume
map={map.current}
key={rfv.comments}
latlngs={rfv.geography.coordinates}
name={rfv.comments}
/>
);
}
})}
{
S.map
((rfv) => {
if (rfvs.indexOf(rfv.id) !== -1) {
/* Rfv is selected to be shown */
return (
<RestrictedFlightVolume
map={map.current}
key={rfv.comments}
latlngs={rfv.geography.coordinates}
name={rfv.comments}
/>
);
} else {
return null;
}
})
(S.values(state.rfv.list))
}







{/* Operation creation */}
Expand Down Expand Up @@ -320,7 +332,7 @@ function Map({ mode }) {
idsSelected={idsShowing}
setIdsSelected={setIdsShowing}
rfvs={rfvs}
setRfvsShowing={setRfvsShowing}
setRfvsShowing={setRfvs}
operations={ops}
disabled={id != null}
/>
Expand Down
9 changes: 6 additions & 3 deletions src/map/actions/Layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import S from 'sanctuary';
import PropTypes from 'prop-types';
import {useTranslation} from 'react-i18next';
import RightAreaButton from '../RightAreaButton';
import {fM, mapValues} from '../../libs/SaferSanctuary';
import {fM} from '../../libs/SaferSanctuary';
import useAdesState from '../../state/AdesState';

const StateFilters = ({selectedFilters, setSelectedFilters}) => {
Expand Down Expand Up @@ -107,7 +107,8 @@ const RfvsFilters = ({rfvs, setRfvs}) => {
<div className='rightAreaButtonTextsSeparator'>
{t('map.filter.rfvs')}
</div>
{mapValues(state.rfv.list)(() => {})((rfv, index) => {
{S.map
((rfv, index) => {
const isSelected = rfvs.indexOf(rfv.id) !== -1;
return (
<div
Expand All @@ -133,7 +134,9 @@ const RfvsFilters = ({rfvs, setRfvs}) => {

</div>
);
})}
})
(S.values(state.rfv.list))
}
</>
);
};
Expand Down
9 changes: 2 additions & 7 deletions src/map/hooks/useOperationFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useEffect, useState} from 'react';

/* Libraries */
import S from 'sanctuary';
import {fM, maybeKeys} from '../../libs/SaferSanctuary';
import {fM} from '../../libs/SaferSanctuary';
import {useParams} from 'react-router-dom';

/* Internal state */
Expand All @@ -27,7 +27,6 @@ const useOperationFilter = () => {
const [adesState, actions] = useAdesState();
const {id} = useParams();
const [ids, setIds] = useState(adesState.map.ids);
const [rfvs, setRfvsShowing] = useState(maybeKeys(adesState.rfv.list));
const [allOperations, setOperations] = useState(extractOperationsFromState(adesState));
const [filteredOperations, setFilteredOperations] = useState([]);
const { t, } = useTranslation();
Expand Down Expand Up @@ -98,10 +97,6 @@ const useOperationFilter = () => {
setOperations(extractOperationsFromState(adesState));
}, [adesState.operations.updated]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
setRfvsShowing(maybeKeys(adesState.rfv.list));
}, [adesState.rfv.updated]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect( () => {
//console.log("filteredOperations", filteredOperations);
}, [filteredOperations]); // eslint-disable-line react-hooks/exhaustive-deps
Expand All @@ -115,7 +110,7 @@ const useOperationFilter = () => {
setIds: To show
*/

return [allOperations, filteredOperations, id, selectedFilters, setSelectedFilters, states, ids, setIds, rfvs, setRfvsShowing];
return [allOperations, filteredOperations, id, selectedFilters, setSelectedFilters, states, ids, setIds];
};

export {useOperationFilter as default};
18 changes: 18 additions & 0 deletions src/map/hooks/useRfvLogic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {useEffect, useState} from 'react';
import S from 'sanctuary';

/* Internal */
import useAdesState from '../../state/AdesState';

const useRfvLogic = () => {
const [state, ] = useAdesState(state => state.rfv, actions => actions.rfv);
const [shownRfvs, setShownRfvs] = useState(S.keys(state.list));

useEffect(() => {
setShownRfvs(S.keys(state.list));
}, [state.updated]); // eslint-disable-line react-hooks/exhaustive-deps

return [shownRfvs, setShownRfvs];
};

export default useRfvLogic;
6 changes: 3 additions & 3 deletions src/state/AdesState.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const initialState = {
updated: Date.now()
},
rfv: {
list: S.Nothing,
updated: Date.now()
list: {},
updated: 0
},
warning: S.Nothing,
notifications: {
Expand Down Expand Up @@ -223,7 +223,7 @@ function addRFV(store, data) {
}));
const rfvs = S.fromPairs(pairs);
print(store.state, false, 'RFVState', rfvs);
store.setState({rfv: {updated: Date.now(), list: S.Just(rfvs)}});
store.setState({rfv: {updated: Date.now(), list: rfvs}});
}

/* QuickFly */
Expand Down

0 comments on commit b66e731

Please sign in to comment.