mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3151 Spaces | Enhancement | Apply empty use if user has more than two spaces when creating new space (#1907)
This commit is contained in:
parent
2b751772fc
commit
a7274257f3
9 changed files with 43 additions and 20 deletions
|
@ -475,6 +475,12 @@ sealed class Command {
|
|||
|
||||
data class SetInternalFlags(val ctx: Id, val flags: List<InternalFlags>)
|
||||
|
||||
data class CreateSpace(
|
||||
val details: Struct,
|
||||
val withChat: Boolean,
|
||||
val shouldApplyEmptyUseCase: Boolean
|
||||
)
|
||||
|
||||
data class AddObjectToSpace(val space: Id, val objectId: Id)
|
||||
data class ApplyTemplate(val objectId: Id, val template: Id?)
|
||||
|
||||
|
|
|
@ -759,9 +759,8 @@ class BlockDataRepository(
|
|||
remote.deleteSpace(space)
|
||||
}
|
||||
|
||||
override suspend fun createWorkspace(details: Struct, withChat: Boolean): Id = remote.createWorkspace(
|
||||
details = details,
|
||||
withChat = withChat
|
||||
override suspend fun createWorkspace(command: Command.CreateSpace): Id = remote.createWorkspace(
|
||||
command = command
|
||||
)
|
||||
|
||||
override suspend fun setSpaceDetails(space: SpaceId, details: Struct) {
|
||||
|
|
|
@ -339,7 +339,7 @@ interface BlockRemote {
|
|||
suspend fun setSpaceDetails(space: SpaceId, details: Struct)
|
||||
|
||||
suspend fun deleteSpace(space: SpaceId)
|
||||
suspend fun createWorkspace(details: Struct, withChat: Boolean): Id
|
||||
suspend fun createWorkspace(command: Command.CreateSpace): Id
|
||||
|
||||
suspend fun getSpaceConfig(space: Id): Config
|
||||
|
||||
|
|
|
@ -391,7 +391,7 @@ interface BlockRepository {
|
|||
): Payload
|
||||
|
||||
suspend fun deleteSpace(space: SpaceId)
|
||||
suspend fun createWorkspace(details: Struct, withChat: Boolean): Id
|
||||
suspend fun createWorkspace(command: Command.CreateSpace): Id
|
||||
suspend fun getSpaceConfig(space: Id): Config
|
||||
suspend fun addObjectListToSpace(objects: List<Id>, space: Id) : List<Id>
|
||||
suspend fun addObjectToSpace(command: Command.AddObjectToSpace) : Pair<Id, Struct?>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.anytypeio.anytype.domain.spaces
|
||||
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
|
@ -13,9 +14,16 @@ class CreateSpace @Inject constructor(
|
|||
) : ResultInteractor<CreateSpace.Params, Id>(dispatchers.io) {
|
||||
|
||||
override suspend fun doWork(params: Params): Id = repo.createWorkspace(
|
||||
details = params.details,
|
||||
withChat = params.withChat
|
||||
command = Command.CreateSpace(
|
||||
details = params.details,
|
||||
withChat = params.withChat,
|
||||
shouldApplyEmptyUseCase = params.shouldApplyEmptyUseCase
|
||||
),
|
||||
)
|
||||
|
||||
data class Params(val details: Struct, val withChat: Boolean = true)
|
||||
data class Params(
|
||||
val details: Struct,
|
||||
val withChat: Boolean = false,
|
||||
val shouldApplyEmptyUseCase: Boolean = false
|
||||
)
|
||||
}
|
|
@ -28,11 +28,13 @@ import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationNaviga
|
|||
import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationSpacesState
|
||||
import com.anytypeio.anytype.gallery_experience.models.GalleryInstallationState
|
||||
import com.anytypeio.anytype.gallery_experience.models.GallerySpaceView
|
||||
import com.anytypeio.anytype.presentation.spaces.CreateSpaceViewModel.Companion.MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE
|
||||
import com.anytypeio.anytype.presentation.spaces.SelectSpaceViewModel
|
||||
import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider
|
||||
import com.anytypeio.anytype.presentation.spaces.spaceIcon
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
|
@ -129,7 +131,10 @@ class GalleryInstallationViewModel(
|
|||
details = mapOf(
|
||||
Relations.NAME to manifestInfo.title,
|
||||
Relations.ICON_OPTION to spaceGradientProvider.randomId().toDouble()
|
||||
)
|
||||
),
|
||||
shouldApplyEmptyUseCase = spacesViewState.value.spaces.count { item ->
|
||||
item.obj.isActive
|
||||
} >= MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE
|
||||
)
|
||||
createSpace.async(params).fold(
|
||||
onSuccess = { space ->
|
||||
|
|
|
@ -730,12 +730,8 @@ class BlockMiddleware(
|
|||
middleware.spaceDelete(space)
|
||||
}
|
||||
|
||||
override suspend fun createWorkspace(
|
||||
details: Struct,
|
||||
withChat: Boolean
|
||||
): Id = middleware.workspaceCreate(
|
||||
details = details,
|
||||
withChat = withChat
|
||||
override suspend fun createWorkspace(command: Command.CreateSpace): Id = middleware.workspaceCreate(
|
||||
command = command
|
||||
)
|
||||
|
||||
override suspend fun getSpaceConfig(space: Id): Config = middleware.workspaceOpen(
|
||||
|
|
|
@ -1935,11 +1935,14 @@ class Middleware @Inject constructor(
|
|||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun workspaceCreate(details: Struct, withChat: Boolean): Id {
|
||||
fun workspaceCreate(command: Command.CreateSpace): Id {
|
||||
val request = Rpc.Workspace.Create.Request(
|
||||
details = details,
|
||||
useCase = Rpc.Object.ImportUseCase.Request.UseCase.GET_STARTED,
|
||||
withChat = withChat
|
||||
details = command.details,
|
||||
useCase = if (command.shouldApplyEmptyUseCase)
|
||||
Rpc.Object.ImportUseCase.Request.UseCase.EMPTY
|
||||
else
|
||||
Rpc.Object.ImportUseCase.Request.UseCase.GET_STARTED,
|
||||
withChat = command.withChat
|
||||
)
|
||||
logRequestIfDebug(request)
|
||||
val (response, time) = measureTimedValue { service.workspaceCreate(request) }
|
||||
|
|
|
@ -58,13 +58,15 @@ class CreateSpaceViewModel(
|
|||
return
|
||||
}
|
||||
val isSingleSpace = spaceViewContainer.get().size == 1
|
||||
val numberOfActiveSpaces = spaceViewContainer.get().filter { it.isActive }.size
|
||||
viewModelScope.launch {
|
||||
createSpace.stream(
|
||||
CreateSpace.Params(
|
||||
details = mapOf(
|
||||
Relations.NAME to name,
|
||||
Relations.ICON_OPTION to spaceIconView.value.color.index.toDouble()
|
||||
)
|
||||
),
|
||||
shouldApplyEmptyUseCase = numberOfActiveSpaces >= MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE
|
||||
)
|
||||
).collect { result ->
|
||||
result.fold(
|
||||
|
@ -135,4 +137,8 @@ class CreateSpaceViewModel(
|
|||
val showMultiplayerTooltip: Boolean
|
||||
): Command()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MAX_SPACE_COUNT_WITH_GET_STARTED_USE_CASE = 2
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue