Skip to content

Commit

Permalink
remove usage of non-js library
Browse files Browse the repository at this point in the history
  • Loading branch information
melod1n committed Aug 8, 2024
1 parent efe4536 commit 16418ed
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 64 deletions.
1 change: 0 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ kotlin {
implementation(libs.haze.materials)
implementation(libs.kstore)
implementation(libs.napier)
implementation(libs.message.bar)
}

commonTest.dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.meloda.overseerr.screens.requests.presentation

import ContentWithMessageBar
import MessageBarPosition
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
Expand Down Expand Up @@ -30,14 +29,15 @@ import dev.chrisbanes.haze.materials.HazeMaterials
import dev.meloda.overseerr.screens.requests.RequestsViewModel
import dev.meloda.overseerr.screens.requests.RequestsViewModelImpl
import dev.meloda.overseerr.screens.requests.model.RequestsScreenState
import kotlinx.coroutines.delay
import org.koin.compose.viewmodel.koinViewModel
import rememberMessageBarState
import kotlin.time.Duration.Companion.seconds

class RequestsScreen : Screen {

@OptIn(
ExperimentalMaterial3Api::class,
ExperimentalHazeMaterialsApi::class
ExperimentalHazeMaterialsApi::class, ExperimentalMaterial3Api::class
)
@Composable
override fun Content() {
Expand All @@ -49,18 +49,17 @@ class RequestsScreen : Screen {
val hazeStyle = HazeMaterials.ultraThin()

val refreshState = rememberPullToRefreshState()
val messageBarState = rememberMessageBarState()

LaunchedEffect(screenState) {
if (screenState.apiErrorText != null) {
messageBarState.addError(Exception(screenState.apiErrorText))
viewModel.onErrorMessageShown()
}

if (screenState.apiInfo != null) {
messageBarState.addSuccess(screenState.apiInfo.toString())
delay(5.seconds)
viewModel.onSuccessMessageShown()
}

if (screenState.apiErrorText != null) {
delay(5.seconds)
viewModel.onErrorMessageShown()
}
}

Scaffold(
Expand Down Expand Up @@ -97,65 +96,79 @@ class RequestsScreen : Screen {
) { padding ->
val bottomPadding = padding.calculateBottomPadding()

ContentWithMessageBar(
messageBarState = messageBarState,
position = MessageBarPosition.BOTTOM
Box(
modifier = Modifier
.fillMaxSize()
.padding(start = padding.calculateStartPadding(LayoutDirection.Ltr))
.padding(end = padding.calculateEndPadding(LayoutDirection.Ltr))
) {
Box(
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(start = padding.calculateStartPadding(LayoutDirection.Ltr))
.padding(end = padding.calculateEndPadding(LayoutDirection.Ltr))
.haze(
state = hazeState,
style = hazeStyle
)
.pullToRefresh(
isRefreshing = screenState.isLoading,
state = refreshState,
onRefresh = viewModel::onRefresh
)
) {
LazyColumn(
item {
Spacer(modifier = Modifier.height(padding.calculateTopPadding()))
}
item {
AnimatedVisibility(screenState.apiErrorText != null || screenState.apiInfo != null) {
Box(
modifier = Modifier
.fillMaxWidth()
.background(
if (screenState.apiInfo != null) Color(0xffb00b69)
else Color.Red
),
contentAlignment = Alignment.CenterStart
) {
Text(
text = screenState.apiErrorText ?: screenState.apiInfo.toString(),
style = MaterialTheme.typography.headlineMedium,
modifier = Modifier.padding(10.dp)
)
}
}
}
items(items = screenState.dummyItems) { index ->
Text(
text = "Text #${index + 1}",
style = MaterialTheme.typography.headlineLarge,
modifier = Modifier.background(Color.Red)
)
Spacer(modifier = Modifier.height(64.dp))
}
item {
Spacer(modifier = Modifier.height(bottomPadding))
}
}

Indicator(
state = refreshState,
isRefreshing = screenState.isLoading,
modifier = Modifier.align(Alignment.TopCenter)
.padding(top = padding.calculateTopPadding())
)

if (bottomPadding.value > 0) {
Box(
modifier = Modifier
.fillMaxSize()
.haze(
.align(Alignment.BottomCenter)
.hazeChild(
state = hazeState,
style = hazeStyle
)
.pullToRefresh(
isRefreshing = screenState.isLoading,
state = refreshState,
onRefresh = viewModel::onRefresh
)
) {
item {
Spacer(modifier = Modifier.height(padding.calculateTopPadding()))
}
items(items = screenState.dummyItems) { index ->
Text(
text = "Text #${index + 1}",
style = MaterialTheme.typography.headlineLarge,
modifier = Modifier.background(Color.Red)
)
Spacer(modifier = Modifier.height(64.dp))
}
item {
Spacer(modifier = Modifier.height(bottomPadding))
}
}

Indicator(
state = refreshState,
isRefreshing = screenState.isLoading,
modifier = Modifier.align(Alignment.TopCenter)
.padding(top = padding.calculateTopPadding())
.background(Color.Transparent)
.height(bottomPadding)
.fillMaxWidth()
)

if (bottomPadding.value > 0) {
Box(
modifier = Modifier
.align(Alignment.BottomCenter)
.hazeChild(
state = hazeState,
style = hazeStyle
)
.background(Color.Transparent)
.height(bottomPadding)
.fillMaxWidth()
)
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ haze = "0.7.3"
kstore = "0.8.0"
appdirs = "1.2.2"
napier = "2.7.1"
message-bar = "1.0.5"

[libraries]

Expand Down Expand Up @@ -49,7 +48,6 @@ kstore-file = { module = "io.github.xxfast:kstore-file", version.ref = "kstore"
kstore-storage = { module = "io.github.xxfast:kstore-storage", version.ref = "kstore" }
appdirs = { module = "net.harawata:appdirs", version.ref = "appdirs" }
napier = { module = "io.github.aakira:napier", version.ref = "napier" }
message-bar = { module = "com.stevdza-san:messagebarkmp", version.ref = "message-bar" }

[plugins]

Expand Down

0 comments on commit 16418ed

Please sign in to comment.