fix(communities): ensure `featured` state is not vanished on update
This commit is contained in:
parent
528bb53b77
commit
190e903921
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue