Курсовая: Готова и сдана

This commit is contained in:
Amon 2023-12-30 14:15:56 +04:00
parent 40ca46846e
commit cf8e779058
4 changed files with 10 additions and 3 deletions

View File

@ -112,7 +112,7 @@ interface ServerService {
): User ): User
companion object { companion object {
private const val BASE_URL = "http://192.168.0.103:8000/" private const val BASE_URL = "http://192.168.43.115:8000/"
private var _token: String = "" private var _token: String = ""

View File

@ -161,8 +161,7 @@ private fun Post(viewModel: PostsViewModel, navController: NavHostController, po
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxHeight(0.3f) .heightIn(min=250.dp, max = 300.dp)
.heightIn(max = 250.dp)
.fillMaxWidth() .fillMaxWidth()
.background(Color.White) .background(Color.White)
.clickable { .clickable {

View File

@ -203,6 +203,12 @@ fun Post(viewModel: TopPostsViewModel, navController: NavHostController, post: P
val likes = remember { mutableIntStateOf(post.likes) } val likes = remember { mutableIntStateOf(post.likes) }
val isLiked = remember { mutableStateOf(false) } val isLiked = remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
viewModel.getLikes(post.id!!).collect {
likes.intValue = it
}
}
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
viewModel.isLiked(sharedPref, post.id!!).collect { viewModel.isLiked(sharedPref, post.id!!).collect {
isLiked.value = it isLiked.value = it

View File

@ -35,6 +35,8 @@ class TopPostsViewModel @Inject constructor(
} }
} }
fun getLikes(postId: Int) = likeRepository.countByPost(postId)
fun likePost(sharedPref: PreferencesManager, postId: Int) { fun likePost(sharedPref: PreferencesManager, postId: Int) {
val userId = sharedPref.getData("userId", "-1").toInt() val userId = sharedPref.getData("userId", "-1").toInt()