mirror of
https://github.com/web3privacy/explorer-app.git
synced 2024-10-15 16:46:26 +02:00
fix: optional return for null cases
This commit is contained in:
parent
950b4164a0
commit
abc5e3cd4d
2 changed files with 23 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { Project } from '~/types'
|
import type { Project, ProjectIndexable } from '~/types'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
project: Project
|
project: Project
|
||||||
|
@ -21,34 +21,33 @@ const availableSupport = computed(() => {
|
||||||
- team: anon / public
|
- team: anon / public
|
||||||
- audit: yes / no
|
- audit: yes / no
|
||||||
*/
|
*/
|
||||||
const calculateScore: number = computed(() => {
|
const calculateScore = computed(() => {
|
||||||
const criterias: { value: string; key?: string }[] = [
|
const criterias: { value: string; key: string }[] = [
|
||||||
{ value: 'product_readiness' },
|
{ value: 'product_readiness', key: '' },
|
||||||
{ value: 'github', key: 'links' },
|
{ value: 'github', key: 'links' },
|
||||||
{ value: 'docs', key: 'links' },
|
{ value: 'docs', key: 'links' },
|
||||||
{ value: 'team' },
|
{ value: 'team', key: '' },
|
||||||
{ value: 'audits' },
|
{ value: 'audits', key: '' },
|
||||||
]
|
]
|
||||||
|
|
||||||
let matched = 0
|
let matched = 0
|
||||||
for (let i = 0; i < criterias.length; i++) {
|
for (let i = 0; i < criterias.length; i++) {
|
||||||
let value
|
let value
|
||||||
if (criterias[i].key) {
|
// value = ((criterias[i].key ?? props.project[criterias[i].value as keyof typeof props.project]) ?? null === null) ? null : (props.project as ProjectIndexable)[criterias[i].key][criterias[i].value]
|
||||||
if (props.project[criterias[i].key] === null || props.project[criterias[i].key] === undefined)
|
|
||||||
continue
|
const indexableProject = (props.project as ProjectIndexable)
|
||||||
value = props.project[criterias[i].key][criterias[i].value]
|
if (criterias[i].key !== '')
|
||||||
}
|
value = indexableProject?.[criterias[i].key]?.[criterias[i].value]
|
||||||
else {
|
else
|
||||||
if (props.project[criterias[i].value] === null || props.project[criterias[i].value] === undefined)
|
value = indexableProject?.[criterias[i].value]
|
||||||
continue
|
|
||||||
value = props.project[criterias[i].value]
|
// console.log(props.project?.links?.github);
|
||||||
}
|
// console.log(Object.keys(props.indexableProject["team"]).length);
|
||||||
// console.log(value);
|
if (value === null || value === undefined)
|
||||||
// console.log(Object.keys(props.project["team"]).length);
|
continue
|
||||||
|
|
||||||
if (fulfilled(value))
|
if (fulfilled(value))
|
||||||
matched++
|
matched++
|
||||||
// console.log('matched', matched);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 100 / criterias.length * matched
|
return 100 / criterias.length * matched
|
||||||
|
@ -65,10 +64,10 @@ function fulfilled(value: any): boolean {
|
||||||
if (Object.keys(value).length > 0)
|
if (Object.keys(value).length > 0)
|
||||||
return true
|
return true
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const logo = props.project?.logos?.at(0)?.url
|
const logo = props.project?.logos?.at(0)?.url
|
||||||
|
|
|
@ -143,3 +143,7 @@ export interface ProjectShallow {
|
||||||
support?: number | undefined
|
support?: number | undefined
|
||||||
anonymity?: boolean | undefined
|
anonymity?: boolean | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProjectIndexable extends Project {
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue