Skip to content

Commit

Permalink
fix(communities): ensure featured state is not vanished on update
Browse files Browse the repository at this point in the history
  • Loading branch information
osmaczko committed May 8, 2023
1 parent 528bb53 commit 190e903
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions src/app/modules/main/communities/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]) =
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 190e903

Please # to comment.