Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Correct query
Browse files Browse the repository at this point in the history
  • Loading branch information
kikakkz committed Dec 6, 2023
1 parent 8b9a848 commit 048fbf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion webui/src/components/ActivityVote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const user = useUserStore()
const account = computed(() => user.account)

const content = useContentStore()
const contents = computed(() => content._contents(account.value).filter((el) => objectCandidates.value.includes(el.cid)).sort((a, b) => {
const contents = computed(() => content._contents().filter((el) => objectCandidates.value.includes(el.cid)).sort((a, b) => {
return activity.objectVotePower(activityId.value, b.cid) - activity.objectVotePower(activityId.value, a.cid)
}))

Expand Down
24 changes: 11 additions & 13 deletions webui/src/stores/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ export interface Activity {
votable: boolean
voteType: VoteType
objectType: ObjectType
objectCandidates: Map<string, boolean>
objectCandidates: Array<string>
condition: ObjectCondition
sponsors: Array<string>
prizeConfigs: Array<PrizeConfig>
announcements: Map<string, boolean>
announcements: Array<string>
prizeAnnouncement: string
voterRewardPercent: number
votePowers: Map<string, string>
voters: Map<string, Map<string, boolean>>
voters: Map<string, Array<string>>
budgetAmount: string
joinType: JoinType
location: string
Expand Down Expand Up @@ -130,20 +130,20 @@ export const useActivityStore = defineStore('activity', {
votes (): (id: number) => number {
return (id: number) => {
let votes = 0
Object.values(this.activities.get(id)?.voters || new Map<string, Map<string, boolean>>()).forEach((el: Map<string, boolean>) => {
votes += el.size
Object.values(this.activities.get(id)?.voters || new Map<string, Array<string>>()).forEach((el: Array<string>) => {
votes += el.length
})
return votes
}
},
objectCandidateCount (): (id: number) => number {
return (id: number) => {
return Object.values(this.activities.get(id)?.objectCandidates || new Map<string, boolean>()).length
return (this.activities.get(id)?.objectCandidates || []).length
}
},
objectCandidates (): (id: number) => Array<string> {
return (id: number) => {
return Object.keys(this.activities.get(id)?.objectCandidates || new Map<string, boolean>())
return this.activities.get(id)?.objectCandidates || []
}
},
objectVotePower (): (id: number, objectId: string) => number {
Expand All @@ -156,7 +156,7 @@ export const useActivityStore = defineStore('activity', {
return Number(
new Map(
new Map(
Object.entries(Object.entries(this.activities.get(id)?.voters || new Map<string, Map<string, boolean>>()))).get(objectId)
Object.entries(Object.entries(this.activities.get(id)?.voters || new Map<string, Array<string>>()))).get(objectId)
).size)
}
},
Expand Down Expand Up @@ -238,15 +238,13 @@ export const useActivityStore = defineStore('activity', {
},
objectRegistered (): (id: number, objectId: string) => boolean | undefined {
return (id: number, objectId: string) => {
return Object.keys(this.activities.get(id)?.objectCandidates || new Map<string, boolean>()).includes(objectId)
return (this.activities.get(id)?.objectCandidates || []).includes(objectId)
}
},
objectVoted (): (id: number, objectId: string, account: string) => boolean | undefined {
return (id: number, objectId: string, account: string) => {
const voters = new Map<string, Map<string, boolean>>(Object.entries(this.activities.get(id)?.voters || new Map<string, Map<string, boolean>>()))
return Object.keys(
voters.get(objectId) || new Map<string, boolean>()
).includes(account)
const voters = new Map<string, Map<string, boolean>>(Object.entries(this.activities.get(id)?.voters || new Map<string, Array<string>>()))
return ((voters.get(objectId) || []) as Array<string>).includes(account)
}
}
},
Expand Down

0 comments on commit 048fbf3

Please sign in to comment.