Skip to content

Commit

Permalink
save edit dialog data
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 14, 2024
1 parent ef2ab83 commit 999528b
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 6 deletions.
22 changes: 22 additions & 0 deletions anilist/src/commonMain/graphql/EditMutation.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mutation EditMutation(
$mediaId: Int,
$progress: Int,
$status: MediaListStatus,
$repeat: Int
) {
SaveMediaListEntry(
mediaId: $mediaId,
progress: $progress,
status: $status,
repeat: $repeat
) {
progress,
progressVolumes,
status,
startedAt {
year,
month,
day
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.apollographql.apollo3.ApolloCall
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.type.MediaListStatus
import kotlinx.coroutines.flow.*

class MediumRepository(
Expand Down Expand Up @@ -68,6 +69,29 @@ class MediumRepository(
return client.mutation(mutation)
}

fun updateEditCall(progress: Int, status: MediaListStatus, repeat: Int): ApolloCall<EditMutation.Data> {
val mutation = EditMutation(
mediaId = Optional.present(id.value),
progress = if (progress >= 1) {
Optional.present(progress)
} else {
Optional.absent()
},
status = if (status != MediaListStatus.UNKNOWN__) {
Optional.present(status)
} else {
Optional.absent()
},
repeat = if (repeat >= 1) {
Optional.present(repeat)
} else {
Optional.absent()
}
)

return client.mutation(mutation)
}

private data class Query(
val id: Int,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ class MediumScreenComponent(
it.medium.startDate
},
onDismiss = dialogNavigation::dismiss,
onSave = { status, progress, repeat ->
dialogNavigation.dismiss {
val call = mediumRepository.updateEditCall(
status = status,
progress = progress,
repeat = repeat
).fetchPolicy(FetchPolicy.NetworkOnly)

launchIO {
call.execute()
}
}
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.anilist.type.MediaListStatus
import dev.datlag.aniflow.anilist.type.MediaStatus
import dev.datlag.aniflow.anilist.type.MediaType
import dev.datlag.aniflow.common.icon
import dev.datlag.aniflow.common.isScrollingUp
import dev.datlag.aniflow.common.mapCollect
Expand Down Expand Up @@ -111,7 +112,7 @@ fun FABContent(
ratingState.show()
}
),
if (bsAvailable && bsOptions.isNotEmpty()) {
if (bsAvailable && type == MediaType.ANIME) {
FABItem(
painter = painterResource(SharedRes.images.bs),
label = stringResource(SharedRes.strings.bs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface EditComponent : DialogComponent {
val listStatus: Flow<MediaListStatus>
val repeatCount: Flow<Int?>
val episodeStartDate: Flow<LocalDate?>

fun save(editState: EditState)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,24 @@ fun EditDialog(component: EditComponent) {

LazyColumn(
modifier = Modifier.fillMaxWidth(),
contentPadding = bottomPadding.merge(PaddingValues(16.dp)),
contentPadding = bottomPadding.merge(
PaddingValues(
top = 16.dp,
start = 16.dp,
end = 16.dp,
bottom = 48.dp
)
),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
TopSection(
state = sheetState,
modifier = Modifier.fillParentMaxWidth(),
onBack = component::dismiss,
onSave = { }
onSave = {
component.save(editState)
}
)
}
item {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dev.datlag.aniflow.ui.navigation.screen.medium.dialog.edit

import androidx.compose.runtime.Composable
import com.apollographql.apollo3.ApolloClient
import com.arkivanov.decompose.ComponentContext
import dev.datlag.aniflow.anilist.model.Medium
import dev.datlag.aniflow.anilist.type.MediaListStatus
import dev.datlag.aniflow.common.onRender
import dev.datlag.aniflow.other.BurningSeriesResolver
import dev.datlag.aniflow.other.Constants
import dev.datlag.aniflow.other.Series
import dev.datlag.tooling.compose.ioDispatcher
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -24,11 +26,10 @@ class EditDialogComponent(
override val listStatus: Flow<MediaListStatus>,
override val repeatCount: Flow<Int?>,
override val episodeStartDate: Flow<LocalDate?>,
private val onDismiss: () -> Unit
private val onDismiss: () -> Unit,
private val onSave: (MediaListStatus, Int, Int) -> Unit
) : EditComponent, ComponentContext by componentContext {



@Composable
override fun render() {
onRender {
Expand All @@ -39,4 +40,12 @@ class EditDialogComponent(
override fun dismiss() {
onDismiss()
}

override fun save(editState: EditState) {
val status = editState.listStatus.value
val progress = editState.episode.value
val repeat = editState.repeat.value

onSave(status, progress, repeat)
}
}

0 comments on commit 999528b

Please sign in to comment.