feat(communities): propagate featured flag

closes: #10565
This commit is contained in:
Patryk Osmaczko 2023-05-05 16:23:28 +02:00 committed by osmaczko
parent 935ab046e6
commit cc191ae0e4
4 changed files with 20 additions and 9 deletions

View File

@ -12,6 +12,7 @@ type
tags: string tags: string
members: int members: int
activeMembers: int activeMembers: int
featured: bool
proc initCuratedCommunityItem*( proc initCuratedCommunityItem*(
id: string, id: string,
@ -23,7 +24,8 @@ proc initCuratedCommunityItem*(
color: string, color: string,
tags: string, tags: string,
members: int, members: int,
activeMembers: int activeMembers: int,
featured: bool
): CuratedCommunityItem = ): CuratedCommunityItem =
result.id = id result.id = id
result.name = name result.name = name
@ -35,6 +37,7 @@ proc initCuratedCommunityItem*(
result.tags = tags result.tags = tags
result.members = members result.members = members
result.activeMembers = activeMembers result.activeMembers = activeMembers
result.featured = featured
proc `$`*(self: CuratedCommunityItem): string = proc `$`*(self: CuratedCommunityItem): string =
result = fmt"""CuratedCommunityItem( result = fmt"""CuratedCommunityItem(
@ -46,6 +49,7 @@ proc `$`*(self: CuratedCommunityItem): string =
tags: {self.tags}, tags: {self.tags},
members: {self.members} members: {self.members}
activeMembers: {self.activeMembers} activeMembers: {self.activeMembers}
featured: {self.featured}
]""" ]"""
proc getId*(self: CuratedCommunityItem): string = proc getId*(self: CuratedCommunityItem): string =
@ -77,3 +81,6 @@ proc getColor*(self: CuratedCommunityItem): string =
proc getTags*(self: CuratedCommunityItem): string = proc getTags*(self: CuratedCommunityItem): string =
return self.tags return self.tags
proc getFeatured*(self: CuratedCommunityItem): bool =
return self.featured

View File

@ -61,7 +61,7 @@ QtObject:
ModelRole.ActiveMembers.int:"activeMembers", ModelRole.ActiveMembers.int:"activeMembers",
ModelRole.Color.int:"color", ModelRole.Color.int:"color",
ModelRole.Popularity.int:"popularity", ModelRole.Popularity.int:"popularity",
ModelRole.Tags.int:"tags" ModelRole.Tags.int:"tags",
}.toTable }.toTable
method data(self: CuratedCommunityModel, index: QModelIndex, role: int): QVariant = method data(self: CuratedCommunityModel, index: QModelIndex, role: int): QVariant =
@ -96,11 +96,7 @@ QtObject:
of ModelRole.Tags: of ModelRole.Tags:
result = newQVariant(item.getTags()) result = newQVariant(item.getTags())
of ModelRole.Featured: of ModelRole.Featured:
# TODO: replace this with a real value result = newQVariant(item.getFeatured())
var featured = false
if index.row < 3:
featured = true
result = newQVariant(featured)
proc findIndexById(self: CuratedCommunityModel, id: string): int = proc findIndexById(self: CuratedCommunityModel, id: string): int =
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:

View File

@ -194,7 +194,8 @@ proc getCuratedCommunityItem(self: Module, c: CommunityDto): CuratedCommunityIte
c.color, c.color,
c.tags, c.tags,
len(c.members), len(c.members),
int(c.activeMembersCount)) int(c.activeMembersCount),
c.featuredInDirectory)
proc getDiscordCategoryItem(self: Module, c: DiscordCategoryDto): DiscordCategoryItem = proc getDiscordCategoryItem(self: Module, c: DiscordCategoryDto): DiscordCategoryItem =
return initDiscordCategoryItem( return initDiscordCategoryItem(

View File

@ -1,5 +1,6 @@
{.used.} {.used.}
import std/jsonutils
import json, sequtils, sugar, tables, strutils, json_serialization import json, sequtils, sugar, tables, strutils, json_serialization
import ../../../../backend/communities import ../../../../backend/communities
@ -91,6 +92,7 @@ type CommunityDto* = object
isMember*: bool isMember*: bool
muted*: bool muted*: bool
listedInDirectory*: bool listedInDirectory*: bool
featuredInDirectory*: bool
pendingRequestsToJoin*: seq[CommunityMembershipRequestDto] pendingRequestsToJoin*: seq[CommunityMembershipRequestDto]
settings*: CommunitySettingsDto settings*: CommunitySettingsDto
adminSettings*: CommunityAdminSettingsDto adminSettings*: CommunityAdminSettingsDto
@ -355,7 +357,12 @@ proc parseCuratedCommunities*(response: JsonNode): seq[CommunityDto] =
result = parseKnownCuratedCommunities(response["communities"]) result = parseKnownCuratedCommunities(response["communities"])
if (response["unknownCommunities"].kind == JArray): if (response["unknownCommunities"].kind == JArray):
result = concat(result, parseUnknownCuratedCommunities(response["unknownCommunities"])) result = concat(result, parseUnknownCuratedCommunities(response["unknownCommunities"]))
if (response["contractFeaturedCommunities"].kind == JArray):
let featuredCommunityIDs = response["contractFeaturedCommunities"].to(seq[string])
for i in 0..<result.len:
let communityID = result[i].id
result[i].featuredInDirectory = any(featuredCommunityIDs, id => id == communityID)
proc contains(arrayToSearch: seq[int], searched: int): bool = proc contains(arrayToSearch: seq[int], searched: int): bool =
for element in arrayToSearch: for element in arrayToSearch:
if element == searched: if element == searched: