feat: show only one valid social link in openess rating

This commit is contained in:
DomWane 2024-10-03 15:54:32 +02:00
parent 05b6b655b2
commit dfbcd7b570

View file

@ -72,7 +72,6 @@ export const useData = defineStore('data', () => {
assets.value = data.assets assets.value = data.assets
features.value = data.features features.value = data.features
ranks.value = data.ranks ranks.value = data.ranks
projectPhase.value = data.phases?.map(p => ({ id: p.id.toLowerCase(), name: p.name })) projectPhase.value = data.phases?.map(p => ({ id: p.id.toLowerCase(), name: p.name }))
assetCustody.value = data.custodys.map(a => ({ id: a.id.toLowerCase(), name: a.name })) assetCustody.value = data.custodys.map(a => ({ id: a.id.toLowerCase(), name: a.name }))
signInRequirments.value = data.requirements.map(s => ({ id: s.id.toLowerCase(), name: s.name })) signInRequirments.value = data.requirements.map(s => ({ id: s.id.toLowerCase(), name: s.name }))
@ -173,9 +172,6 @@ export const useData = defineStore('data', () => {
case 'live-on-mainnet': case 'live-on-mainnet':
return project.project_phase === 'mainnet' return project.project_phase === 'mainnet'
} }
// const features = project.technology?.features?.map(f => f.toLowerCase()) || []
// if (!features.includes(selectedFeature))
// return false
} }
return true return true
@ -191,7 +187,7 @@ export const useData = defineStore('data', () => {
if (!projects.value) return [] if (!projects.value) return []
const query = filter.query.toLowerCase() const query = filter.query.toLowerCase()
const sortDirection = filter.sortDirection === 'asc' ? 1 : -1 const sortDirection = filter.sortDirection === 'desc' ? 1 : -1
const sortBy = filter.sortby const sortBy = filter.sortby
const filteredShallowProjects = getProjectsByFilters({ shallow: true }) const filteredShallowProjects = getProjectsByFilters({ shallow: true })
@ -200,10 +196,11 @@ export const useData = defineStore('data', () => {
}) })
.sort((a, b) => { .sort((a, b) => {
if (sortBy === 'score') { if (sortBy === 'score') {
return sortDirection * (a.percentage - b.percentage) return sortDirection * (b.percentage - a.percentage)
} }
if (sortBy === 'title') { if (sortBy === 'title') {
// sortDirection is reversed because the default sort is descending
return sortDirection * a.title1.toLowerCase().localeCompare(b.title1.toLowerCase()) return sortDirection * a.title1.toLowerCase().localeCompare(b.title1.toLowerCase())
} }
@ -248,11 +245,17 @@ export const useData = defineStore('data', () => {
const projectRatings: ProjectRating[] = ranks.value?.map((rank) => { const projectRatings: ProjectRating[] = ranks.value?.map((rank) => {
let rankPoints = 0 let rankPoints = 0
let maxPoints = 0 let maxPoints = 0
const ratingStats: ProjectRatingItem[] = []
const ratingStats: ProjectRatingItem[] = rank.references?.map((ref) => { rank.references?.forEach((ref) => {
let isValid = false let isValid = false
const field = ref.field.includes('.') ? getNestedField(project, ref.field) : project[ref.field] const field = ref.field.includes('.') ? getNestedField(project, ref.field) : project[ref.field]
// adds only one valid social link
if (ref.label.positive === 'Link' && ref.label.name !== 'Documentation')
if (ratingStats.some(r => r.positive === 'Link' && r.label !== 'Documentation' && r.value) || !field)
return
let value let value
let positive let positive
let negative let negative
@ -285,14 +288,15 @@ export const useData = defineStore('data', () => {
rankPoints += isValid ? ref.points : 0 rankPoints += isValid ? ref.points : 0
maxPoints += ref.points maxPoints += ref.points
return { ratingStats.push({
isValid, isValid,
label: ref.label.name, label: ref.label.name,
positive: positive ? positive : ref.label.positive, positive: positive ? positive : ref.label.positive,
negative: negative ? negative : ref.label.negative, negative: negative ? negative : ref.label.negative,
value, value,
} as ProjectRatingItem } as ProjectRatingItem)
}) })
return { return {
type: rank.id, type: rank.id,
name: rank.name, name: rank.name,