Commit 5edecc5
committed
feat: Implement MainViewModel and UiState for user data display
This commit introduces the `MainViewModel` to manage user data fetching and a `UiState` sealed class to represent the different states of the UI. It also adds Koin dependency injection for the `MainViewModel`.
Changes:
- Created `MainViewModel` to manage the user data fetching and UI state.
- It fetches users from the `UserRepository` and updates the `UiState`.
- It exposes a `uiState` as a `StateFlow` to be observed by the UI.
- It contains the `fetchUsers()` function that calls `userRepository.getUsers()`
- Created `UiState` to represent the loading, success, and error states of the UI.
- `UiState.Loading`: Represents the loading state.
- `UiState.Success`: Represents the success state with a list of users.
- `UiState.Error`: Represents the error state with an error message.
- Added `viewModelOf(::MainViewModel)` in `AppModule` to enable Koin dependency injection for `MainViewModel`.1 parent c961c0f commit 5edecc5
3 files changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments