This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
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
16 changed files
with
457 additions
and
123 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
56 changes: 56 additions & 0 deletions
56
common/src/commonMain/kotlin/io/github/mmauro94/common/client/entities/GetCommentsForm.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,56 @@ | ||
package io.github.mmauro94.common.client.entities | ||
|
||
data class GetCommentsForm( | ||
val userPreferences: GetCommentsUserPreferenceInfo, | ||
val context: GetCommentsFormContextualInfo? = null, | ||
val page: GetCommentsFormPageInfo? = null, | ||
val maxDepth: Int? = null, | ||
) { | ||
|
||
init { | ||
require(maxDepth == null || maxDepth > 0) { "Invalid max depth: $maxDepth" } | ||
} | ||
|
||
fun withIncreasedPage(): GetCommentsForm { | ||
check(page != null) | ||
return copy(page = page.increased()) | ||
} | ||
} | ||
|
||
sealed interface GetCommentsFormContextualInfo { | ||
data class CommunityId( | ||
val communityId: Long, | ||
) : GetCommentsFormContextualInfo | ||
|
||
data class CommunityName( | ||
val communityName: String, | ||
) : GetCommentsFormContextualInfo | ||
|
||
data class PostId( | ||
val postId: Long, | ||
) : GetCommentsFormContextualInfo | ||
|
||
data class ParentId( | ||
val commentId: Long, | ||
) : GetCommentsFormContextualInfo | ||
} | ||
|
||
data class GetCommentsFormPageInfo( | ||
val page: Int, | ||
val limit: Int, | ||
) { | ||
init { | ||
require(page > 0) { "Invalid page: $page" } | ||
require(limit > 0) { "Invalid limit: $limit" } | ||
} | ||
|
||
fun increased(): GetCommentsFormPageInfo { | ||
return copy(page = page + 1) | ||
} | ||
} | ||
|
||
data class GetCommentsUserPreferenceInfo( | ||
val savedOnly: Boolean? = null, | ||
val sort: CommentSortType? = null, | ||
val type: ListingType? = null, | ||
) |
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
39 changes: 39 additions & 0 deletions
39
...rc/commonMain/kotlin/io/github/mmauro94/common/ui/components/comments/CommentContainer.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,39 @@ | ||
package io.github.mmauro94.common.ui.components.comments | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.IntrinsicSize | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.Divider | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
private val DEPTH_WIDTH = 4.dp | ||
|
||
@Composable | ||
fun CommentContainer( | ||
depth: Int, | ||
modifier: Modifier = Modifier, | ||
content: @Composable () -> Unit, | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.height(IntrinsicSize.Max) | ||
.fillMaxWidth() | ||
.then(modifier), | ||
) { | ||
Spacer(Modifier.width(DEPTH_WIDTH * (depth - 1))) | ||
if (depth > 0) { | ||
Box(Modifier.width(DEPTH_WIDTH).fillMaxHeight().background(MaterialTheme.colorScheme.primary)) | ||
} | ||
content() | ||
} | ||
Divider() | ||
} |
36 changes: 36 additions & 0 deletions
36
...rc/commonMain/kotlin/io/github/mmauro94/common/ui/components/comments/LoadMoreComments.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,36 @@ | ||
package io.github.mmauro94.common.ui.components.comments | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import dev.icerock.moko.resources.compose.stringResource | ||
import io.github.mmauro94.common.MR | ||
import io.github.mmauro94.common.utils.LocalLemmyContext | ||
import io.github.mmauro94.common.utils.comments.CommentList | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun LoadMoreComments( | ||
coroutineScope: CoroutineScope, | ||
commentList: CommentList<*>, | ||
depth: Int, | ||
) { | ||
val client = LocalLemmyContext.current.client | ||
CommentContainer( | ||
modifier = Modifier.clickable { | ||
coroutineScope.launch { commentList.loadNext(client) } | ||
}, | ||
depth = depth, | ||
) { | ||
Text( | ||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), | ||
text = stringResource(MR.strings.load_more_comments), | ||
style = MaterialTheme.typography.bodyMedium, | ||
) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...src/commonMain/kotlin/io/github/mmauro94/common/ui/components/comments/LoadingComments.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,31 @@ | ||
package io.github.mmauro94.common.ui.components.comments | ||
|
||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import dev.icerock.moko.resources.compose.stringResource | ||
import io.github.mmauro94.common.MR | ||
|
||
@Composable | ||
fun LoadingComments(depth: Int) { | ||
CommentContainer(depth = depth) { | ||
Row( | ||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp) | ||
Text( | ||
modifier = Modifier.padding(start = 8.dp), | ||
text = stringResource(MR.strings.loading___), | ||
style = MaterialTheme.typography.bodyMedium, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.