Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.anytypeio.anytype.presentation.widgets.Widget.Source.Companion.WIDGET
import com.anytypeio.anytype.presentation.widgets.WidgetView
import com.anytypeio.anytype.ui.widgets.types.AddWidgetButton
import com.anytypeio.anytype.ui.widgets.types.BinWidgetCard
import com.anytypeio.anytype.ui.widgets.types.SpaceChatWidgetCard
import sh.calvin.reorderable.ReorderableItem
import sh.calvin.reorderable.rememberReorderableLazyListState

Expand All @@ -50,7 +49,6 @@ fun WidgetsScreen(
val hapticFeedback = rememberReorderHapticFeedback()

val mode = viewModel.mode.collectAsState().value
val chatWidget = viewModel.chatView.collectAsState().value
val pinnedWidgets = viewModel.pinnedViews.collectAsState().value
val typeWidgets = viewModel.typeViews.collectAsState().value
val binWidget = viewModel.binView.collectAsState().value
Expand Down Expand Up @@ -151,31 +149,6 @@ fun WidgetsScreen(
modifier = Modifier.fillMaxSize()
) {

// Chat widget
chatWidget?.let { chat ->
if (chat is WidgetView.SpaceChat) {
item {
ReorderableItem(
enabled = false,
state = reorderableState,
key = chat.id,
) {
SpaceChatWidgetCard(
item = chat,
mode = mode,
unReadMentionCount = chat.unreadMentionCount,
unReadMessageCount = chat.unreadMessageCount,
isMuted = chat.isMuted,
onWidgetClicked = viewModel::onWidgetChatClicked,
onDropDownMenuAction = { action ->
viewModel.onDropDownMenuAction(chat.id, action)
}
)
}
}
}
}

// Only show pinned section header if there are items or section is collapsed
if (shouldShowPinnedHeader) {
item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ class HomeScreenViewModel(
private val treeWidgetBranchStateHolder = TreeWidgetBranchStateHolder()

// Separate StateFlows for different widget sections
private val chatWidget = MutableStateFlow<Widget.Chat?>(null)
private val pinnedWidgets = MutableStateFlow<List<Widget>>(emptyList())
private val typeWidgets = MutableStateFlow<List<Widget>>(emptyList())
private val binWidget = MutableStateFlow<Widget.Bin?>(null)
Expand Down Expand Up @@ -325,23 +324,6 @@ class HomeScreenViewModel(
initialValue = emptyList()
)

// Exposed flow for space chat widget
@OptIn(ExperimentalCoroutinesApi::class)
val chatView: StateFlow<WidgetView?> = chatWidget
.flatMapLatest { widget ->
if (widget == null) {
flowOf(null)
} else {
// Create container for chat widget
widgetContainerDelegate.createContainer(widget, emptyList())?.view ?: flowOf(null)
}
}
.stateIn(
scope = viewModelScope,
started = SharingStarted.Eagerly,
initialValue = null
)

// Exposed flow for bin widget
@OptIn(ExperimentalCoroutinesApi::class)
val binView: StateFlow<WidgetView?> = binWidget
Expand Down Expand Up @@ -786,10 +768,9 @@ class HomeScreenViewModel(
}
}.collect { sections ->
if (sections != null) {
val totalWidgets = (if (sections.chatWidget != null) 1 else 0) + sections.pinnedWidgets.size + sections.typeWidgets.size + (if (sections.binWidget != null) 1 else 0)
Timber.d("Emitting widget sections: chat=${sections.chatWidget != null}, pinned=${sections.pinnedWidgets.size}, types=${sections.typeWidgets.size}, bin=${sections.binWidget != null}, total=$totalWidgets")
val totalWidgets = sections.pinnedWidgets.size + sections.typeWidgets.size + (if (sections.binWidget != null) 1 else 0)
Timber.d("Emitting widget sections: pinned=${sections.pinnedWidgets.size}, types=${sections.typeWidgets.size}, bin=${sections.binWidget != null}, total=$totalWidgets")

chatWidget.value = sections.chatWidget
pinnedWidgets.value = sections.pinnedWidgets

// Check event lock before updating type widgets to prevent race conditions during DnD
Expand All @@ -801,7 +782,6 @@ class HomeScreenViewModel(

binWidget.value = sections.binWidget
} else {
chatWidget.value = null
pinnedWidgets.value = emptyList()

// Check event lock before clearing type widgets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,11 @@ data class WidgetUiParams(
/**
* Result of building widgets, separated into sections.
*
* @property chatWidget The space chat widget, displayed separately at the top (for shared spaces)
* @property pinnedWidgets Widgets from the pinned section (user-arranged widgets)
* @property typeWidgets Widgets from the object type section
* @property binWidget The bin widget, displayed separately at the bottom
*/
data class WidgetSections(
val chatWidget: Widget.Chat? = null,
val pinnedWidgets: List<Widget>,
val typeWidgets: List<Widget>,
val binWidget: Widget.Bin? = null
Expand All @@ -412,12 +410,6 @@ suspend fun buildWidgetSections(
): WidgetSections {
val currentCollapsedSections = params.collapsedSections

// Build space chat widget (displayed separately at top for shared spaces)
val chatWidget = buildChatWidget(
spaceView = spaceView,
state = state
)

// Build pinned section
val pinnedWidgets = buildPinnedSection(
state = state,
Expand All @@ -442,7 +434,6 @@ suspend fun buildWidgetSections(
)

return WidgetSections(
chatWidget = chatWidget,
pinnedWidgets = pinnedWidgets,
typeWidgets = typeWidgets,
binWidget = binWidget
Expand Down