Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-wls committed Nov 26, 2024
1 parent 9c6ac81 commit 8f83931
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ fun `Metis - Conversation Channel`() {
listContentPadding = PaddingValues(),
serverUrl = "",
courseId = 0,
markdownImageLoader = null,
state = rememberLazyListState(),
isReplyEnabled = true,
onCreatePost = { CompletableDeferred() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems
import coil.ImageLoader
import de.tum.informatics.www1.artemis.native_app.core.ui.markdown.ProvideMarkwon
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.R
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.EmojiService
import de.tum.informatics.www1.artemis.native_app.feature.metis.conversation.service.MetisModificationFailure
Expand Down Expand Up @@ -91,7 +92,7 @@ internal fun MetisChatList(

val context = LocalContext.current
var imageLoader: ImageLoader? by remember { mutableStateOf(null) }
LaunchedEffect(rememberCoroutineScope()) {
LaunchedEffect(true) {
imageLoader = viewModel.createMarkdownImageLoader(context).await()
}

Expand All @@ -101,28 +102,29 @@ internal fun MetisChatList(
}
}

MetisChatList(
modifier = modifier,
initialReplyTextProvider = viewModel,
posts = posts.asPostsDataState(),
clientId = clientId,
hasModerationRights = hasModerationRights,
isAtLeastTutorInCourse = isAtLeastTutorInCourse,
listContentPadding = listContentPadding,
serverUrl = serverUrl,
courseId = viewModel.courseId,
markdownImageLoader = imageLoader,
state = state,
bottomItem = bottomItem,
isReplyEnabled = isReplyEnabled,
onCreatePost = viewModel::createPost,
onEditPost = viewModel::editPost,
onDeletePost = viewModel::deletePost,
onRequestReactWithEmoji = viewModel::createOrDeleteReaction,
onClickViewPost = onClickViewPost,
onRequestRetrySend = viewModel::retryCreatePost,
title = updatedTitle
)
ProvideMarkwon(imageLoader) {
MetisChatList(
modifier = modifier,
initialReplyTextProvider = viewModel,
posts = posts.asPostsDataState(),
clientId = clientId,
hasModerationRights = hasModerationRights,
isAtLeastTutorInCourse = isAtLeastTutorInCourse,
listContentPadding = listContentPadding,
serverUrl = serverUrl,
courseId = viewModel.courseId,
state = state,
bottomItem = bottomItem,
isReplyEnabled = isReplyEnabled,
onCreatePost = viewModel::createPost,
onEditPost = viewModel::editPost,
onDeletePost = viewModel::deletePost,
onRequestReactWithEmoji = viewModel::createOrDeleteReaction,
onClickViewPost = onClickViewPost,
onRequestRetrySend = viewModel::retryCreatePost,
title = updatedTitle
)
}
}

@Composable
Expand All @@ -137,7 +139,6 @@ fun MetisChatList(
listContentPadding: PaddingValues,
serverUrl: String,
courseId: Long,
markdownImageLoader: ImageLoader?,
state: LazyListState,
emojiService: EmojiService = koinInject(),
isReplyEnabled: Boolean,
Expand Down Expand Up @@ -172,7 +173,6 @@ fun MetisChatList(
itemCount = posts.itemCount,
order = DisplayPostOrder.REVERSED,
emojiService = emojiService,
markdownImageLoader = markdownImageLoader,
bottomItem = bottomItem
) {
when (posts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ internal fun <T : Any> MetisPostListHandler(
itemCount: Int,
bottomItem: T?,
order: DisplayPostOrder,
markdownImageLoader: ImageLoader?,
emojiService: EmojiService,
content: @Composable BoxScope.() -> Unit
) {
Expand Down Expand Up @@ -119,11 +118,9 @@ internal fun <T : Any> MetisPostListHandler(
PostArtemisMarkdownTransformer(serverUrl = strippedServerUrl, courseId = courseId)
}

ProvideMarkwon(markdownImageLoader) {
ProvideEmojis(emojiService) {
CompositionLocalProvider(LocalMarkdownTransformer provides markdownTransformer) {
content()
}
ProvideEmojis(emojiService) {
CompositionLocalProvider(LocalMarkdownTransformer provides markdownTransformer) {
content()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal fun MetisThreadUi(

val context = LocalContext.current
var imageLoader: ImageLoader? by remember { mutableStateOf(null) }
LaunchedEffect(rememberCoroutineScope()) {
LaunchedEffect(true) {
imageLoader = viewModel.createMarkdownImageLoader(context).await()
}

Expand All @@ -101,50 +101,51 @@ internal fun MetisThreadUi(

val conversationDataState by viewModel.conversation.collectAsState()

MetisThreadUi(
modifier = modifier,
courseId = viewModel.courseId,
initialReplyTextProvider = viewModel,
conversationDataState = conversationDataState,
postDataState = postDataState,
isAtLeastTutorInCourse = isAtLeastTutorInCourse,
hasModerationRights = hasModerationRights,
listContentPadding = listContentPadding,
serverUrl = serverUrl,
emojiService = koinInject(),
clientId = clientId,
markdownImageLoader = imageLoader,
onCreatePost = viewModel::createReply,
onEditPost = { post, newText ->
val parentPost = postDataState.orNull()
ProvideMarkwon(imageLoader) {
MetisThreadUi(
modifier = modifier,
courseId = viewModel.courseId,
initialReplyTextProvider = viewModel,
conversationDataState = conversationDataState,
postDataState = postDataState,
isAtLeastTutorInCourse = isAtLeastTutorInCourse,
hasModerationRights = hasModerationRights,
listContentPadding = listContentPadding,
serverUrl = serverUrl,
emojiService = koinInject(),
clientId = clientId,
onCreatePost = viewModel::createReply,
onEditPost = { post, newText ->
val parentPost = postDataState.orNull()

when (post) {
is AnswerPostPojo -> {
if (parentPost == null) CompletableDeferred(
MetisModificationFailure.UPDATE_POST
) else viewModel.editAnswerPost(parentPost, post, newText)
}

when (post) {
is AnswerPostPojo -> {
is PostPojo -> viewModel.editPost(post, newText)
else -> throw NotImplementedError()
}
},
onResolvePost = { post ->
val parentPost = postDataState.orNull()

if (post is AnswerPostPojo) {
if (parentPost == null) CompletableDeferred(
MetisModificationFailure.UPDATE_POST
) else viewModel.editAnswerPost(parentPost, post, newText)
) else viewModel.toggleResolvePost(parentPost, post)
} else {
throw NotImplementedError()
}

is PostPojo -> viewModel.editPost(post, newText)
else -> throw NotImplementedError()
}
},
onResolvePost = { post ->
val parentPost = postDataState.orNull()

if (post is AnswerPostPojo) {
if (parentPost == null) CompletableDeferred(
MetisModificationFailure.UPDATE_POST
) else viewModel.toggleResolvePost(parentPost, post)
} else {
throw NotImplementedError()
}
},
onDeletePost = viewModel::deletePost,
onRequestReactWithEmoji = viewModel::createOrDeleteReaction,
onRequestReload = viewModel::requestReload,
onRequestRetrySend = viewModel::retryCreateReply
)
},
onDeletePost = viewModel::deletePost,
onRequestReactWithEmoji = viewModel::createOrDeleteReaction,
onRequestReload = viewModel::requestReload,
onRequestRetrySend = viewModel::retryCreateReply
)
}
}

@Composable
Expand All @@ -159,7 +160,6 @@ internal fun MetisThreadUi(
listContentPadding: PaddingValues,
serverUrl: String,
emojiService: EmojiService,
markdownImageLoader: ImageLoader?,
initialReplyTextProvider: InitialReplyTextProvider,
onCreatePost: () -> Deferred<MetisModificationFailure?>,
onEditPost: (IBasePost, String) -> Deferred<MetisModificationFailure?>,
Expand Down Expand Up @@ -206,7 +206,6 @@ internal fun MetisThreadUi(
state = listState,
itemCount = post.orderedAnswerPostings.size,
order = DisplayPostOrder.REGULAR,
markdownImageLoader = markdownImageLoader,
emojiService = emojiService,
bottomItem = post.orderedAnswerPostings.lastOrNull()
) {
Expand All @@ -219,7 +218,6 @@ internal fun MetisThreadUi(
isAtLeastTutorInCourse = isAtLeastTutorInCourse,
listContentPadding = listContentPadding,
clientId = clientId,
markdownImageLoader = markdownImageLoader,
onRequestReactWithEmoji = onRequestReactWithEmojiDelegate,
onRequestEdit = onEditPostDelegate,
onRequestDelete = onDeletePostDelegate,
Expand Down Expand Up @@ -255,7 +253,6 @@ private fun PostAndRepliesList(
isAtLeastTutorInCourse: Boolean,
listContentPadding: PaddingValues,
clientId: Long,
markdownImageLoader: ImageLoader?,
onRequestEdit: (IBasePost) -> Unit,
onRequestDelete: (IBasePost) -> Unit,
onRequestResolve: (IBasePost) -> Unit,
Expand Down

0 comments on commit 8f83931

Please sign in to comment.