Commit 897d2eda by Tonk

get connected device from firebase, add modal, ...update

parent 5d90726b
......@@ -12,6 +12,7 @@ export const GET_EXISTED_MCBLINKS_DATA = 'GET_EXISTED_MCBLINKS_DATA';
export const GET_EXISTED_SUBBREAKERS_DATA = 'GET_EXISTED_SUBBREAKERS_DATA';
export const GET_SELECTED_TIMER_DATA = 'GET_SELECTED_TIMER_DATA';
export const SET_EDIT_MODAL_VISIBLE = 'SET_EDIT_MODAL_VISIBLE';
export const GET_EXISTED_CONNECTED_DEVICE = 'GET_EXISTED_CONNECTED_DEVICE';
export const getTimersAction = allTimers => ({
type: GET_TIMERS,
......@@ -28,6 +29,11 @@ export const getExistedSubBreakersDataAction = existedSubBreakersData => ({
existedSubBreakersData,
});
export const getExistedConnectedDeviceAction = existedConnectedDevice => ({
type: GET_EXISTED_CONNECTED_DEVICE,
existedConnectedDevice,
});
export const getSelectedTimerDataAction = selectedTimerData => ({
type: GET_SELECTED_TIMER_DATA,
selectedTimerData,
......@@ -59,6 +65,7 @@ export const getTimers = () => async (dispatch, getState) => {
let subBreakersTimers = [];
let existedMcbLinks = [];
let existedSubBreakers = [];
let existedConnectedDevice = [];
//main device section
/*-------------------------------------*/
......@@ -126,6 +133,31 @@ export const getTimers = () => async (dispatch, getState) => {
})
)
);
await Promise.all(
selectedDeviceSubBreakersDetails.docs.map(async subBreaker => {
if (subBreaker.exists) {
//Electronic device section
/*-------------------------------------*/
const connectedDevices = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id)
.collection('subBreakers')
.doc(subBreaker.id)
.collection('electronicDevices')
.get();
existedConnectedDevice.push(
connectedDevices.docs.map(connectedDevice =>
Object.assign(connectedDevice.data(), {
connectedDeviceId: connectedDevice.id,
})
)
);
}
})
);
await Promise.all(
selectedDeviceSubBreakersDetails.docs.map(async subBreaker => {
......@@ -163,6 +195,7 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(getExistedMcbLinksDataAction(existedMcbLinks));
dispatch(getExistedSubBreakersDataAction(existedSubBreakers));
dispatch(getExistedConnectedDeviceAction(existedConnectedDevice));
allTimersData = [...mainDeviceTimers, ...subBreakersTimers];
dispatch(getTimersAction(allTimersData));
......
......@@ -6,12 +6,14 @@ import {
GET_EXISTED_SUBBREAKERS_DATA,
GET_SELECTED_TIMER_DATA,
SET_EDIT_MODAL_VISIBLE,
GET_EXISTED_CONNECTED_DEVICE,
} from '../actions/timersAction';
const initState = {
allTimers: [],
existedMcbLinksData: [],
existedSubBreakersData: [],
existedConnectedDevice: [],
selectedTimerData: null,
isEditVisible: false,
isLoading: true,
......@@ -34,7 +36,8 @@ const timersReducer = (state = initState, action) => {
return { ...state, isLoading: action.isLoading };
case GET_TIMERS_ERROR:
return { ...state, error: action.error };
case GET_EXISTED_CONNECTED_DEVICE:
return { ...state, existedConnectedDevice: action.existedConnectedDevice };
default:
return state;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment