mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-22 11:38:57 +00:00
feat(category): hook category Drag and Drop to backend correctly
Fixes #10733
This commit is contained in:
parent
6233eedf58
commit
a69b8de3c3
@ -532,6 +532,8 @@ QtObject:
|
||||
categoryId: string,
|
||||
position: int,
|
||||
) =
|
||||
self.beginResetModel()
|
||||
|
||||
for i in 0 ..< self.items.len:
|
||||
var item = self.items[i]
|
||||
if item.categoryId != categoryId:
|
||||
@ -539,8 +541,9 @@ QtObject:
|
||||
if item.categoryPosition == position:
|
||||
continue
|
||||
item.categoryPosition = position
|
||||
let modelIndex = self.createIndex(i, 0, nil)
|
||||
self.dataChanged(modelIndex, modelIndex, @[ModelRole.CategoryPosition.int])
|
||||
|
||||
self.items.sort(cmpChatsAndCats)
|
||||
self.endResetModel()
|
||||
|
||||
proc clearItems*(self: Model) =
|
||||
self.beginResetModel()
|
||||
|
@ -1123,8 +1123,12 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
|
||||
)
|
||||
self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = true)
|
||||
|
||||
method reorderCommunityCategories*(self: Module, categoryId: string, position: int) =
|
||||
self.controller.reorderCommunityCategories(categoryId, position)
|
||||
method reorderCommunityCategories*(self: Module, categoryId: string, categoryPositon: int) =
|
||||
var finalPosition = categoryPositon
|
||||
if finalPosition < 0:
|
||||
finalPosition = 0
|
||||
|
||||
self.controller.reorderCommunityCategories(categoryId, finalPosition)
|
||||
|
||||
method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, toPosition: int): string =
|
||||
# Calculate actual position, since the position coming from the UI is assuming a single list where categories are items
|
||||
|
@ -344,8 +344,8 @@ QtObject:
|
||||
proc prepareEditCategoryModel*(self: View, categoryId: string) {.slot.} =
|
||||
self.delegate.prepareEditCategoryModel(categoryId)
|
||||
|
||||
proc reorderCommunityCategories*(self: View, categoryId: string, position: int) {.slot} =
|
||||
self.delegate.reorderCommunityCategories(categoryId, position)
|
||||
proc reorderCommunityCategories*(self: View, categoryId: string, categoryPositon: int) {.slot} =
|
||||
self.delegate.reorderCommunityCategories(categoryId, categoryPositon)
|
||||
|
||||
proc reorderCommunityChat*(self: View, categoryId: string, chatId: string, position: int): string {.slot} =
|
||||
self.delegate.reorderCommunityChat(categoryId, chatId, position)
|
||||
|
@ -401,22 +401,22 @@ QtObject:
|
||||
|
||||
proc checkForCategoryPropertyUpdates(self: Service, community: CommunityDto, prev_community: CommunityDto) =
|
||||
for category in community.categories:
|
||||
# id is present
|
||||
let index = findIndexById(category.id, prev_community.categories)
|
||||
if index == -1:
|
||||
continue
|
||||
# but something is different
|
||||
let prev_category = prev_community.categories[index]
|
||||
# id is present
|
||||
let index = findIndexById(category.id, prev_community.categories)
|
||||
if index == -1:
|
||||
continue
|
||||
# but something is different
|
||||
let prev_category = prev_community.categories[index]
|
||||
|
||||
if category.position != prev_category.position:
|
||||
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED,
|
||||
CommunityCategoryOrderArgs(
|
||||
communityId: community.id,
|
||||
categoryId: category.id,
|
||||
position: category.position))
|
||||
if category.name != prev_category.name:
|
||||
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_NAME_EDITED,
|
||||
CommunityCategoryArgs(communityId: community.id, category: category))
|
||||
if category.position != prev_category.position:
|
||||
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_REORDERED,
|
||||
CommunityCategoryOrderArgs(
|
||||
communityId: community.id,
|
||||
categoryId: category.id,
|
||||
position: category.position))
|
||||
if category.name != prev_category.name:
|
||||
self.events.emit(SIGNAL_COMMUNITY_CATEGORY_NAME_EDITED,
|
||||
CommunityCategoryArgs(communityId: community.id, category: category))
|
||||
|
||||
|
||||
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto], removedChats: seq[string]) =
|
||||
@ -1315,6 +1315,10 @@ QtObject:
|
||||
let error = Json.decode($response.error, RpcError)
|
||||
raise newException(RpcException, "Error reordering community category: " & error.message)
|
||||
|
||||
let updatedCommunity = response.result["communities"][0].toCommunityDto()
|
||||
# Update community categories
|
||||
self.checkForCategoryPropertyUpdates(updatedCommunity, self.communities[communityId])
|
||||
self.communities[communityId].categories = updatedCommunity.categories
|
||||
except Exception as e:
|
||||
error "Error reordering category channel", msg = e.msg, communityId, categoryId, position
|
||||
|
||||
|
@ -51,6 +51,7 @@ Item {
|
||||
readonly property int visualIndex: index
|
||||
readonly property string chatId: model.itemId
|
||||
readonly property string categoryId: model.categoryId
|
||||
readonly property int categoryPosition: model.categoryPosition // needed for the DnD
|
||||
readonly property bool isCategory: model.isCategory
|
||||
readonly property Item item: isCategory ? draggableItem.actions[0] : draggableItem.actions[1]
|
||||
|
||||
@ -72,7 +73,7 @@ Item {
|
||||
if (!drop.source.isCategory) {
|
||||
root.chatItemReordered(statusChatListItems.itemAtIndex(from).categoryId, statusChatListItems.itemAtIndex(from).chatId, to);
|
||||
} else {
|
||||
root.categoryReordered(statusChatListItems.itemAtIndex(from).categoryId, to);
|
||||
root.categoryReordered(statusChatListItems.itemAtIndex(from).categoryId, statusChatListItems.itemAtIndex(to).categoryPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user