6 changed files with 132 additions and 54 deletions
-
48src/pages/Measure.tsx
-
9src/pages/MeasureSave.tsx
-
8src/services/apiTypes.ts
-
45src/store/features/baseData.ts
-
18src/utils/bridge.ts
-
44src/utils/constant.ts
@ -1,26 +1,51 @@ |
|||||
import { createSelector, createSlice } from "@reduxjs/toolkit"; |
|
||||
import { KTJOrg } from "../../services/apiTypes"; |
|
||||
import { labeledKtjOrgs } from "../../utils/helper"; |
|
||||
|
import { createAsyncThunk, createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit'; |
||||
|
import { KTJOrg, RailType } from '../../services/apiTypes'; |
||||
|
import { labeledKtjOrgs } from '../../utils/helper'; |
||||
|
|
||||
import { ktjOrgs } from "../../utils/constant"; |
|
||||
|
import { ktjOrgs } from '../../utils/constant'; |
||||
|
import Bridge from '../../utils/bridge'; |
||||
|
|
||||
interface BaseDataState { |
interface BaseDataState { |
||||
ktjOrgs: KTJOrg[]; |
ktjOrgs: KTJOrg[]; |
||||
|
railTypes: RailType[]; |
||||
} |
} |
||||
|
|
||||
const initialState: BaseDataState = { |
const initialState: BaseDataState = { |
||||
ktjOrgs: ktjOrgs as KTJOrg[], |
ktjOrgs: ktjOrgs as KTJOrg[], |
||||
} |
|
||||
|
railTypes: [], |
||||
|
}; |
||||
|
|
||||
|
export const fetchRailTypes = createAsyncThunk('base/fetchRailTypes', async (_, thunkAPI) => { |
||||
|
const res = await Bridge.getBasicTrackList(); |
||||
|
return res.success ? res.data : null; |
||||
|
}); |
||||
|
|
||||
export const baseDataSlice = createSlice({ |
export const baseDataSlice = createSlice({ |
||||
name: 'baseData', |
name: 'baseData', |
||||
initialState, |
initialState, |
||||
reducers: {} |
|
||||
|
reducers: { |
||||
|
updateRailTypes: (state, action: PayloadAction<RailType[]>) => { |
||||
|
state.railTypes = action.payload; |
||||
|
}, |
||||
|
updateRailPoints: (state, action: PayloadAction<RailType>) => { |
||||
|
const r = state.railTypes.find((r) => r.code === action.payload.code); |
||||
|
if (r) { |
||||
|
r.points = action.payload.points; |
||||
|
r.calPoints = action.payload.calPoints; |
||||
|
} |
||||
|
}, |
||||
|
}, |
||||
|
extraReducers: (builder) => { |
||||
|
builder.addCase(fetchRailTypes.fulfilled, (state, action) => { |
||||
|
state.railTypes = action.payload || []; |
||||
|
}); |
||||
|
}, |
||||
}); |
}); |
||||
|
|
||||
|
export const { updateRailPoints } = baseDataSlice.actions; |
||||
export default baseDataSlice.reducer; |
export default baseDataSlice.reducer; |
||||
|
|
||||
export const selectKtjOrgs = (state: BaseDataState) => state.ktjOrgs |
|
||||
export const selectLabeledKtjOrgs = createSelector(selectKtjOrgs,(orgs) => { |
|
||||
return labeledKtjOrgs(orgs) |
|
||||
}) |
|
||||
|
export const selectKtjOrgs = (state: BaseDataState) => state.ktjOrgs; |
||||
|
export const selectLabeledKtjOrgs = createSelector(selectKtjOrgs, (orgs) => { |
||||
|
return labeledKtjOrgs(orgs); |
||||
|
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue