mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
Data View | Refact | Create-relation-and-add-it-to-data-view-view flow (#1435)
This commit is contained in:
parent
9c3b6aafc3
commit
2d09ddb679
11 changed files with 52 additions and 37 deletions
2
.github/workflows/check.yml
vendored
2
.github/workflows/check.yml
vendored
|
@ -1,7 +1,7 @@
|
|||
on:
|
||||
pull_request:
|
||||
# add "synchronize" in "types", in order to trigger workflow for pull request commit(s) pushes.
|
||||
types: [opened, synchronize]
|
||||
types: [opened]
|
||||
branches: [develop]
|
||||
name: Run debug unit tests
|
||||
jobs:
|
||||
|
|
|
@ -294,7 +294,7 @@ class BlockDataRepository(
|
|||
target: Id,
|
||||
name: String,
|
||||
format: Relation.Format
|
||||
): Payload = factory.remote.addDataViewRelation(
|
||||
): Pair<Id, Payload> = factory.remote.addDataViewRelation(
|
||||
context = context,
|
||||
target = target,
|
||||
name = name,
|
||||
|
|
|
@ -88,7 +88,7 @@ interface BlockDataStore {
|
|||
target: Id,
|
||||
name: String,
|
||||
format: Relation.Format
|
||||
): Payload
|
||||
): Pair<Id, Payload>
|
||||
|
||||
suspend fun updateDataViewViewer(
|
||||
context: Id,
|
||||
|
|
|
@ -89,7 +89,7 @@ interface BlockRemote {
|
|||
target: Id,
|
||||
name: String,
|
||||
format: Relation.Format
|
||||
): Payload
|
||||
): Pair<Id, Payload>
|
||||
|
||||
suspend fun updateDataViewViewer(
|
||||
context: String,
|
||||
|
|
|
@ -215,7 +215,7 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
|
|||
target: Id,
|
||||
name: String,
|
||||
format: Relation.Format
|
||||
): Payload = remote.addDataViewRelation(
|
||||
): Pair<Id, Payload> = remote.addDataViewRelation(
|
||||
context = context,
|
||||
target = target,
|
||||
name = name,
|
||||
|
|
|
@ -143,7 +143,7 @@ interface BlockRepository {
|
|||
target: Id,
|
||||
name: String,
|
||||
format: Relation.Format
|
||||
): Payload
|
||||
): Pair<Id, Payload>
|
||||
|
||||
suspend fun updateDataViewViewer(
|
||||
context: Id,
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package com.anytypeio.anytype.domain.dataview.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.AddDataViewRelation.Params
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.AddDataViewRelation.Params
|
||||
|
||||
class AddDataViewRelation(
|
||||
private val repo: BlockRepository
|
||||
) : BaseUseCase<Payload, Params>() {
|
||||
) : BaseUseCase<Pair<Id, Payload>, Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = safe {
|
||||
repo.addDataViewRelation(
|
||||
|
|
|
@ -236,7 +236,7 @@ class BlockMiddleware(
|
|||
target: String,
|
||||
name: String,
|
||||
format: Relation.Format
|
||||
): Payload = middleware.addDataViewRelation(
|
||||
): Pair<Id, Payload> = middleware.addDataViewRelation(
|
||||
context = context,
|
||||
target = target,
|
||||
format = format,
|
||||
|
|
|
@ -1045,7 +1045,7 @@ class Middleware(
|
|||
target: String,
|
||||
name: String,
|
||||
format: com.anytypeio.anytype.core_models.Relation.Format
|
||||
): Payload {
|
||||
): Pair<Id, Payload> {
|
||||
|
||||
val relation = Relation(
|
||||
name = name,
|
||||
|
@ -1061,7 +1061,7 @@ class Middleware(
|
|||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.blockDataViewRelationAdd(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
return response.event.toPayload()
|
||||
return Pair(response.relationKey, response.event.toPayload())
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.anytypeio.anytype.presentation.sets
|
||||
|
||||
import com.anytypeio.anytype.core_models.*
|
||||
import com.anytypeio.anytype.core_models.DV
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Event.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.presentation.extension.updateFields
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
@ -139,26 +142,6 @@ class ObjectSetReducer {
|
|||
relations = content.relations.toMutableList().apply {
|
||||
removeIf { it.key == event.key }
|
||||
add(event.relation)
|
||||
},
|
||||
viewers = content.viewers.map { viewer ->
|
||||
val new = viewer.viewerRelations.toMutableList().apply {
|
||||
removeIf { it.key == event.key }
|
||||
add(
|
||||
DVViewerRelation(
|
||||
key = event.key,
|
||||
isVisible = true
|
||||
)
|
||||
)
|
||||
}
|
||||
viewer.copy(viewerRelations = new.toSet().toList()).apply {
|
||||
// May cause data races. Consider some other solution.
|
||||
effects.add(
|
||||
SideEffect.ViewerUpdate(
|
||||
target = block.id,
|
||||
viewer = this
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
@ -219,11 +219,42 @@ class ObjectSetViewModel(
|
|||
)
|
||||
).process(
|
||||
failure = { Timber.e(it, "Error while adding data view relation") },
|
||||
success = defaultPayloadConsumer
|
||||
success = { (key, payload) ->
|
||||
reducer.dispatch(payload.events).also {
|
||||
proceedWithAddingNewRelationToCurrentViewer(relation = key)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun proceedWithAddingNewRelationToCurrentViewer(relation: Id) {
|
||||
val state = reducer.state.value
|
||||
val block = state.dataview
|
||||
val dv = block.content as DV
|
||||
val viewer = dv.viewers.find {
|
||||
it.id == session.currentViewerId
|
||||
} ?: dv.viewers.first()
|
||||
|
||||
updateDataViewViewer(
|
||||
UpdateDataViewViewer.Params(
|
||||
context = context,
|
||||
target = block.id,
|
||||
viewer = viewer.copy(
|
||||
viewerRelations = viewer.viewerRelations + listOf(
|
||||
DVViewerRelation(
|
||||
key = relation,
|
||||
isVisible = true
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
).process(
|
||||
success = defaultPayloadConsumer,
|
||||
failure = { Timber.e(it, "Error while updating data view's viewer") }
|
||||
)
|
||||
}
|
||||
|
||||
fun onTitleChanged(txt: String) {
|
||||
val target = header.value?.id
|
||||
checkNotNull(target) { "Title block was missing or not ready" }
|
||||
|
@ -242,7 +273,8 @@ class ObjectSetViewModel(
|
|||
val state = reducer.state.value
|
||||
val block = state.dataview
|
||||
val dv = block.content as DV
|
||||
val viewer = dv.viewers.find { it.id == session.currentViewerId }?.id ?: dv.viewers.first().id
|
||||
val viewer = dv.viewers.find { it.id == session.currentViewerId }?.id
|
||||
?: dv.viewers.first().id
|
||||
|
||||
when (cell) {
|
||||
is CellView.Description, is CellView.Number, is CellView.Email,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue