fix(communities): ensure `featured` state is not vanished on update

This commit is contained in:
Patryk Osmaczko 2023-05-08 13:53:45 +02:00 committed by osmaczko
parent 528bb53b77
commit 190e903921
2 changed files with 15 additions and 4 deletions

View File

@ -18,7 +18,7 @@ type
QtObject:
type CuratedCommunityModel* = ref object of QAbstractListModel
items*: seq[CuratedCommunityItem]
items: seq[CuratedCommunityItem]
proc setup(self: CuratedCommunityModel) =
self.QAbstractListModel.setup
@ -104,6 +104,13 @@ QtObject:
return i
return -1
proc getItemById*(self: CuratedCommunityModel, id: string): CuratedCommunityItem =
let ind = self.findIndexById(id)
if(ind == -1):
return
return self.items[ind]
proc containsItemWithId*(self: CuratedCommunityModel, id: string): bool =
return self.findIndexById(id) != -1

View File

@ -97,8 +97,6 @@ method communityDataLoaded*(self: Module) =
self.setAllCommunities(self.controller.getAllCommunities())
method onActivated*(self: Module) =
if self.curatedCommunitiesLoaded:
return
self.controller.asyncLoadCuratedCommunities()
method curatedCommunitiesLoaded*(self: Module, curatedCommunities: seq[CommunityDto]) =
@ -232,7 +230,13 @@ method curatedCommunityAdded*(self: Module, community: CommunityDto) =
self.view.curatedCommunitiesModel().addItem(self.getCuratedCommunityItem(community))
method curatedCommunityEdited*(self: Module, community: CommunityDto) =
self.view.curatedCommunitiesModel().addItem(self.getCuratedCommunityItem(community))
if (self.view.curatedCommunitiesModel.containsItemWithId(community.id)):
# FIXME: CommunityDto should not contain fields not present in the stauts-go's community update,
# otherwise the state will vanish. For instance, the `listedInDirectory` and `featuredInDirectory`
# fields are vanished when community update is received.
var communityCopy = community
communityCopy.featuredInDirectory = self.view.curatedCommunitiesModel.getItemById(community.id).getFeatured()
self.view.curatedCommunitiesModel().addItem(self.getCuratedCommunityItem(communityCopy))
method createCommunity*(self: Module, name: string,
description, introMessage: string, outroMessage: string,