-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
617 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import counterReducer from '../features/counter/counterSlice'; | ||
import courseAllocationReducer from '../features/CourseAllocation/courseAllocationSlice'; | ||
|
||
export default configureStore({ | ||
reducer: { | ||
counter: counterReducer, | ||
courseAllocation: courseAllocationReducer, | ||
}, | ||
}); |
45 changes: 22 additions & 23 deletions
45
client/src/features/CourseAllocation/CourseAllocationSlice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const counterSlice = createSlice({ | ||
name: 'counter', | ||
|
||
export const courseAllocationSlice = createSlice({ | ||
name: 'courseAllocation', | ||
initialState: { | ||
value: 0, | ||
allData: null, | ||
isLoading: false | ||
}, | ||
reducers: { | ||
increment: state => { | ||
// Redux Toolkit allows us to write "mutating" logic in reducers. It | ||
// doesn't actually mutate the state because it uses the Immer library, | ||
// which detects changes to a "draft state" and produces a brand new | ||
// immutable state based off those changes | ||
state.value += 1; | ||
}, | ||
decrement: state => { | ||
state.value -= 1; | ||
}, | ||
incrementByAmount: (state, action) => { | ||
state.value += action.payload; | ||
getCourseAllocationData: (state, action) => { | ||
console.log('payload ', action.payload); | ||
state.allData = action.payload; | ||
state.isLoading = false; | ||
}, | ||
|
||
setDataLoading: state => { | ||
// state = {...state}; | ||
state.isLoading = true; | ||
} | ||
}, | ||
}); | ||
|
||
export const { increment, decrement, incrementByAmount } = counterSlice.actions; | ||
export const { setDataLoading, getCourseAllocationData } = courseAllocationSlice.actions; | ||
|
||
// The function below is called a thunk and allows us to perform async logic. It | ||
// can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This | ||
// will call the thunk with the `dispatch` function as the first argument. Async | ||
// code can then be executed and other actions can be dispatched | ||
export const incrementAsync = amount => dispatch => { | ||
setTimeout(() => { | ||
dispatch(incrementByAmount(amount)); | ||
}, 1000); | ||
}; | ||
// export const incrementAsync = amount => dispatch => { | ||
// setTimeout(() => { | ||
// dispatch(incrementByAmount(amount)); | ||
// }, 1000); | ||
// }; | ||
|
||
// The function below is called a selector and allows us to select a value from | ||
// the state. Selectors can also be defined inline where they're used instead of | ||
// in the slice file. For example: `useSelector((state) => state.counter.value)` | ||
export const selectCount = state => state.counter.value; | ||
export const selectCourseAllocation = state => state.courseAllocation; | ||
|
||
export default counterSlice.reducer; | ||
export default courseAllocationSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
client/src/features/CourseAllocation/courseAllocationActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import axios from 'axios'; | ||
import { setDataLoading, getCourseAllocationData } from './courseAllocationSlice'; | ||
|
||
// get / read | ||
export const fetchCourseAllocationData = () => dispatch => { | ||
dispatch(setDataLoading()) | ||
axios | ||
.get('http://localhost:8000/api/course-allocation/') | ||
.then(res => { | ||
dispatch(getCourseAllocationData(res.data.data)); | ||
console.log('cadata ', res); | ||
}) | ||
.catch(err => console.log('err ', err.response)); | ||
}; | ||
|
||
// // add / create | ||
// export const newUser = body => dispatch => { | ||
// dispatch(addUser(body)); | ||
// }; | ||
|
||
// // remove / delete | ||
// export const removeUser = id => dispatch => { | ||
// dispatch(deleteUser(id)); | ||
// }; | ||
|
||
// // update | ||
// export const modifyUser = body => dispatch => { | ||
// dispatch(updateUser(body)); | ||
// }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.