-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding admin / mod view votes. (#1331)
* Starting to work on admin_view_votes, needs API added yet. * Finished up adding admin view votes. * Fix package name. * Upping lemmy-api version. * Adding a moderation subfield to post and comment action dropdowns. * Adding feature flag check. * Addressing PR comments. - Moving padding up to Box. - Using alternate feature flag method.
- Loading branch information
1 parent
35d4132
commit 42d37e8
Showing
21 changed files
with
776 additions
and
81 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
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
86 changes: 86 additions & 0 deletions
86
app/src/main/java/com/jerboa/model/CommentLikesViewModel.kt
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,86 @@ | ||
package com.jerboa.model | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableLongStateOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.viewModelScope | ||
import androidx.lifecycle.viewmodel.CreationExtras | ||
import com.jerboa.api.API | ||
import com.jerboa.api.ApiState | ||
import com.jerboa.api.toApiState | ||
import com.jerboa.appendData | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.CommentId | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommentLikes | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.ListCommentLikesResponse | ||
import kotlinx.coroutines.launch | ||
|
||
class CommentLikesViewModel(val id: CommentId) : ViewModel() { | ||
var likesRes: ApiState<ListCommentLikesResponse> by mutableStateOf(ApiState.Empty) | ||
private set | ||
private var page by mutableLongStateOf(1) | ||
|
||
init { | ||
getLikes() | ||
} | ||
|
||
fun resetPage() { | ||
page = 1 | ||
} | ||
|
||
fun getLikes(state: ApiState<ListCommentLikesResponse> = ApiState.Loading) { | ||
viewModelScope.launch { | ||
likesRes = state | ||
likesRes = API.getInstance().listCommentLikes(getForm()).toApiState() | ||
} | ||
} | ||
|
||
private fun getForm(): ListCommentLikes { | ||
return ListCommentLikes( | ||
comment_id = id, | ||
page = page, | ||
) | ||
} | ||
|
||
fun appendLikes() { | ||
viewModelScope.launch { | ||
val oldRes = likesRes | ||
when (oldRes) { | ||
is ApiState.Success -> likesRes = ApiState.Appending(oldRes.data) | ||
else -> return@launch | ||
} | ||
|
||
page += 1 | ||
val newRes = API.getInstance().listCommentLikes(getForm()).toApiState() | ||
|
||
likesRes = | ||
when (newRes) { | ||
is ApiState.Success -> { | ||
val appended = appendData(oldRes.data.comment_likes, newRes.data.comment_likes) | ||
|
||
ApiState.Success(oldRes.data.copy(comment_likes = appended)) | ||
} | ||
|
||
else -> { | ||
oldRes | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
class Factory( | ||
private val id: CommentId, | ||
) : ViewModelProvider.Factory { | ||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel> create( | ||
modelClass: Class<T>, | ||
extras: CreationExtras, | ||
): T { | ||
return CommentLikesViewModel(id) as T | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.jerboa.model | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableLongStateOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.viewModelScope | ||
import androidx.lifecycle.viewmodel.CreationExtras | ||
import com.jerboa.api.API | ||
import com.jerboa.api.ApiState | ||
import com.jerboa.api.toApiState | ||
import com.jerboa.appendData | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPostLikes | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.ListPostLikesResponse | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.PostId | ||
import kotlinx.coroutines.launch | ||
|
||
class PostLikesViewModel(val id: PostId) : ViewModel() { | ||
var likesRes: ApiState<ListPostLikesResponse> by mutableStateOf(ApiState.Empty) | ||
private set | ||
private var page by mutableLongStateOf(1) | ||
|
||
init { | ||
getLikes() | ||
} | ||
|
||
fun resetPage() { | ||
page = 1 | ||
} | ||
|
||
fun getLikes(state: ApiState<ListPostLikesResponse> = ApiState.Loading) { | ||
viewModelScope.launch { | ||
likesRes = state | ||
likesRes = API.getInstance().listPostLikes(getForm()).toApiState() | ||
} | ||
} | ||
|
||
private fun getForm(): ListPostLikes { | ||
return ListPostLikes( | ||
post_id = id, | ||
page = page, | ||
) | ||
} | ||
|
||
fun appendLikes() { | ||
viewModelScope.launch { | ||
val oldRes = likesRes | ||
when (oldRes) { | ||
is ApiState.Success -> likesRes = ApiState.Appending(oldRes.data) | ||
else -> return@launch | ||
} | ||
|
||
page += 1 | ||
val newRes = API.getInstance().listPostLikes(getForm()).toApiState() | ||
|
||
likesRes = | ||
when (newRes) { | ||
is ApiState.Success -> { | ||
val appended = appendData(oldRes.data.post_likes, newRes.data.post_likes) | ||
|
||
ApiState.Success(oldRes.data.copy(post_likes = appended)) | ||
} | ||
|
||
else -> { | ||
oldRes | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
class Factory( | ||
private val id: PostId, | ||
) : ViewModelProvider.Factory { | ||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel> create( | ||
modelClass: Class<T>, | ||
extras: CreationExtras, | ||
): T { | ||
return PostLikesViewModel(id) as T | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.