-
-
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.
Merge pull request #8 from groupeminaste/fix/pagination-and-post-details
Pagination fixes + post details
- Loading branch information
Showing
28 changed files
with
494 additions
and
99 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
101 changes: 101 additions & 0 deletions
101
android/src/main/java/me/nathanfallet/extopy/features/posts/PostView.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,101 @@ | ||
package me.nathanfallet.extopy.features.posts | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.rickclephas.kmm.viewmodel.coroutineScope | ||
import kotlinx.coroutines.launch | ||
import me.nathanfallet.extopy.R | ||
import me.nathanfallet.extopy.models.users.User | ||
import me.nathanfallet.extopy.ui.components.posts.PostCard | ||
import me.nathanfallet.extopy.viewmodels.posts.PostViewModel | ||
import org.koin.androidx.compose.koinViewModel | ||
import org.koin.core.parameter.parametersOf | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun PostView( | ||
id: String, | ||
viewedBy: User, | ||
navigate: (String) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
|
||
val viewModel = koinViewModel<PostViewModel>( | ||
parameters = { parametersOf(id) } | ||
) | ||
|
||
LaunchedEffect(id) { | ||
viewModel.fetchPost() | ||
} | ||
|
||
val post by viewModel.post.collectAsState() | ||
val posts by viewModel.posts.collectAsState() | ||
|
||
LazyColumn( | ||
modifier | ||
) { | ||
item { | ||
TopAppBar( | ||
title = { | ||
Text(stringResource(R.string.timeline_post_title)) | ||
}, | ||
) | ||
} | ||
item { | ||
Spacer(modifier = Modifier.height(12.dp)) | ||
} | ||
item { | ||
post?.let { | ||
PostCard( | ||
post = it, | ||
navigate = navigate, | ||
onLikeClicked = { post -> | ||
viewModel.viewModelScope.coroutineScope.launch { | ||
viewModel.onLikeClicked(post) | ||
} | ||
}, | ||
onRepostClicked = { post -> | ||
navigate.invoke("timeline/compose?repostOfId=${post.id}") | ||
}, | ||
onReplyClicked = { post -> | ||
navigate.invoke("timeline/compose?repliedToId=${post.id}") | ||
} | ||
) | ||
} | ||
} | ||
items(posts ?: listOf()) { | ||
PostCard( | ||
post = it, | ||
navigate = navigate, | ||
onLikeClicked = { post -> | ||
viewModel.viewModelScope.coroutineScope.launch { | ||
viewModel.onLikeClicked(post) | ||
} | ||
}, | ||
onRepostClicked = { post -> | ||
navigate.invoke("timeline/compose?repostOfId=${post.id}") | ||
}, | ||
onReplyClicked = { post -> | ||
navigate.invoke("timeline/compose?repliedToId=${post.id}") | ||
} | ||
) | ||
viewModel.loadMoreIfNeeded(it.id) | ||
} | ||
item { | ||
Spacer(modifier = Modifier.height(12.dp)) | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// PostView.swift | ||
// Extopy | ||
// | ||
// Created by Nathan Fallet on 14/01/2024. | ||
// Copyright © 2024 orgName. All rights reserved. | ||
// | ||
|
||
import shared | ||
import SwiftUI | ||
import Kingfisher | ||
import KMMViewModelSwiftUI | ||
import KMPNativeCoroutinesAsync | ||
|
||
struct PostView: View { | ||
|
||
@StateViewModel var viewModel: PostViewModel | ||
|
||
let viewedBy: Extopy_commonsUser | ||
|
||
var body: some View { | ||
ZStack { | ||
ScrollView { | ||
LazyVStack(spacing: 8) { | ||
if let post = viewModel.post { | ||
NavigationLink(destination: PostView( | ||
viewModel: KoinApplication.shared.koin.postViewModel(id: post.id), | ||
viewedBy: viewedBy | ||
)) { | ||
PostCard( | ||
post: post, | ||
viewedBy: viewedBy, | ||
onLikeClicked: { post in | ||
Task { | ||
try await asyncFunction(for: viewModel.onLikeClicked(post: post)) | ||
} | ||
}, | ||
onRepostClicked: { _ in }, | ||
onReplyClicked: { _ in } | ||
) | ||
} | ||
} | ||
ForEach(viewModel.posts ?? [], id: \.namespacedId) { post in | ||
NavigationLink(destination: PostView( | ||
viewModel: KoinApplication.shared.koin.postViewModel(id: post.id), | ||
viewedBy: viewedBy | ||
)) { | ||
PostCard( | ||
post: post, | ||
viewedBy: viewedBy, | ||
onLikeClicked: { post in | ||
Task { | ||
try await asyncFunction(for: viewModel.onLikeClicked(post: post)) | ||
} | ||
}, | ||
onRepostClicked: { _ in }, | ||
onReplyClicked: { _ in } | ||
) | ||
.onAppear { | ||
viewModel.loadMoreIfNeeded(postId: post.id) | ||
} | ||
} | ||
} | ||
} | ||
.padding() | ||
} | ||
} | ||
.navigationTitle("timeline_post_title") | ||
.refreshable { | ||
Task { | ||
try await asyncFunction(for: viewModel.fetchPost()) | ||
} | ||
} | ||
.onAppear { | ||
Task { | ||
try await asyncFunction(for: viewModel.fetchPost()) | ||
} | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.